From 564ea43a808aad93d9640fa9cd484d0ae02c6b94 Mon Sep 17 00:00:00 2001 From: ts_salikhov Date: Tue, 20 Sep 2022 12:39:05 +0400 Subject: [PATCH 01/10] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B0=20=D1=81=D1=82=D1=80=D0=B0=D0=BD=D0=B8=D1=86?= =?UTF-8?q?=D0=B0=20"=D0=9D=D0=B0=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D0=BA?= =?UTF-8?q?=D0=B0"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/d3/D3HorizontalChart.tsx | 149 ++++++++++++++ src/pages/Telemetry/OperationTime/index.tsx | 210 ++++++++++++++++++++ src/pages/Telemetry/index.jsx | 3 + src/styles/d3.less | 5 + 4 files changed, 367 insertions(+) create mode 100644 src/components/d3/D3HorizontalChart.tsx create mode 100644 src/pages/Telemetry/OperationTime/index.tsx diff --git a/src/components/d3/D3HorizontalChart.tsx b/src/components/d3/D3HorizontalChart.tsx new file mode 100644 index 0000000..421108b --- /dev/null +++ b/src/components/d3/D3HorizontalChart.tsx @@ -0,0 +1,149 @@ +import React, { memo, useEffect } from 'react' +import * as d3 from 'd3' + +import LoaderPortal from '@components/LoaderPortal' +import { useElementSize } from 'usehooks-ts' + + +import '@styles/d3.less' + +type DataType = { + name: string + percent: number +} + +type D3HorizontalChartProps = { + width?: string + height?: string + data: DataType[] + colors?: string[] +} + +const D3HorizontalChart = memo(( + { + width: givenWidth = '100%', + height: givenHeight = '100%', + data, + colors + }: D3HorizontalChartProps) => { + + const [rootRef, { width, height }] = useElementSize() + + const margin = { top: 50, right: 100, bottom: 50, left: 100 } + + useEffect(() => { + if (width < 100 || height < 100) return + const _width = width - margin.left - margin.right + const _height = height - margin.top - margin.bottom + + const svg = d3.select('#d3-horizontal-chart') + .attr('width', '100%') + .attr('height', '100%') + .append('g') + .attr('transform', `translate(${margin.left},${margin.top})`) + + const percents = ['percents'] + const names = data.map(d => d.name) + + const stackedData = d3.stack() + //@ts-ignore + .keys(percents)(data) + + const xMax = 100 + + // scales + + const x = d3.scaleLinear() + .domain([0, xMax]) + .range([0, _width]) + + const y = d3.scaleBand() + .domain(names) + .range([0, _height]) + .padding(0.25) + + // axes + + const xAxisTop = d3.axisTop(x) + .tickValues([0, 25, 50, 75, 100]) + .tickFormat(d => d + '%') + + const xAxisBottom = d3.axisBottom(x) + .tickValues([0, 25, 50, 75, 100]) + .tickFormat(d => d + '%') + + const yAxisLeft = d3.axisLeft(y) + + const gridlines = d3.axisBottom(x) + .tickValues([0, 25, 50, 75, 100]) + .tickFormat(d => '') + .tickSize(_height) + + const yAxisRight = d3.axisRight(y) + .ticks(0) + .tickValues([]) + .tickFormat(d => '') + + svg.append('g') + .attr('transform', `translate(0,0)`) + .attr("class", "grid-line") + .call(g => g.select('.domain').remove()) + .call(gridlines) + + svg.append('g') + .attr('transform', `translate(0,0)`) + .call(xAxisTop) + + svg.append("g") + .call(yAxisLeft) + + svg.append('g') + .attr('transform', `translate(0,${_height})`) + .call(xAxisBottom) + + svg.append('g') + .attr('transform', `translate(${_width},0)`) + .call(yAxisRight) + + const layers = svg.append('g') + .selectAll('g') + .data(stackedData) + .join('g') + + // transition for bars + const duration = 1000 + const t = d3.transition() + .duration(duration) + .ease(d3.easeLinear) + + layers.each(function() { + d3.select(this) + .selectAll('rect') + //@ts-ignore + .data(d => d) + .join('rect') + .attr('fill', (d, i) => colors ? colors[i] : 'black') + //@ts-ignore + .attr('y', d => y(d.data.name)) + .attr('height', y.bandwidth()) + //@ts-ignore + .transition(t) + //@ts-ignore + .attr('width', d => x(d.data.percent)) + }) + + return () => { + svg.selectAll("g").selectAll("*").remove() + } + }, [width, height, data]) + + return ( + +
+ +
+
+ ) +}) + +export default D3HorizontalChart \ No newline at end of file diff --git a/src/pages/Telemetry/OperationTime/index.tsx b/src/pages/Telemetry/OperationTime/index.tsx new file mode 100644 index 0000000..8764d34 --- /dev/null +++ b/src/pages/Telemetry/OperationTime/index.tsx @@ -0,0 +1,210 @@ +import React, { ReactNode, useEffect, useState } from 'react' +import { Col, Row, Select } from 'antd' +import { Moment } from 'moment' + +import { DateRangeWrapper, makeColumn, Table } from '@components/Table' +import LoaderPortal from '@components/LoaderPortal' +import { arrayOrDefault, wrapPrivateComponent } from '@utils' +import D3HorizontalChart from '@components/d3/D3HorizontalChart' +import { useWell } from '@asb/context' +import { invokeWebApiWrapperAsync } from '@components/factory' +import { SubsystemOperationTimeService } from '@api' + +const { Option } = Select; + +type DataType = { + idSubsystem: number + subsystemName: string + usedTimeHours: number + kUsage: number + k2: number +} + +const _data: DataType[] = [ + { + "idSubsystem": 1, + "subsystemName": "Keруррурk", + "usedTimeHours": 2, + "kUsage": 0.45, + "k2": 1 + }, + { + "idSubsystem": 2, + "subsystemName": "Lol", + "usedTimeHours": 0, + "kUsage": 0.24, + "k2": 0 + }, + { + "idSubsystem": 3, + "subsystemName": "kek", + "usedTimeHours": 0, + "kUsage": 0.37, + "k2": 0 + }, + { + "idSubsystem": 4, + "subsystemName": "keklol", + "usedTimeHours": 0, + "kUsage": 0.73, + "k2": 0 + }, + { + "idSubsystem": 5, + "subsystemName": "Keруррурk1", + "usedTimeHours": 2, + "kUsage": 0.45, + "k2": 1 + }, + { + "idSubsystem": 6, + "subsystemName": "Lol2", + "usedTimeHours": 0, + "kUsage": 0.24, + "k2": 0 + }, + { + "idSubsystem": 7, + "subsystemName": "kek3", + "usedTimeHours": 0, + "kUsage": 0.37, + "k2": 0 + }, + { + "idSubsystem": 8, + "subsystemName": "keklol4", + "usedTimeHours": 0, + "kUsage": 0.73, + "k2": 0 + }, +] + +const subsystemColors = [ + '#1abc9c', + '#16a085', + '#2ecc71', + '#27ae60', + '#3498db', + '#2980b9', + '#9b59b6', + '#8e44ad', + '#34495e', + '#2c3e50', + '#f1c40f', + '#f39c12', + '#e67e22', + '#d35400', + '#e74c3c', + '#c0392b', + '#ecf0f1', + '#bdc3c7', + '#95a5a6', + '#7f8c8d', +] + +const tableColumns = [ + makeColumn('Цвет', 'color', { width: 50, render: (color) => ( +
+ ) }), + makeColumn('Подсистема', 'subsystemName'), + makeColumn('Время работы, ч', 'usedTimeHours'), + makeColumn('Активность, %', 'kUsage', { render: (d) => d * 100 }) +] + +const OperationTime = () => { + const [showLoader, setShowLoader] = useState(false) + const [data1, setData1] = useState([]) + const [data, setData] = useState(_data) + const [dateRange, setDateRange] = useState([]) + const [childrenData, setChildrenData] = useState([]) + const [well] = useWell() + + const errorNotifyText = `Не удалось загрузить данные` + + useEffect(() => { + + invokeWebApiWrapperAsync( + async () => { + if (!well.id) return + try { + setData1(arrayOrDefault(await SubsystemOperationTimeService.getStat( + well.id, + undefined, + dateRange[1] ? dateRange[0]?.toISOString() : undefined, + dateRange[1]?.toISOString(), + ))) + } catch(e) { + setData1([]) + throw e + } + }, + setShowLoader, + errorNotifyText, + { actionName: 'Получение данных по скважине', well } + ) + }, [dateRange]) + + useEffect(() => { + setChildrenData(_data.map((item) => ( + + ))) + }, [data]) + + const selectChange = (value: string[]) => { + + setData(_data.reduce((previousValue: DataType[], currentValue) => { + if (value.includes(currentValue.subsystemName)) { + previousValue.push(currentValue) + } + return previousValue + }, [])) + + } + + return ( + +

Фильтр подсистем

+ + + + + + setDateRange(dateRange)} + value={[dateRange[0], dateRange[1]]} + /> + + +
+ ({name: item.subsystemName, percent: item.kUsage * 100}))} + colors={subsystemColors} + width={'100%'} + height={'50vh'} + /> +
+ ({...d, color: subsystemColors[i]}))} + scroll={{ y: '25vh', x: true }} + pagination={false} + /> + + ) +} + +export default wrapPrivateComponent(OperationTime, { + requirements: [], + title: 'Наработка', + route: 'operation_time', +}) \ No newline at end of file diff --git a/src/pages/Telemetry/index.jsx b/src/pages/Telemetry/index.jsx index 9048ba5..d85f7e8 100755 --- a/src/pages/Telemetry/index.jsx +++ b/src/pages/Telemetry/index.jsx @@ -12,6 +12,7 @@ import Messages from './Messages' import Operations from './Operations' import DashboardNNB from './DashboardNNB' import TelemetryView from './TelemetryView' +import OperationTime from './OperationTime' import '@styles/index.css' @@ -30,6 +31,7 @@ const Telemetry = memo(() => { } /> + @@ -43,6 +45,7 @@ const Telemetry = memo(() => { } /> } /> } /> + } /> diff --git a/src/styles/d3.less b/src/styles/d3.less index c009c17..2e48ca4 100644 --- a/src/styles/d3.less +++ b/src/styles/d3.less @@ -116,6 +116,11 @@ } } +.grid-line line { + stroke: #ddd; + stroke-dasharray: 4 +} + @media (max-width: 1800px) { .asb-d3-chart .adaptive-tooltip { font-size: 11px; From 292d4e0ef01fa7c7926af6cb37cb105ce8a199e4 Mon Sep 17 00:00:00 2001 From: ts_salikhov Date: Thu, 22 Sep 2022 17:38:43 +0400 Subject: [PATCH 02/10] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2?= =?UTF-8?q?=D0=BB=D0=B5=D0=BD=D0=BE=20=D0=BE=D1=82=D0=BE=D0=B1=D1=80=D0=B0?= =?UTF-8?q?=D0=B6=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=B4=D0=B0=D0=BD=D0=BD=D1=8B?= =?UTF-8?q?=D1=85=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?= =?UTF-8?q?=D1=80=D0=B5=D0=B6=D0=B8=D0=BC=D1=8B=20=D1=82=D0=B5=D0=BA=D1=83?= =?UTF-8?q?=D1=89=D0=B5=D0=B9=20=D1=81=D0=BA=D0=B2=D0=B0=D0=B6=D0=B8=D0=BD?= =?UTF-8?q?=D1=8B"=20=D0=B8=20=D0=B2=20=D1=82=D0=B0=D0=B1=D0=BB=D0=B8?= =?UTF-8?q?=D1=86=D0=B5=20=D0=BD=D0=B0=20=D1=81=D1=82=D1=80=D0=B0=D0=BD?= =?UTF-8?q?=D0=B8=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 03/10] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2?= =?UTF-8?q?=D0=BB=D0=B5=D0=BD=D0=BE=20=D0=BE=D1=82=D0=BE=D0=B1=D1=80=D0=B0?= =?UTF-8?q?=D0=B6=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=B4=D0=B0=D0=BD=D0=BD=D1=8B?= =?UTF-8?q?=D1=85=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?= =?UTF-8?q?=D1=80=D0=B5=D0=B6=D0=B8=D0=BC=D1=8B=20=D1=82=D0=B5=D0=BA=D1=83?= =?UTF-8?q?=D1=89=D0=B5=D0=B9=20=D1=81=D0=BA=D0=B2=D0=B0=D0=B6=D0=B8=D0=BD?= =?UTF-8?q?=D1=8B"=20=D0=B8=20=D0=B2=20=D1=82=D0=B0=D0=B1=D0=BB=D0=B8?= =?UTF-8?q?=D1=86=D0=B5=20=D0=BD=D0=B0=20=D1=81=D1=82=D1=80=D0=B0=D0=BD?= =?UTF-8?q?=D0=B8=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 04/10] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2?= =?UTF-8?q?=D0=BB=D0=B5=D0=BD=D0=BE=20=D0=BE=D1=82=D0=BE=D0=B1=D1=80=D0=B0?= =?UTF-8?q?=D0=B6=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=B4=D0=B0=D0=BD=D0=BD=D1=8B?= =?UTF-8?q?=D1=85=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?= =?UTF-8?q?=D1=80=D0=B5=D0=B6=D0=B8=D0=BC=D1=8B=20=D1=82=D0=B5=D0=BA=D1=83?= =?UTF-8?q?=D1=89=D0=B5=D0=B9=20=D1=81=D0=BA=D0=B2=D0=B0=D0=B6=D0=B8=D0=BD?= =?UTF-8?q?=D1=8B"=20=D0=B8=20=D0=B2=20=D1=82=D0=B0=D0=B1=D0=BB=D0=B8?= =?UTF-8?q?=D1=86=D0=B5=20=D0=BD=D0=B0=20=D1=81=D1=82=D1=80=D0=B0=D0=BD?= =?UTF-8?q?=D0=B8=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 05/10] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2?= =?UTF-8?q?=D0=BB=D0=B5=D0=BD=D0=BE=20=D0=BE=D1=82=D0=BE=D0=B1=D1=80=D0=B0?= =?UTF-8?q?=D0=B6=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=B4=D0=B0=D0=BD=D0=BD=D1=8B?= =?UTF-8?q?=D1=85=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?= =?UTF-8?q?=D1=80=D0=B5=D0=B6=D0=B8=D0=BC=D1=8B=20=D1=82=D0=B5=D0=BA=D1=83?= =?UTF-8?q?=D1=89=D0=B5=D0=B9=20=D1=81=D0=BA=D0=B2=D0=B0=D0=B6=D0=B8=D0=BD?= =?UTF-8?q?=D1=8B"=20=D0=B8=20=D0=B2=20=D1=82=D0=B0=D0=B1=D0=BB=D0=B8?= =?UTF-8?q?=D1=86=D0=B5=20=D0=BD=D0=B0=20=D1=81=D1=82=D1=80=D0=B0=D0=BD?= =?UTF-8?q?=D0=B8=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 1f8bf12821b2a096ab4f2a728ee928140ce373cb Mon Sep 17 00:00:00 2001 From: ngfrolov Date: Wed, 28 Sep 2022 18:04:55 +0500 Subject: [PATCH 06/10] OperationTime. Adapt Dto. --- src/pages/Telemetry/OperationTime/index.tsx | 81 +++------------------ 1 file changed, 12 insertions(+), 69 deletions(-) diff --git a/src/pages/Telemetry/OperationTime/index.tsx b/src/pages/Telemetry/OperationTime/index.tsx index 8764d34..d442d29 100644 --- a/src/pages/Telemetry/OperationTime/index.tsx +++ b/src/pages/Telemetry/OperationTime/index.tsx @@ -2,7 +2,7 @@ import React, { ReactNode, useEffect, useState } from 'react' import { Col, Row, Select } from 'antd' import { Moment } from 'moment' -import { DateRangeWrapper, makeColumn, Table } from '@components/Table' +import { DateRangeWrapper, makeColumn, makeNumericRender, Table } from '@components/Table' import LoaderPortal from '@components/LoaderPortal' import { arrayOrDefault, wrapPrivateComponent } from '@utils' import D3HorizontalChart from '@components/d3/D3HorizontalChart' @@ -17,68 +17,10 @@ type DataType = { subsystemName: string usedTimeHours: number kUsage: number - k2: number + sumDepthInterval: number + operationCount: number } -const _data: DataType[] = [ - { - "idSubsystem": 1, - "subsystemName": "Keруррурk", - "usedTimeHours": 2, - "kUsage": 0.45, - "k2": 1 - }, - { - "idSubsystem": 2, - "subsystemName": "Lol", - "usedTimeHours": 0, - "kUsage": 0.24, - "k2": 0 - }, - { - "idSubsystem": 3, - "subsystemName": "kek", - "usedTimeHours": 0, - "kUsage": 0.37, - "k2": 0 - }, - { - "idSubsystem": 4, - "subsystemName": "keklol", - "usedTimeHours": 0, - "kUsage": 0.73, - "k2": 0 - }, - { - "idSubsystem": 5, - "subsystemName": "Keруррурk1", - "usedTimeHours": 2, - "kUsage": 0.45, - "k2": 1 - }, - { - "idSubsystem": 6, - "subsystemName": "Lol2", - "usedTimeHours": 0, - "kUsage": 0.24, - "k2": 0 - }, - { - "idSubsystem": 7, - "subsystemName": "kek3", - "usedTimeHours": 0, - "kUsage": 0.37, - "k2": 0 - }, - { - "idSubsystem": 8, - "subsystemName": "keklol4", - "usedTimeHours": 0, - "kUsage": 0.73, - "k2": 0 - }, -] - const subsystemColors = [ '#1abc9c', '#16a085', @@ -107,14 +49,15 @@ const tableColumns = [
) }), makeColumn('Подсистема', 'subsystemName'), - makeColumn('Время работы, ч', 'usedTimeHours'), - makeColumn('Активность, %', 'kUsage', { render: (d) => d * 100 }) + makeColumn('% использования', 'kUsage', { render: val => (+val * 100).toFixed(2) }), + makeColumn('Проходка, м', 'sumDepthInterval', {render: makeNumericRender(2)}), + makeColumn('Время работы, ч', 'usedTimeHours', {render: makeNumericRender(2)}), + makeColumn('Кол-во запусков', 'operationCount'), ] const OperationTime = () => { const [showLoader, setShowLoader] = useState(false) - const [data1, setData1] = useState([]) - const [data, setData] = useState(_data) + const [data, setData] = useState([]) const [dateRange, setDateRange] = useState([]) const [childrenData, setChildrenData] = useState([]) const [well] = useWell() @@ -127,14 +70,14 @@ const OperationTime = () => { async () => { if (!well.id) return try { - setData1(arrayOrDefault(await SubsystemOperationTimeService.getStat( + setData(arrayOrDefault(await SubsystemOperationTimeService.getStat( well.id, undefined, dateRange[1] ? dateRange[0]?.toISOString() : undefined, dateRange[1]?.toISOString(), ))) } catch(e) { - setData1([]) + setData([]) throw e } }, @@ -145,7 +88,7 @@ const OperationTime = () => { }, [dateRange]) useEffect(() => { - setChildrenData(_data.map((item) => ( + setChildrenData(data.map((item) => ( @@ -154,7 +97,7 @@ const OperationTime = () => { const selectChange = (value: string[]) => { - setData(_data.reduce((previousValue: DataType[], currentValue) => { + setData(data.reduce((previousValue: DataType[], currentValue) => { if (value.includes(currentValue.subsystemName)) { previousValue.push(currentValue) } From e0f8583f99833f3450704c87da9415dacc0fceda Mon Sep 17 00:00:00 2001 From: ts_salikhov Date: Thu, 29 Sep 2022 13:36:07 +0400 Subject: [PATCH 07/10] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2?= =?UTF-8?q?=D0=BB=D0=B5=D0=BD=D0=BE=20=D0=BE=D1=82=D0=BE=D0=B1=D1=80=D0=B0?= =?UTF-8?q?=D0=B6=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=B4=D0=B0=D0=BD=D0=BD=D1=8B?= =?UTF-8?q?=D1=85=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?= =?UTF-8?q?=D1=80=D0=B5=D0=B6=D0=B8=D0=BC=D1=8B=20=D1=82=D0=B5=D0=BA=D1=83?= =?UTF-8?q?=D1=89=D0=B5=D0=B9=20=D1=81=D0=BA=D0=B2=D0=B0=D0=B6=D0=B8=D0=BD?= =?UTF-8?q?=D1=8B"=20=D0=B8=20=D0=B2=20=D1=82=D0=B0=D0=B1=D0=BB=D0=B8?= =?UTF-8?q?=D1=86=D0=B5=20=D0=BD=D0=B0=20=D1=81=D1=82=D1=80=D0=B0=D0=BD?= =?UTF-8?q?=D0=B8=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 08/10] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2?= =?UTF-8?q?=D0=BB=D0=B5=D0=BD=D0=BE=20=D0=BE=D1=82=D0=BE=D0=B1=D1=80=D0=B0?= =?UTF-8?q?=D0=B6=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=B4=D0=B0=D0=BD=D0=BD=D1=8B?= =?UTF-8?q?=D1=85=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?= =?UTF-8?q?=D1=80=D0=B5=D0=B6=D0=B8=D0=BC=D1=8B=20=D1=82=D0=B5=D0=BA=D1=83?= =?UTF-8?q?=D1=89=D0=B5=D0=B9=20=D1=81=D0=BA=D0=B2=D0=B0=D0=B6=D0=B8=D0=BD?= =?UTF-8?q?=D1=8B"=20=D0=B8=20=D0=B2=20=D1=82=D0=B0=D0=B1=D0=BB=D0=B8?= =?UTF-8?q?=D1=86=D0=B5=20=D0=BD=D0=B0=20=D1=81=D1=82=D1=80=D0=B0=D0=BD?= =?UTF-8?q?=D0=B8=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 09/10] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2?= =?UTF-8?q?=D0=BB=D0=B5=D0=BD=D0=BE=20=D0=BE=D1=82=D0=BE=D0=B1=D1=80=D0=B0?= =?UTF-8?q?=D0=B6=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=B4=D0=B0=D0=BD=D0=BD=D1=8B?= =?UTF-8?q?=D1=85=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?= =?UTF-8?q?=D1=80=D0=B5=D0=B6=D0=B8=D0=BC=D1=8B=20=D1=82=D0=B5=D0=BA=D1=83?= =?UTF-8?q?=D1=89=D0=B5=D0=B9=20=D1=81=D0=BA=D0=B2=D0=B0=D0=B6=D0=B8=D0=BD?= =?UTF-8?q?=D1=8B"=20=D0=B8=20=D0=B2=20=D1=82=D0=B0=D0=B1=D0=BB=D0=B8?= =?UTF-8?q?=D1=86=D0=B5=20=D0=BD=D0=B0=20=D1=81=D1=82=D1=80=D0=B0=D0=BD?= =?UTF-8?q?=D0=B8=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 10/10] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2?= =?UTF-8?q?=D0=BB=D0=B5=D0=BD=D0=BE=20=D0=BE=D1=82=D0=BE=D0=B1=D1=80=D0=B0?= =?UTF-8?q?=D0=B6=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=B4=D0=B0=D0=BD=D0=BD=D1=8B?= =?UTF-8?q?=D1=85=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?= =?UTF-8?q?=D1=80=D0=B5=D0=B6=D0=B8=D0=BC=D1=8B=20=D1=82=D0=B5=D0=BA=D1=83?= =?UTF-8?q?=D1=89=D0=B5=D0=B9=20=D1=81=D0=BA=D0=B2=D0=B0=D0=B6=D0=B8=D0=BD?= =?UTF-8?q?=D1=8B"=20=D0=B8=20=D0=B2=20=D1=82=D0=B0=D0=B1=D0=BB=D0=B8?= =?UTF-8?q?=D1=86=D0=B5=20=D0=BD=D0=B0=20=D1=81=D1=82=D1=80=D0=B0=D0=BD?= =?UTF-8?q?=D0=B8=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'