From 292d4e0ef01fa7c7926af6cb37cb105ce8a199e4 Mon Sep 17 00:00:00 2001 From: ts_salikhov Date: Thu, 22 Sep 2022 17:38:43 +0400 Subject: [PATCH 1/8] =?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 | 40 ++++++++++++++++++-- src/components/Table/sorters.ts | 3 ++ src/pages/WellOperations/WellDrillParams.jsx | 7 +--- src/styles/index.css | 12 ++++++ 4 files changed, 53 insertions(+), 9 deletions(-) diff --git a/src/components/Table/Columns/numeric.tsx b/src/components/Table/Columns/numeric.tsx index 1b2ed3b..a205283 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 { makeNumericSorter, makeObjNumericSorter } from '../sorters' import { columnPropsOther, makeGroupColumn, RenderMethod } from '.' export const RegExpIsFloat = /^[-+]?\d+\.?\d*$/ @@ -21,6 +21,25 @@ export const makeNumericRender = (fixed?: number): RenderMeth ) } +type ObjRenderType = { + max: number + avg: number + min: number + isMax: boolean + isMin: boolean +} + +export const makeObjRender = (key: keyof ObjRenderType, boolKey?: keyof ObjRenderType): RenderMethod => (value: ObjRenderType) => { + const val = key ? value[key]: '-' + const isSelected = boolKey ? value[boolKey] : false + + return ( +
+ {val} +
+ ) +} + export const makeNumericColumnOptions = (fixed?: number, sorterKey?: string): columnPropsOther => ({ editable: true, initialValue: 0, @@ -34,6 +53,19 @@ export const makeNumericColumnOptions = (fixed?: number, sorterKey?: string): co render: makeNumericRender(fixed), }) +export const makeObjColumnOptions = (key: keyof ObjRenderType, sortedObj?: string, boolKey?: keyof ObjRenderType): columnPropsOther => ({ + editable: true, + initialValue: 0, + width: 100, + sorter: sortedObj && key ? makeObjNumericSorter(sortedObj, key) : undefined, + formItemRules: [{ + required: true, + message: 'Введите число', + pattern: RegExpIsFloat, + }], + render: makeObjRender(key, boolKey), +}) + export const makeNumericColumn = ( title: ReactNode, dataIndex: string, @@ -103,9 +135,9 @@ export const makeNumericAvgRange = ( 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')) + makeNumericColumn('мин', dataIndex, filters, filterDelegate, renderDelegate, width, makeObjColumnOptions('min', dataIndex, 'isMin')), + makeNumericColumn('сред', dataIndex, filters, filterDelegate, renderDelegate, width, makeObjColumnOptions('avg', dataIndex)), + makeNumericColumn('макс', dataIndex, filters, filterDelegate, renderDelegate, width, makeObjColumnOptions('max', dataIndex, 'isMax')) ]) export default makeNumericColumn diff --git a/src/components/Table/sorters.ts b/src/components/Table/sorters.ts index 11fb7e2..f0a1ac9 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 makeObjNumericSorter = (obj: keyof DataType, key: keyof DataType) => + (a: DataType>, b: DataType>) => Number(a[obj][key]) - Number(b[obj][key]) + 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..aab2d2d 100755 --- a/src/pages/WellOperations/WellDrillParams.jsx +++ b/src/pages/WellOperations/WellDrillParams.jsx @@ -2,7 +2,7 @@ import { useState, useEffect, useCallback, memo, useMemo } from 'react' import { useWell } from '@asb/context' import { - EditableTable, + Table, makeSelectColumn, makeNumericAvgRange, makeNumericSorter, @@ -81,15 +81,12 @@ export const WellDrillParams = memo(() => { return ( - 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 From 95950458c892b953b5be6a9070046160998cb509 Mon Sep 17 00:00:00 2001 From: ts_salikhov Date: Fri, 23 Sep 2022 16:23:10 +0400 Subject: [PATCH 2/8] =?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 | 47 ++++--------------- src/components/Table/sorters.ts | 3 -- .../WellCompositeEditor/NewParamsTable.jsx | 3 +- src/pages/WellOperations/WellDrillParams.jsx | 13 ++--- ...edObjectsIntoObjectsWithPrimitiveValues.ts | 26 ++++++++++ src/utils/functions/index.ts | 3 ++ 6 files changed, 46 insertions(+), 49 deletions(-) create mode 100644 src/utils/functions/getArrayConvertedObjectsIntoObjectsWithPrimitiveValues.ts diff --git a/src/components/Table/Columns/numeric.tsx b/src/components/Table/Columns/numeric.tsx index a205283..d1a2aef 100755 --- a/src/components/Table/Columns/numeric.tsx +++ b/src/components/Table/Columns/numeric.tsx @@ -1,38 +1,20 @@ import { InputNumber } from 'antd' import { ReactNode } from 'react' -import { makeNumericSorter, makeObjNumericSorter } from '../sorters' +import { makeNumericSorter } from '../sorters' import { columnPropsOther, makeGroupColumn, RenderMethod } from '.' export const RegExpIsFloat = /^[-+]?\d+\.?\d*$/ -export const makeNumericRender = (fixed?: number): RenderMethod => (value) => { +export const makeNumericRender = (fixed?: number, columnKey?: string): RenderMethod => (value, obj) => { let val = '-' + const isSelected = obj && columnKey ? obj[columnKey] : false if ((value ?? null) !== null && Number.isFinite(+value)) { val = (fixed ?? null) !== null ? (+value).toFixed(fixed) : (+value).toPrecision(5) } - return ( -
- {val} -
- ) -} - -type ObjRenderType = { - max: number - avg: number - min: number - isMax: boolean - isMin: boolean -} - -export const makeObjRender = (key: keyof ObjRenderType, boolKey?: keyof ObjRenderType): RenderMethod => (value: ObjRenderType) => { - const val = key ? value[key]: '-' - const isSelected = boolKey ? value[boolKey] : false - return (
{val} @@ -40,7 +22,7 @@ export const makeObjRender = (key: keyof ObjRenderType, boolKey?: keyof ObjRende ) } -export const makeNumericColumnOptions = (fixed?: number, sorterKey?: string): columnPropsOther => ({ +export const makeNumericColumnOptions = (fixed?: number, sorterKey?: string, columnKey?: string): columnPropsOther => ({ editable: true, initialValue: 0, width: 100, @@ -50,20 +32,7 @@ export const makeNumericColumnOptions = (fixed?: number, sorterKey?: string): co message: 'Введите число', pattern: RegExpIsFloat, }], - render: makeNumericRender(fixed), -}) - -export const makeObjColumnOptions = (key: keyof ObjRenderType, sortedObj?: string, boolKey?: keyof ObjRenderType): columnPropsOther => ({ - editable: true, - initialValue: 0, - width: 100, - sorter: sortedObj && key ? makeObjNumericSorter(sortedObj, key) : undefined, - formItemRules: [{ - required: true, - message: 'Введите число', - pattern: RegExpIsFloat, - }], - render: makeObjRender(key, boolKey), + render: makeNumericRender(fixed, columnKey), }) export const makeNumericColumn = ( @@ -135,9 +104,9 @@ export const makeNumericAvgRange = ( renderDelegate: (_: any, row: object) => any, width: string ) => makeGroupColumn(title, [ - makeNumericColumn('мин', dataIndex, filters, filterDelegate, renderDelegate, width, makeObjColumnOptions('min', dataIndex, 'isMin')), - makeNumericColumn('сред', dataIndex, filters, filterDelegate, renderDelegate, width, makeObjColumnOptions('avg', dataIndex)), - makeNumericColumn('макс', dataIndex, filters, filterDelegate, renderDelegate, width, makeObjColumnOptions('max', dataIndex, 'isMax')) + makeNumericColumn('мин', dataIndex + 'Min', filters, filterDelegate, renderDelegate, width, makeNumericColumnOptions(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')) ]) export default makeNumericColumn diff --git a/src/components/Table/sorters.ts b/src/components/Table/sorters.ts index f0a1ac9..11fb7e2 100755 --- a/src/components/Table/sorters.ts +++ b/src/components/Table/sorters.ts @@ -7,9 +7,6 @@ import { DataType } from './Columns' export const makeNumericSorter = (key: keyof DataType) => (a: DataType, b: DataType) => Number(a[key]) - Number(b[key]) -export const makeObjNumericSorter = (obj: keyof DataType, key: keyof DataType) => - (a: DataType>, b: DataType>) => Number(a[obj][key]) - Number(b[obj][key]) - 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 bf504df..817b617 100755 --- a/src/pages/Analytics/WellCompositeEditor/NewParamsTable.jsx +++ b/src/pages/Analytics/WellCompositeEditor/NewParamsTable.jsx @@ -6,6 +6,7 @@ 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' @@ -25,7 +26,7 @@ export const NewParamsTable = memo(({ selectedWellsKeys }) => { async () => { setIsParamsModalVisible(true) const params = await DrillParamsService.getCompositeAll(well.id) - setParams(params) + setParams(getArrayConvertedObjectsIntoObjectsWithPrimitiveValues(params)) }, setShowParamsLoader, `Не удалось загрузить список режимов`, diff --git a/src/pages/WellOperations/WellDrillParams.jsx b/src/pages/WellOperations/WellDrillParams.jsx index aab2d2d..236c7c6 100755 --- a/src/pages/WellOperations/WellDrillParams.jsx +++ b/src/pages/WellOperations/WellDrillParams.jsx @@ -2,7 +2,7 @@ import { useState, useEffect, useCallback, memo, useMemo } from 'react' import { useWell } from '@asb/context' import { - Table, + EditableTable, makeSelectColumn, makeNumericAvgRange, makeNumericSorter, @@ -10,7 +10,7 @@ import { import LoaderPortal from '@components/LoaderPortal' import { invokeWebApiWrapperAsync } from '@components/factory' import { DrillParamsService, WellOperationService } from '@api' -import { arrayOrDefault } from '@utils' +import { arrayOrDefault, getArrayConvertedObjectsIntoObjectsWithPrimitiveValues } from '@utils' export const getColumns = async (idWell) => { @@ -44,9 +44,7 @@ export const WellDrillParams = memo(() => { const updateParams = useCallback(async () => await invokeWebApiWrapperAsync( async () => { const params = arrayOrDefault(await DrillParamsService.getAll(well.id)) - // Typescript против использования числа в качестве типа значения select - params.forEach((param) => param.idWellSectionType = `${param.idWellSectionType}`) - setParams(params) + setParams(getArrayConvertedObjectsIntoObjectsWithPrimitiveValues(params)) }, setShowLoader, `Не удалось загрузить список режимов бурения`, @@ -81,12 +79,15 @@ export const WellDrillParams = memo(() => { return ( - diff --git a/src/utils/functions/getArrayConvertedObjectsIntoObjectsWithPrimitiveValues.ts b/src/utils/functions/getArrayConvertedObjectsIntoObjectsWithPrimitiveValues.ts new file mode 100644 index 0000000..c8a72f4 --- /dev/null +++ b/src/utils/functions/getArrayConvertedObjectsIntoObjectsWithPrimitiveValues.ts @@ -0,0 +1,26 @@ +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 69fcf3c..87e4506 100644 --- a/src/utils/functions/index.ts +++ b/src/utils/functions/index.ts @@ -27,3 +27,6 @@ export * from './svg' export * from './table_settings' export type { TableColumnSettings, TableSettings, TableSettingsStore } from './table_settings' + +export * from './getArrayConvertedObjectsIntoObjectsWithPrimitiveValues' +export type { ObjType } from './getArrayConvertedObjectsIntoObjectsWithPrimitiveValues' From b74d6d1e4f782b9eabf757a81acf7ee2fbdff9fe Mon Sep 17 00:00:00 2001 From: ts_salikhov Date: Mon, 26 Sep 2022 17:23:44 +0400 Subject: [PATCH 3/8] =?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 | 38 ++++++++++++++++--- .../WellCompositeEditor/NewParamsTable.jsx | 5 +-- src/pages/WellOperations/WellDrillParams.jsx | 24 +++++++++++- ...edObjectsIntoObjectsWithPrimitiveValues.ts | 26 ------------- src/utils/functions/index.ts | 3 -- 5 files changed, 57 insertions(+), 39 deletions(-) delete mode 100644 src/utils/functions/getArrayConvertedObjectsIntoObjectsWithPrimitiveValues.ts 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' From 0ce979fdc812a45dbc382457aa08d81dac727082 Mon Sep 17 00:00:00 2001 From: ts_salikhov Date: Wed, 28 Sep 2022 14:33:34 +0400 Subject: [PATCH 4/8] =?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/EditableTable.jsx | 20 ++++++++- src/pages/WellOperations/WellDrillParams.jsx | 46 ++++++++++++++++++++ 2 files changed, 65 insertions(+), 1 deletion(-) diff --git a/src/components/Table/EditableTable.jsx b/src/components/Table/EditableTable.jsx index a94955e..2d75dcd 100755 --- a/src/components/Table/EditableTable.jsx +++ b/src/components/Table/EditableTable.jsx @@ -113,10 +113,28 @@ export const EditableTable = memo(({ const newData = [...data] const index = newData.findIndex((item) => record.key === item.key) const item = newData[index] - const newItem = { ...item, ...row } + let newItem = { ...item, ...row } 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/pages/WellOperations/WellDrillParams.jsx b/src/pages/WellOperations/WellDrillParams.jsx index 7c7d7bb..65d3b59 100755 --- a/src/pages/WellOperations/WellDrillParams.jsx +++ b/src/pages/WellOperations/WellDrillParams.jsx @@ -54,6 +54,51 @@ 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) @@ -108,6 +153,7 @@ export const WellDrillParams = memo(() => { onRowAdd={tableHandlers.add} onRowEdit={tableHandlers.edit} onRowDelete={tableHandlers.delete} + objRowType={objRowType} pagination={false} /> From e0f8583f99833f3450704c87da9415dacc0fceda Mon Sep 17 00:00:00 2001 From: ts_salikhov Date: Thu, 29 Sep 2022 13:36:07 +0400 Subject: [PATCH 5/8] =?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} /> From c82fec8f60eb4be57ad9d8deb0d2888fd4fdf962 Mon Sep 17 00:00:00 2001 From: ts_salikhov Date: Thu, 29 Sep 2022 13:37:48 +0400 Subject: [PATCH 6/8] =?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/EditableTable.jsx | 2 +- src/pages/WellOperations/WellDrillParams.jsx | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/components/Table/EditableTable.jsx b/src/components/Table/EditableTable.jsx index f9fbde1..a94955e 100755 --- a/src/components/Table/EditableTable.jsx +++ b/src/components/Table/EditableTable.jsx @@ -113,7 +113,7 @@ export const EditableTable = memo(({ const newData = [...data] const index = newData.findIndex((item) => record.key === item.key) const item = newData[index] - let newItem = { ...item, ...row } + const newItem = { ...item, ...row } newData.splice(index, 1, newItem) diff --git a/src/pages/WellOperations/WellDrillParams.jsx b/src/pages/WellOperations/WellDrillParams.jsx index 012e86b..6391023 100755 --- a/src/pages/WellOperations/WellDrillParams.jsx +++ b/src/pages/WellOperations/WellDrillParams.jsx @@ -12,6 +12,7 @@ import { invokeWebApiWrapperAsync } from '@components/factory' import { DrillParamsService, WellOperationService } from '@api' import { arrayOrDefault } from '@utils' + export const getColumns = async (idWell) => { let sectionTypes = await WellOperationService.getSectionTypes(idWell) sectionTypes = Object.entries(sectionTypes).map(([id, value]) => ({ From 38fa8ffbebf6259b5d61593ceaa9e7dee367dc7b Mon Sep 17 00:00:00 2001 From: ts_salikhov Date: Thu, 29 Sep 2022 16:26:55 +0400 Subject: [PATCH 7/8] =?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) From 9d5c38f984b56dfd2a88163011fa712155c7f1c7 Mon Sep 17 00:00:00 2001 From: ts_salikhov Date: Thu, 29 Sep 2022 16:28:14 +0400 Subject: [PATCH 8/8] =?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 | 1 - src/pages/WellOperations/WellDrillParams.jsx | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/components/Table/Columns/numeric.tsx b/src/components/Table/Columns/numeric.tsx index ce9a947..3737ca6 100755 --- a/src/components/Table/Columns/numeric.tsx +++ b/src/components/Table/Columns/numeric.tsx @@ -21,7 +21,6 @@ export const makeNumericRender = (fixed?: number): RenderMeth ) } - export const makeNumericColumnOptions = (fixed?: number, sorterKey?: string): columnPropsOther => ({ editable: true, initialValue: 0, diff --git a/src/pages/WellOperations/WellDrillParams.jsx b/src/pages/WellOperations/WellDrillParams.jsx index f3db0a1..486b422 100755 --- a/src/pages/WellOperations/WellDrillParams.jsx +++ b/src/pages/WellOperations/WellDrillParams.jsx @@ -4,10 +4,10 @@ import { InputNumber } from 'antd' import { useWell } from '@asb/context' import { EditableTable, + makeSelectColumn, makeGroupColumn, makeNumericRender, makeNumericSorter, - makeSelectColumn, RegExpIsFloat, } from '@components/Table' import LoaderPortal from '@components/LoaderPortal'