diff --git a/src/components/Layout/AdminLayoutPortal.tsx b/src/components/Layout/AdminLayoutPortal.tsx new file mode 100644 index 0000000..f9f60c3 --- /dev/null +++ b/src/components/Layout/AdminLayoutPortal.tsx @@ -0,0 +1,21 @@ +import { Button, Layout } from 'antd' +import { Link } from 'react-router-dom' +import PageHeader from '../PageHeader' + +type LayoutPortalProps = { + title?: string + [props: string]: any +} + +export const AdminLayoutPortal: React.FC = ({title, ...props}) => ( + + + + + + + + +) diff --git a/src/components/Layout/LayoutPortal.tsx b/src/components/Layout/LayoutPortal.tsx new file mode 100644 index 0000000..051cb90 --- /dev/null +++ b/src/components/Layout/LayoutPortal.tsx @@ -0,0 +1,22 @@ +import { Layout } from 'antd' +import PageHeader from '../PageHeader' +import WellTreeSelector from '../WellTreeSelector' + +type LayoutPortalProps = { + title?: string + noSheet?: boolean + [props: string]: any +} + +export const LayoutPortal: React.FC = ({title, noSheet, ...props}) => ( + + + + + + {noSheet ? props.children : ( + + )} + + +) diff --git a/src/components/Layout/index.ts b/src/components/Layout/index.ts new file mode 100644 index 0000000..90bb16b --- /dev/null +++ b/src/components/Layout/index.ts @@ -0,0 +1,2 @@ +export { AdminLayoutPortal } from './AdminLayoutPortal' +export { LayoutPortal } from './LayoutPortal' diff --git a/src/components/LayoutPortal.jsx b/src/components/LayoutPortal.jsx deleted file mode 100644 index 2fa6886..0000000 --- a/src/components/LayoutPortal.jsx +++ /dev/null @@ -1,13 +0,0 @@ -import {Layout} from 'antd' -import PageHeader from './PageHeader' - -export const LayoutPortal = ({title, noSheet, ...props}) => ( - - - - {noSheet ? props.children : ( - - )} - - -) diff --git a/src/components/PageHeader.tsx b/src/components/PageHeader.tsx index 569c39e..5fc2b9d 100644 --- a/src/components/PageHeader.tsx +++ b/src/components/PageHeader.tsx @@ -1,36 +1,25 @@ -import { Layout, Button } from 'antd' -import { UserOutlined } from '@ant-design/icons' -import logo from '../images/logo_32.png' import { Link } from 'react-router-dom' -import WellTreeSelector from './WellTreeSelector' +import { Layout } from 'antd' import { headerHeight } from '../utils' +import { UserMenu } from './UserMenu' +import logo from '../images/logo_32.png' -const { Header } = Layout - -const logoStyle = { height: headerHeight } - -const handleLogout = () => { - localStorage.removeItem('login') - localStorage.removeItem('token') +type PageHeaderProps = { + children?: React.ReactNode + title?: string } -type PageHeaderProps = { title?: string } - -export const PageHeader = ({ title = 'Мониторинг' }: PageHeaderProps) => ( - -
- - {'АСБ'} - - -

{title}

- - - -
-
+export const PageHeader: React.FC = ({ children, title = 'Мониторинг' }) => ( + + + + {'АСБ'} + + {children} +

{title}

+ +
+
) export default PageHeader diff --git a/src/components/Table/index.tsx b/src/components/Table/index.tsx index 8dff5ad..a1cf049 100644 --- a/src/components/Table/index.tsx +++ b/src/components/Table/index.tsx @@ -1,5 +1,6 @@ import { ReactNode } from 'react' -import { Table as RawTable } from 'antd' +import { Select, Table as RawTable } from 'antd' +import { OptionsType } from 'rc-select/lib/interface' import { tryAddKeys } from './EditableTable' import { makeNumericSorter, makeStringSorter} from './sorters' export { makeDateSorter, makeNumericSorter, makeStringSorter} from './sorters' @@ -25,7 +26,7 @@ export const makeNumericRender = (fixed?: number) => (value: any, row: object): ) } -export const makeNumericColumnOptions = (fixed?:number, sorterKey?:string ) => ({ +export const makeNumericColumnOptions = (fixed?: number, sorterKey?: string ) => ({ editable: true, initialValue: 0, width:100, @@ -57,35 +58,41 @@ interface columnPropsOther { formItemRules?: any[] // дефолтное значение при добавлении новой строки initialValue?: string|number + + render?: (...attributes: any) => any } -export const makeColumn = (title:string | ReactNode, key:string, other?:columnPropsOther) => ({ +export const makeColumn = (title: string | ReactNode, key: string, other?: columnPropsOther) => ({ title: title, key: key, dataIndex: key, ...other, }) -export const makeColumnsPlanFact = (title:string | ReactNode, key:string|string[], columsOther?:any|any[], gruopOther?:any) => -{ +export const makeColumnsPlanFact = ( + title:string | ReactNode, + key:string | string[], + columsOther?: any | any[], + gruopOther?: any +) => { let keyPlanLocal = key let keyFactLocal = key - - if(key instanceof Array){ + + if (key instanceof Array) { keyPlanLocal = key[0] keyFactLocal = key[1] - }else{ + } else { keyPlanLocal = key + 'Plan' keyFactLocal = key + 'Fact' } - let columsOtherLoacl :any[2] - if(columsOther instanceof Array) + let columsOtherLoacl : any[2] + if (columsOther instanceof Array) columsOtherLoacl = [columsOther[0], columsOther[1]] else columsOtherLoacl = [columsOther, columsOther] - return { + return { title: title, ...gruopOther, children: [ @@ -98,49 +105,61 @@ export const makeColumnsPlanFact = (title:string | ReactNode, key:string|string[ export const makeFilterTextMatch = (key: string | number) => (filterValue: string | number, dataItem: any) => dataItem[key] === filterValue -export const makeGroupColumn = (title: string, children: object[]) => ({ +export const makeGroupColumn = (title: string, children: object[]) => ({ title: title, children: children, }) export const makeTextColumn = ( - title: string, - dataIndex: string, - filters: object[], - sorter?: (key: string) => any, - render?: any, - other?: any) => ({ - title: title, - dataIndex: dataIndex, - key: dataIndex, - filters: filters, - onFilter: filters ? makeFilterTextMatch(dataIndex) : null, - sorter: sorter ?? makeStringSorter(dataIndex), - render: render, - ...other + title: string, + dataIndex: string, + filters: object[], + sorter?: (key: string) => any, + render?: any, + other?: any +) => ({ + title: title, + dataIndex: dataIndex, + key: dataIndex, + filters: filters, + onFilter: filters ? makeFilterTextMatch(dataIndex) : null, + sorter: sorter ?? makeStringSorter(dataIndex), + render: render, + ...other }) -export const makeNumericColumn = (title: string, dataIndex: string, - filters: object[], filterDelegate: (key: string | number) => any, - renderDelegate: (_: any, row: object) => any, width: string, other?: columnPropsOther) => ({ - title: title, - dataIndex: dataIndex, - key: dataIndex, - filters: filters, - onFilter: filterDelegate ? filterDelegate(dataIndex) : null, - sorter: makeNumericSorter(dataIndex), - width: width, - render: renderDelegate??makeNumericRender(), - align: 'right', - ...other +export const makeNumericColumn = ( + title: string, + dataIndex: string, + filters: object[], + filterDelegate: (key: string | number) => any, + renderDelegate: (_: any, row: object) => any, + width: string, + other?: columnPropsOther +) => ({ + title: title, + dataIndex: dataIndex, + key: dataIndex, + filters: filters, + onFilter: filterDelegate ? filterDelegate(dataIndex) : null, + sorter: makeNumericSorter(dataIndex), + width: width, + render: renderDelegate??makeNumericRender(), + align: 'right', + ...other }) -export const makeNumericColumnPlanFact = (title: string, dataIndex: string, filters: object[], - filterDelegate: (key: string | number) => any, renderDelegate: (_: any, row: object) => any, width: string) => - makeGroupColumn( title, [ - makeNumericColumn('п', dataIndex + 'Plan', filters, filterDelegate, renderDelegate, width), - makeNumericColumn('ф', dataIndex + 'Fact', filters, filterDelegate, renderDelegate, width), - ]) +export const makeNumericColumnPlanFact = ( + title: string, + dataIndex: string, + filters: object[], + filterDelegate: (key: string | number) => any, + renderDelegate: (_: any, row: object) => any, + width: string +) => makeGroupColumn(title, [ + makeNumericColumn('п', dataIndex + 'Plan', filters, filterDelegate, renderDelegate, width), + makeNumericColumn('ф', dataIndex + 'Fact', filters, filterDelegate, renderDelegate, width), +]) export const makeNumericStartEnd = ( title: string, @@ -150,7 +169,7 @@ export const makeNumericStartEnd = ( filterDelegate: (key: string | number) => any, renderDelegate: (_: any, row: object) => any, width: string, -) => makeGroupColumn( title, [ +) => makeGroupColumn(title, [ makeNumericColumn('старт', dataIndex + 'Start', filters, filterDelegate, renderDelegate, width, makeNumericColumnOptions(fixed, dataIndex + 'Start')), makeNumericColumn('конец', dataIndex + 'End', filters, filterDelegate, renderDelegate, width, makeNumericColumnOptions(fixed, dataIndex + 'End')) ]) @@ -169,41 +188,50 @@ export const makeNumericMinMax = ( ]) export const makeNumericAvgRange = ( - title: string, - dataIndex: string, - fixed: number, - filters: object[], - filterDelegate: (key: string | number) => any, - renderDelegate: (_: any, row: object) => any, - width: string -) => makeGroupColumn( title, [ - makeNumericColumn('мин', dataIndex + 'Min', filters, filterDelegate, renderDelegate, width, makeNumericColumnOptions(fixed, dataIndex + 'Min')), - makeNumericColumn('сред', dataIndex + 'Avg', filters, filterDelegate, renderDelegate, width, makeNumericColumnOptions(fixed, dataIndex + 'Avg')), - makeNumericColumn('макс', dataIndex + 'Max', filters, filterDelegate, renderDelegate, width, makeNumericColumnOptions(fixed, dataIndex + 'Max')) + title: string, + dataIndex: string, + fixed: number, + filters: object[], + filterDelegate: (key: string | number) => any, + renderDelegate: (_: any, row: object) => any, + width: string +) => makeGroupColumn(title, [ + makeNumericColumn('мин', dataIndex + 'Min', filters, filterDelegate, renderDelegate, width, makeNumericColumnOptions(fixed, dataIndex + 'Min')), + makeNumericColumn('сред', dataIndex + 'Avg', filters, filterDelegate, renderDelegate, width, makeNumericColumnOptions(fixed, dataIndex + 'Avg')), + makeNumericColumn('макс', dataIndex + 'Max', filters, filterDelegate, renderDelegate, width, makeNumericColumnOptions(fixed, dataIndex + 'Max')) ]) +export const makeSelectColumn = ( + title: string, + dataIndex: string, + options: OptionsType, + defaultValue?: T, + other?: columnPropsOther +) => makeColumn(title, dataIndex, { + input: