diff --git a/src/components/Table/Columns/numeric.tsx b/src/components/Table/Columns/numeric.tsx index d1a2aef..5599819 100755 --- a/src/components/Table/Columns/numeric.tsx +++ b/src/components/Table/Columns/numeric.tsx @@ -6,7 +6,22 @@ import { columnPropsOther, makeGroupColumn, RenderMethod } from '.' export const RegExpIsFloat = /^[-+]?\d+\.?\d*$/ -export const makeNumericRender = (fixed?: number, columnKey?: string): RenderMethod => (value, obj) => { +export const makeNumericRender = (fixed?: number): RenderMethod => (value) => { + let val = '-' + if ((value ?? null) !== null && Number.isFinite(+value)) { + val = (fixed ?? null) !== null + ? (+value).toFixed(fixed) + : (+value).toPrecision(5) + } + + return ( +
+ {val} +
+ ) +} + +export const makeNumericColorRender = (fixed?: number, columnKey?: string): RenderMethod => (value, obj) => { let val = '-' const isSelected = obj && columnKey ? obj[columnKey] : false if ((value ?? null) !== null && Number.isFinite(+value)) { @@ -22,7 +37,7 @@ export const makeNumericRender = (fixed?: number, columnKey?: ) } -export const makeNumericColumnOptions = (fixed?: number, sorterKey?: string, columnKey?: string): columnPropsOther => ({ +export const makeNumericColumnOptions = (fixed?: number, sorterKey?: string): columnPropsOther => ({ editable: true, initialValue: 0, width: 100, @@ -32,7 +47,20 @@ export const makeNumericColumnOptions = (fixed?: number, sorterKey?: string, col message: 'Введите число', pattern: RegExpIsFloat, }], - render: makeNumericRender(fixed, columnKey), + render: makeNumericRender(fixed), +}) + +export const makeNumericColumnOptionsWithColor = (fixed?: number, sorterKey?: string, columnKey?: string): columnPropsOther => ({ + editable: true, + initialValue: 0, + width: 100, + sorter: sorterKey ? makeNumericSorter(sorterKey) : undefined, + formItemRules: [{ + required: true, + message: 'Введите число', + pattern: RegExpIsFloat, + }], + render: makeNumericColorRender(fixed, columnKey), }) export const makeNumericColumn = ( @@ -104,9 +132,9 @@ export const makeNumericAvgRange = ( renderDelegate: (_: any, row: object) => any, width: string ) => makeGroupColumn(title, [ - makeNumericColumn('мин', dataIndex + 'Min', filters, filterDelegate, renderDelegate, width, makeNumericColumnOptions(fixed, dataIndex + 'Min', dataIndex + 'IsMin')), + 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, makeNumericColumnOptions(fixed, dataIndex + 'Max', dataIndex + 'IsMax')) + makeNumericColumn('макс', dataIndex + 'Max', filters, filterDelegate, renderDelegate, width, makeNumericColumnOptionsWithColor(fixed, dataIndex + 'Max', dataIndex + 'IsMax')) ]) export default makeNumericColumn diff --git a/src/pages/Analytics/WellCompositeEditor/NewParamsTable.jsx b/src/pages/Analytics/WellCompositeEditor/NewParamsTable.jsx index 817b617..a4c2c12 100755 --- a/src/pages/Analytics/WellCompositeEditor/NewParamsTable.jsx +++ b/src/pages/Analytics/WellCompositeEditor/NewParamsTable.jsx @@ -6,9 +6,8 @@ import { Table } from '@components/Table' import LoaderPortal from '@components/LoaderPortal' import { invokeWebApiWrapperAsync } from '@components/factory' import { DrillParamsService } from '@api' -import { getArrayConvertedObjectsIntoObjectsWithPrimitiveValues } from '@utils' -import { getColumns } from '@pages/WellOperations/WellDrillParams' +import { getColumns, convertValuesInObjectsToPrimitiveValues } from '@pages/WellOperations/WellDrillParams' export const NewParamsTable = memo(({ selectedWellsKeys }) => { const [params, setParams] = useState([]) @@ -26,7 +25,7 @@ export const NewParamsTable = memo(({ selectedWellsKeys }) => { async () => { setIsParamsModalVisible(true) const params = await DrillParamsService.getCompositeAll(well.id) - setParams(getArrayConvertedObjectsIntoObjectsWithPrimitiveValues(params)) + setParams(convertValuesInObjectsToPrimitiveValues(params)) }, setShowParamsLoader, `Не удалось загрузить список режимов`, diff --git a/src/pages/WellOperations/WellDrillParams.jsx b/src/pages/WellOperations/WellDrillParams.jsx index 236c7c6..7c7d7bb 100755 --- a/src/pages/WellOperations/WellDrillParams.jsx +++ b/src/pages/WellOperations/WellDrillParams.jsx @@ -10,8 +10,28 @@ import { import LoaderPortal from '@components/LoaderPortal' import { invokeWebApiWrapperAsync } from '@components/factory' import { DrillParamsService, WellOperationService } from '@api' -import { arrayOrDefault, getArrayConvertedObjectsIntoObjectsWithPrimitiveValues } from '@utils' +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) @@ -44,7 +64,7 @@ export const WellDrillParams = memo(() => { const updateParams = useCallback(async () => await invokeWebApiWrapperAsync( async () => { const params = arrayOrDefault(await DrillParamsService.getAll(well.id)) - setParams(getArrayConvertedObjectsIntoObjectsWithPrimitiveValues(params)) + setParams(convertValuesInObjectsToPrimitiveValues(params)) }, setShowLoader, `Не удалось загрузить список режимов бурения`, diff --git a/src/utils/functions/getArrayConvertedObjectsIntoObjectsWithPrimitiveValues.ts b/src/utils/functions/getArrayConvertedObjectsIntoObjectsWithPrimitiveValues.ts deleted file mode 100644 index c8a72f4..0000000 --- a/src/utils/functions/getArrayConvertedObjectsIntoObjectsWithPrimitiveValues.ts +++ /dev/null @@ -1,26 +0,0 @@ -export type ObjType = { - [key:string]: Object | any -} - -export function getArrayConvertedObjectsIntoObjectsWithPrimitiveValues(arr: Array) { - return arr.map(param => { - const newObj:ObjType = {} - 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 default getArrayConvertedObjectsIntoObjectsWithPrimitiveValues \ No newline at end of file diff --git a/src/utils/functions/index.ts b/src/utils/functions/index.ts index 87e4506..69fcf3c 100644 --- a/src/utils/functions/index.ts +++ b/src/utils/functions/index.ts @@ -27,6 +27,3 @@ export * from './svg' export * from './table_settings' export type { TableColumnSettings, TableSettings, TableSettingsStore } from './table_settings' - -export * from './getArrayConvertedObjectsIntoObjectsWithPrimitiveValues' -export type { ObjType } from './getArrayConvertedObjectsIntoObjectsWithPrimitiveValues'