diff --git a/src/components/Table/Columns/index.ts b/src/components/Table/Columns/index.ts index c97f091..28427e8 100755 --- a/src/components/Table/Columns/index.ts +++ b/src/components/Table/Columns/index.ts @@ -12,6 +12,7 @@ export { makeNumericColumnPlanFact, makeNumericStartEnd, makeNumericMinMax, + makeNumericAvgRange, } from './numeric' export { makeColumnsPlanFact } from './plan_fact' export { makeSelectColumn } from './select' diff --git a/src/components/Table/Columns/numeric.tsx b/src/components/Table/Columns/numeric.tsx index ad8fdee..1da2055 100755 --- a/src/components/Table/Columns/numeric.tsx +++ b/src/components/Table/Columns/numeric.tsx @@ -1,15 +1,15 @@ +import { ColumnFilterItem } from 'antd/lib/table/interface' import { InputNumber } from 'antd' import { ReactNode } from 'react' import { makeNumericSorter } from '../sorters' import makeColumn, { columnPropsOther, DataType, makeGroupColumn, RenderMethod } from '.' -import { ColumnFilterItem, CompareFn } from 'antd/lib/table/interface' export const RegExpIsFloat = /^[-+]?\d+\.?\d*$/ type FilterMethod = (value: string | number | boolean, record: DataType) => boolean -export const makeNumericRender = (fixed?: number): RenderMethod => (value: T) => { +export const makeNumericRender = (fixed?: number): RenderMethod => (value: T) => { let val = '-' if ((value ?? null) !== null && Number.isFinite(+value)) { val = (fixed ?? null) !== null @@ -24,7 +24,7 @@ export const makeNumericRender = (fixed?: number): RenderMeth ) } -export const makeNumericColumnOptions = (fixed?: number, sorterKey?: string): columnPropsOther => ({ +export const makeNumericColumnOptions = (fixed?: number, sorterKey?: string): columnPropsOther => ({ editable: true, initialValue: 0, width: 100, @@ -37,7 +37,7 @@ export const makeNumericColumnOptions = (fixed?: number render: makeNumericRender(fixed), }) -export const makeNumericColumn = ( +export const makeNumericColumn = ( title: ReactNode, key: string, filters?: ColumnFilterItem[], @@ -48,7 +48,7 @@ export const makeNumericColumn = ( ) => makeColumn(title, key, { filters, onFilter: filterDelegate ? filterDelegate(key) : undefined, - sorter: makeNumericSorter(key), + sorter: makeNumericSorter(key), width, input: , render: renderDelegate ?? makeNumericRender(2), @@ -56,7 +56,7 @@ export const makeNumericColumn = ( ...other }) -export const makeNumericColumnPlanFact = ( +export const makeNumericColumnPlanFact = ( title: ReactNode, key: string, filters?: ColumnFilterItem[], @@ -68,7 +68,7 @@ export const makeNumericColumnPlanFact = ( makeNumericColumn('ф', key + 'Fact', filters, filterDelegate, renderDelegate, width), ]) -export const makeNumericStartEnd = ( +export const makeNumericStartEnd = ( title: ReactNode, key: string, fixed: number, @@ -77,11 +77,11 @@ export const makeNumericStartEnd = ( renderDelegate?: RenderMethod, width?: string | number, ) => makeGroupColumn(title, [ - makeNumericColumn('старт', key + 'Start', filters, filterDelegate, renderDelegate, width, makeNumericColumnOptions(fixed, key + 'Start')), - makeNumericColumn('конец', key + 'End', filters, filterDelegate, renderDelegate, width, makeNumericColumnOptions(fixed, key + 'End')) + makeNumericColumn('старт', key + 'Start', filters, filterDelegate, renderDelegate, width, makeNumericColumnOptions(fixed, key + 'Start')), + makeNumericColumn('конец', key + 'End', filters, filterDelegate, renderDelegate, width, makeNumericColumnOptions(fixed, key + 'End')) ]) -export const makeNumericMinMax = ( +export const makeNumericMinMax = ( title: ReactNode, key: string, fixed: number, @@ -90,8 +90,22 @@ export const makeNumericMinMax = ( renderDelegate?: RenderMethod, width?: string | number, ) => makeGroupColumn(title, [ - makeNumericColumn('мин', key + 'Min', filters, filterDelegate, renderDelegate, width, makeNumericColumnOptions(fixed, key + 'Min')), - makeNumericColumn('макс', key + 'Max', filters, filterDelegate, renderDelegate, width, makeNumericColumnOptions(fixed, key + 'Max')), + makeNumericColumn('мин', key + 'Min', filters, filterDelegate, renderDelegate, width, makeNumericColumnOptions(fixed, key + 'Min')), + makeNumericColumn('макс', key + 'Max', filters, filterDelegate, renderDelegate, width, makeNumericColumnOptions(fixed, key + 'Max')), +]) + +export const makeNumericAvgRange = ( + title: ReactNode, + dataIndex: string, + fixed: number, + filters: ColumnFilterItem[], + filterDelegate: (key: string | number) => FilterMethod, + renderDelegate: RenderMethod, + 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 default makeNumericColumn diff --git a/src/components/Table/index.tsx b/src/components/Table/index.tsx index c1b3558..b03b8de 100755 --- a/src/components/Table/index.tsx +++ b/src/components/Table/index.tsx @@ -20,6 +20,7 @@ export { makeNumericColumnPlanFact, makeNumericStartEnd, makeNumericMinMax, + makeNumericAvgRange, makeSelectColumn, makeTagColumn, makeTagInput, diff --git a/src/pages/WellOperations/WellDrillParams.jsx b/src/pages/WellOperations/WellDrillParams.jsx index 486b422..f240630 100755 --- a/src/pages/WellOperations/WellDrillParams.jsx +++ b/src/pages/WellOperations/WellDrillParams.jsx @@ -1,89 +1,18 @@ import { useState, useEffect, useCallback, memo, useMemo } from 'react' -import { InputNumber } from 'antd' import { useWell } from '@asb/context' import { EditableTable, makeSelectColumn, - makeGroupColumn, - makeNumericRender, makeNumericSorter, - RegExpIsFloat, + makeNumericAvgRange, } from '@components/Table' import LoaderPortal from '@components/LoaderPortal' import { invokeWebApiWrapperAsync } from '@components/factory' import { DrillParamsService, WellOperationService } from '@api' import { arrayOrDefault } from '@utils' -import { makeNumericObjSorter } from '@components/Table/sorters' - -const makeNumericObjRender = (fixed, columnKey) => (value, obj) => { - let val = '-' - const isSelected = obj && columnKey && obj[columnKey[0]] ? obj[columnKey[0]][columnKey[1]] : false - - if ((value ?? null) !== null && Number.isFinite(+value)) { - val = (fixed ?? null) !== null - ? (+value).toFixed(fixed) - : (+value).toPrecision(5) - } - - return ( -
- {val} -
- ) -} - -const makeNumericColumnOptionsWithColor = (fixed, sorterKey, columnKey) => ({ - editable: true, - initialValue: 0, - width: 100, - sorter: sorterKey ? makeNumericObjSorter(sorterKey) : undefined, - formItemRules: [{ - required: true, - message: 'Введите число', - pattern: RegExpIsFloat, - }], - render: makeNumericObjRender(fixed, columnKey), -}) - -const makeNumericObjColumn = ( - title, - dataIndex, - filters, - filterDelegate, - renderDelegate, - width, - other -) => ({ - title: title, - dataIndex: dataIndex, - key: dataIndex, - filters: filters, - onFilter: filterDelegate ? filterDelegate(dataIndex) : null, - sorter: makeNumericObjSorter(dataIndex), - width: width, - input: , - render: renderDelegate ?? makeNumericRender(), - align: 'right', - ...other -}) - -const makeNumericAvgRange = ( - title, - dataIndex, - fixed, - filters, - filterDelegate, - renderDelegate, - width -) => makeGroupColumn(title, [ - makeNumericObjColumn('мин', [dataIndex, 'min'], filters, filterDelegate, renderDelegate, width, makeNumericColumnOptionsWithColor(fixed, [dataIndex, 'min'], [dataIndex, 'isMin'])), - makeNumericObjColumn('сред', [dataIndex, 'avg'], filters, filterDelegate, renderDelegate, width, makeNumericColumnOptionsWithColor(fixed, [dataIndex, 'avg'])), - makeNumericObjColumn('макс', [dataIndex, 'max'], filters, filterDelegate, renderDelegate, width, makeNumericColumnOptionsWithColor(fixed, [dataIndex, 'max'], [dataIndex, 'isMax'])) -]) - -export const getColumns = async (idWell) => { +export const getColumns = async (idWell, makeAvgRange = makeNumericAvgRange) => { let sectionTypes = await WellOperationService.getSectionTypes(idWell) sectionTypes = Object.entries(sectionTypes).map(([id, value]) => ({ label: value, @@ -96,11 +25,11 @@ export const getColumns = async (idWell) => { width: 160, sorter: makeNumericSorter('idWellSectionType'), }), - makeNumericAvgRange('Нагрузка, т', 'axialLoad', 1), - makeNumericAvgRange('Давление, атм', 'pressure', 1), - makeNumericAvgRange('Момент на ВСП, кН·м', 'rotorTorque', 1), - makeNumericAvgRange('Обороты на ВСП, об/мин', 'rotorSpeed', 1), - makeNumericAvgRange('Расход, л/с', 'flow', 1), + makeAvgRange('Нагрузка, т', 'axialLoad', 1), + makeAvgRange('Давление, атм', 'pressure', 1), + makeAvgRange('Момент на ВСП, кН·м', 'rotorTorque', 1), + makeAvgRange('Обороты на ВСП, об/мин', 'rotorSpeed', 1), + makeAvgRange('Расход, л/с', 'flow', 1), ] }