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 1b2ed3b..3737ca6 100755 --- a/src/components/Table/Columns/numeric.tsx +++ b/src/components/Table/Columns/numeric.tsx @@ -94,18 +94,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 | 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 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/components/Table/sorters.ts b/src/components/Table/sorters.ts index 11fb7e2..80ca5c0 100755 --- a/src/components/Table/sorters.ts +++ b/src/components/Table/sorters.ts @@ -7,6 +7,9 @@ import { DataType } from './Columns' export const makeNumericSorter = (key: keyof DataType) => (a: DataType, b: DataType) => Number(a[key]) - Number(b[key]) +export const makeNumericObjSorter = (key: [string, string]) => + (a: DataType, b: DataType) => Number(a[key[0]][key[1]]) - Number(b[key[0]][key[1]]) + export const makeStringSorter = (key: keyof DataType) => (a?: DataType | null, b?: DataType | null) => { if (!a && !b) return 0 if (!a) return 1 diff --git a/src/pages/WellOperations/WellDrillParams.jsx b/src/pages/WellOperations/WellDrillParams.jsx index 6391023..486b422 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, + 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) diff --git a/src/styles/index.css b/src/styles/index.css index b095532..bde3eb8 100755 --- a/src/styles/index.css +++ b/src/styles/index.css @@ -141,4 +141,16 @@ code { .download-link { height: 32px; padding: 4px 15px; +} + +.ant-table-cell:has(.color-pale-green) { + background-color: #98fb98; +} + +.ant-table-tbody > tr > td.ant-table-cell-row-hover:has( > div.color-pale-green) { + background: #98fb98; +} + +.color-pale-green { + background-color: #98fb98; } \ No newline at end of file