From e0f8583f99833f3450704c87da9415dacc0fceda Mon Sep 17 00:00:00 2001 From: ts_salikhov Date: Thu, 29 Sep 2022 13:36:07 +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/numeric.tsx | 43 ++++++++--- src/components/Table/EditableTable.jsx | 18 ----- src/components/Table/sorters.ts | 3 + .../WellCompositeEditor/NewParamsTable.jsx | 4 +- src/pages/WellOperations/WellDrillParams.jsx | 71 +------------------ 5 files changed, 41 insertions(+), 98 deletions(-) diff --git a/src/components/Table/Columns/numeric.tsx b/src/components/Table/Columns/numeric.tsx index 5599819..db028a8 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 { makeNumericSorter } from '../sorters' +import { makeNumericObjSorter, makeNumericSorter } from '../sorters' import { columnPropsOther, makeGroupColumn, RenderMethod } from '.' export const RegExpIsFloat = /^[-+]?\d+\.?\d*$/ @@ -21,9 +21,10 @@ export const makeNumericRender = (fixed?: number): RenderMeth ) } -export const makeNumericColorRender = (fixed?: number, columnKey?: string): RenderMethod => (value, obj) => { +export const makeNumericObjRender = (fixed?: number, columnKey?: [string, string]): RenderMethod => (value, obj) => { let val = '-' - const isSelected = obj && columnKey ? obj[columnKey] : false + 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) @@ -50,17 +51,17 @@ export const makeNumericColumnOptions = (fixed?: number, sorterKey?: string): co render: makeNumericRender(fixed), }) -export const makeNumericColumnOptionsWithColor = (fixed?: number, sorterKey?: string, columnKey?: string): columnPropsOther => ({ +export const makeNumericColumnOptionsWithColor = (fixed?: number, sorterKey?: [string, string], columnKey?: [string, string]): columnPropsOther => ({ editable: true, initialValue: 0, width: 100, - sorter: sorterKey ? makeNumericSorter(sorterKey) : undefined, + sorter: sorterKey ? makeNumericObjSorter(sorterKey) : undefined, formItemRules: [{ required: true, message: 'Введите число', pattern: RegExpIsFloat, }], - render: makeNumericColorRender(fixed, columnKey), + render: makeNumericObjRender(fixed, columnKey), }) export const makeNumericColumn = ( @@ -85,6 +86,28 @@ 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, @@ -128,13 +151,13 @@ export const makeNumericAvgRange = ( dataIndex: string, fixed: number, filters: object[], - filterDelegate: (key: string | number) => any, + filterDelegate: (key: [string, string]) => any, renderDelegate: (_: any, row: object) => any, width: string ) => makeGroupColumn(title, [ - makeNumericColumn('мин', dataIndex + 'Min', filters, filterDelegate, renderDelegate, width, makeNumericColumnOptionsWithColor(fixed, dataIndex + 'Min', dataIndex + 'IsMin')), - makeNumericColumn('сред', dataIndex + 'Avg', filters, filterDelegate, renderDelegate, width, makeNumericColumnOptions(fixed, dataIndex + 'Avg')), - makeNumericColumn('макс', dataIndex + 'Max', filters, filterDelegate, renderDelegate, width, makeNumericColumnOptionsWithColor(fixed, dataIndex + 'Max', dataIndex + 'IsMax')) + 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/EditableTable.jsx b/src/components/Table/EditableTable.jsx index 2d75dcd..f9fbde1 100755 --- a/src/components/Table/EditableTable.jsx +++ b/src/components/Table/EditableTable.jsx @@ -117,24 +117,6 @@ export const EditableTable = memo(({ newData.splice(index, 1, newItem) - if (otherTableProps.objRowType) { - const newObj = {} - const objRowType = otherTableProps.objRowType - for (const itemElement in objRowType) { - if (typeof objRowType[itemElement] === 'object') { - for (const el in objRowType[itemElement]) { - if (!newObj[itemElement]) { - newObj[itemElement] = {} - } - newObj[itemElement][el] = newItem[itemElement + el[0].toUpperCase() + el.slice(1)] ?? objRowType[itemElement][el] - } - } else { - newObj[itemElement] = newItem[itemElement] - } - } - newItem = newObj - } - if (item.key === newRowKeyValue) item.key = newRowKeyValue + newData.length 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/Analytics/WellCompositeEditor/NewParamsTable.jsx b/src/pages/Analytics/WellCompositeEditor/NewParamsTable.jsx index a4c2c12..bf504df 100755 --- a/src/pages/Analytics/WellCompositeEditor/NewParamsTable.jsx +++ b/src/pages/Analytics/WellCompositeEditor/NewParamsTable.jsx @@ -7,7 +7,7 @@ import LoaderPortal from '@components/LoaderPortal' import { invokeWebApiWrapperAsync } from '@components/factory' import { DrillParamsService } from '@api' -import { getColumns, convertValuesInObjectsToPrimitiveValues } from '@pages/WellOperations/WellDrillParams' +import { getColumns } from '@pages/WellOperations/WellDrillParams' export const NewParamsTable = memo(({ selectedWellsKeys }) => { const [params, setParams] = useState([]) @@ -25,7 +25,7 @@ export const NewParamsTable = memo(({ selectedWellsKeys }) => { async () => { setIsParamsModalVisible(true) const params = await DrillParamsService.getCompositeAll(well.id) - setParams(convertValuesInObjectsToPrimitiveValues(params)) + setParams(params) }, setShowParamsLoader, `Не удалось загрузить список режимов`, diff --git a/src/pages/WellOperations/WellDrillParams.jsx b/src/pages/WellOperations/WellDrillParams.jsx index 65d3b59..012e86b 100755 --- a/src/pages/WellOperations/WellDrillParams.jsx +++ b/src/pages/WellOperations/WellDrillParams.jsx @@ -12,27 +12,6 @@ import { invokeWebApiWrapperAsync } from '@components/factory' import { DrillParamsService, WellOperationService } from '@api' import { arrayOrDefault } from '@utils' -export function convertValuesInObjectsToPrimitiveValues(arr) { - return arr.map(param => { - const newObj = {} - for (const paramElement in param) { - if (typeof param[paramElement] === 'object') { - for (const item in param[paramElement]) { - newObj[paramElement + item[0].toUpperCase() + item.slice(1)] = param[paramElement][item] - } - } else { - // Typescript против использования числа в качестве типа значения select - if (paramElement === 'idWellSectionType') { - newObj[paramElement] = String(param[paramElement]) - } else { - newObj[paramElement] = param[paramElement] - } - } - } - return newObj - }) -} - export const getColumns = async (idWell) => { let sectionTypes = await WellOperationService.getSectionTypes(idWell) sectionTypes = Object.entries(sectionTypes).map(([id, value]) => ({ @@ -54,51 +33,6 @@ export const getColumns = async (idWell) => { ] } -const objRowType = { - 'id': 0, - 'idWell': 0, - 'depth': { - 'min': 0, - 'max': 0 - }, - 'idWellSectionType': 0, - 'axialLoad': { - 'min': 0, - 'max': 0, - 'avg': 0, - 'isMax': false, - 'isMin': false, - }, - 'pressure': { - 'min': 0, - 'max': 0, - 'avg': 0, - 'isMax': false, - 'isMin': false, - }, - 'rotorTorque': { - 'min': 0, - 'max': 0, - 'avg': 0, - 'isMax': false, - 'isMin': false, - }, - 'rotorSpeed': { - 'min': 0, - 'max': 0, - 'avg': 0, - 'isMax': false, - 'isMin': false, - }, - 'flow': { - 'min': 0, - 'max': 0, - 'avg': 0, - 'isMax': false, - 'isMin': false, - } -} - export const WellDrillParams = memo(() => { const [params, setParams] = useState([]) const [showLoader, setShowLoader] = useState(false) @@ -109,7 +43,9 @@ export const WellDrillParams = memo(() => { const updateParams = useCallback(async () => await invokeWebApiWrapperAsync( async () => { const params = arrayOrDefault(await DrillParamsService.getAll(well.id)) - setParams(convertValuesInObjectsToPrimitiveValues(params)) + // Typescript против использования числа в качестве типа значения select + params.forEach((param) => param.idWellSectionType = `${param.idWellSectionType}`) + setParams(params) }, setShowLoader, `Не удалось загрузить список режимов бурения`, @@ -153,7 +89,6 @@ export const WellDrillParams = memo(() => { onRowAdd={tableHandlers.add} onRowEdit={tableHandlers.edit} onRowDelete={tableHandlers.delete} - objRowType={objRowType} pagination={false} />