From 32ec3c22d2b1fa7d613d6f714c2511d38e040a16 Mon Sep 17 00:00:00 2001 From: goodmice Date: Wed, 19 Oct 2022 13:52:26 +0500 Subject: [PATCH] =?UTF-8?q?makeNumericAvgRange=20=D0=B2=D0=B5=D1=80=D0=BD?= =?UTF-8?q?=D1=83=D1=82=20=D0=BA=20=D0=B8=D0=B7=D0=BD=D0=B0=D1=87=D0=B0?= =?UTF-8?q?=D0=BB=D1=8C=D0=BD=D0=BE=D0=BC=D1=83=20=D0=B2=D0=B8=D0=B4=D1=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/Table/Columns/index.ts | 1 + src/components/Table/Columns/numeric.tsx | 38 ++++++--- src/components/Table/index.tsx | 1 + src/pages/WellOperations/WellDrillParams.jsx | 85 ++------------------ 4 files changed, 35 insertions(+), 90 deletions(-) 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), ] }