From 38fa8ffbebf6259b5d61593ceaa9e7dee367dc7b Mon Sep 17 00:00:00 2001 From: ts_salikhov Date: Thu, 29 Sep 2022 16:26:55 +0400 Subject: [PATCH] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=BE=20=D0=BE=D1=82=D0=BE=D0=B1=D1=80=D0=B0=D0=B6?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=B4=D0=B0=D0=BD=D0=BD=D1=8B=D1=85?= =?UTF-8?q?=20=D0=B2=20=D1=82=D0=B0=D0=B1=D0=BB=D0=B8=D1=86=D0=B5=20"?= =?UTF-8?q?=D0=97=D0=B0=D0=BF=D0=BE=D0=BB=D0=BD=D0=B8=D1=82=D1=8C=20=D1=80?= =?UTF-8?q?=D0=B5=D0=B6=D0=B8=D0=BC=D1=8B=20=D1=82=D0=B5=D0=BA=D1=83=D1=89?= =?UTF-8?q?=D0=B5=D0=B9=20=D1=81=D0=BA=D0=B2=D0=B0=D0=B6=D0=B8=D0=BD=D1=8B?= =?UTF-8?q?"=20=D0=B8=20=D0=B2=20=D1=82=D0=B0=D0=B1=D0=BB=D0=B8=D1=86?= =?UTF-8?q?=D0=B5=20=D0=BD=D0=B0=20=D1=81=D1=82=D1=80=D0=B0=D0=BD=D0=B8?= =?UTF-8?q?=D1=86=D0=B5=20"=D0=A0=D0=B5=D0=B6=D0=B8=D0=BC=D1=8B"?= 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 | 67 +----------------- src/components/Table/index.tsx | 1 - src/pages/WellOperations/WellDrillParams.jsx | 74 +++++++++++++++++++- 4 files changed, 73 insertions(+), 70 deletions(-) diff --git a/src/components/Table/Columns/index.ts b/src/components/Table/Columns/index.ts index de3a044..0a4e113 100755 --- a/src/components/Table/Columns/index.ts +++ b/src/components/Table/Columns/index.ts @@ -12,7 +12,6 @@ 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 db028a8..ce9a947 100755 --- a/src/components/Table/Columns/numeric.tsx +++ b/src/components/Table/Columns/numeric.tsx @@ -1,7 +1,7 @@ import { InputNumber } from 'antd' import { ReactNode } from 'react' -import { makeNumericObjSorter, makeNumericSorter } from '../sorters' +import { makeNumericSorter } from '../sorters' import { columnPropsOther, makeGroupColumn, RenderMethod } from '.' export const RegExpIsFloat = /^[-+]?\d+\.?\d*$/ @@ -21,22 +21,6 @@ export const makeNumericRender = (fixed?: number): RenderMeth ) } -export const makeNumericObjRender = (fixed?: number, columnKey?: [string, string]): RenderMethod => (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} -
- ) -} export const makeNumericColumnOptions = (fixed?: number, sorterKey?: string): columnPropsOther => ({ editable: true, @@ -51,19 +35,6 @@ export const makeNumericColumnOptions = (fixed?: number, sorterKey?: string): co render: makeNumericRender(fixed), }) -export const makeNumericColumnOptionsWithColor = (fixed?: number, sorterKey?: [string, string], columnKey?: [string, string]): columnPropsOther => ({ - editable: true, - initialValue: 0, - width: 100, - sorter: sorterKey ? makeNumericObjSorter(sorterKey) : undefined, - formItemRules: [{ - required: true, - message: 'Введите число', - pattern: RegExpIsFloat, - }], - render: makeNumericObjRender(fixed, columnKey), -}) - export const makeNumericColumn = ( title: ReactNode, dataIndex: string, @@ -86,28 +57,6 @@ export const makeNumericColumn = ( ...other }) -export const makeNumericObjColumn = ( - title: ReactNode, - dataIndex: [string, string], - filters: object[], - filterDelegate: (key: [string, string]) => any, - renderDelegate: (_: any, row: object) => any, - width: string, - other?: columnPropsOther -) => ({ - 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 -}) - export const makeNumericColumnPlanFact = ( title: ReactNode, dataIndex: string, @@ -146,18 +95,4 @@ export const makeNumericMinMax = ( makeNumericColumn('макс', dataIndex + 'Max', filters, filterDelegate, renderDelegate, width, makeNumericColumnOptions(fixed, dataIndex + 'Max')), ]) -export const makeNumericAvgRange = ( - title: ReactNode, - dataIndex: string, - fixed: number, - filters: object[], - filterDelegate: (key: [string, string]) => any, - renderDelegate: (_: any, row: object) => any, - width: string -) => 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 default makeNumericColumn diff --git a/src/components/Table/index.tsx b/src/components/Table/index.tsx index b03b8de..c1b3558 100755 --- a/src/components/Table/index.tsx +++ b/src/components/Table/index.tsx @@ -20,7 +20,6 @@ export { makeNumericColumnPlanFact, makeNumericStartEnd, makeNumericMinMax, - makeNumericAvgRange, makeSelectColumn, makeTagColumn, makeTagInput, diff --git a/src/pages/WellOperations/WellDrillParams.jsx b/src/pages/WellOperations/WellDrillParams.jsx index 6391023..f3db0a1 100755 --- a/src/pages/WellOperations/WellDrillParams.jsx +++ b/src/pages/WellOperations/WellDrillParams.jsx @@ -1,17 +1,87 @@ import { useState, useEffect, useCallback, memo, useMemo } from 'react' +import { InputNumber } from 'antd' import { useWell } from '@asb/context' import { EditableTable, - makeSelectColumn, - makeNumericAvgRange, + makeGroupColumn, + makeNumericRender, makeNumericSorter, + makeSelectColumn, + RegExpIsFloat, } 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) => { let sectionTypes = await WellOperationService.getSectionTypes(idWell)