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} />