From 37ac8a14bcba668c23f496de187dcb12cc0d6f14 Mon Sep 17 00:00:00 2001 From: goodm2ice Date: Mon, 14 Mar 2022 10:35:47 +0500 Subject: [PATCH 01/21] =?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=84=D0=B8=D0=BB=D1=8C=D1=82=D1=80=D0=B0?= =?UTF-8?q?=D1=86=D0=B8=D1=8F=20=D1=81=D1=82=D0=BE=D0=BB=D0=B1=D1=86=D0=BE?= =?UTF-8?q?=D0=B2=20=D0=BF=D0=BE=20=D1=81=D0=BE=D0=B4=D0=B5=D1=80=D0=B6?= =?UTF-8?q?=D0=B8=D0=BC=D0=BE=D0=BC=D1=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/Analytics/Statistics.jsx | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/pages/Analytics/Statistics.jsx b/src/pages/Analytics/Statistics.jsx index 329d919..f52a77e 100644 --- a/src/pages/Analytics/Statistics.jsx +++ b/src/pages/Analytics/Statistics.jsx @@ -90,21 +90,30 @@ export const Statistics = memo(({ idWell }) => { async () => { const types = await WellOperationService.getSectionTypes(idWell) setSectionTypes(Object.entries(types)) + }, + setIsPageLoading, + `Не удалось получить типы секции`, + `Получение списка возможных секций`, + ), [idWell]) + + useEffect(() => invokeWebApiWrapperAsync( + async () => { + const filteredSections = avgData?.length > 0 ? sectionTypes.filter(([id, _]) => avgData.some((row) => `section_${id}` in row)) : sectionTypes + setAvgColumns([ ...defaultColumns, - ...Object.entries(types).map(([id, name]) => makeSectionColumn(name, `section_${id}`)), + ...filteredSections.map(([id, name]) => makeSectionColumn(name, `section_${id}`)), ]) setCmpColumns([ ...defaultColumns, - ...Object.entries(types).map(([id, name]) => makeSectionColumn(name, `section_${id}`, { + ...filteredSections.map(([id, name]) => makeSectionColumn(name, `section_${id}`, { speedRender: cmpSpeedRender(`section_${id}`) })) ]) }, setIsPageLoading, - `Не удалось получить типы секции`, - `Получение списка возможных секций`, - ), [idWell, cmpSpeedRender]) + 'Не удалось установить необходимые столбцы' + ), [sectionTypes, avgData, cmpSpeedRender]) useEffect(() => invokeWebApiWrapperAsync( async () => { From d6c4261d26ae382c44398b5d72ed2be5e63fcbf1 Mon Sep 17 00:00:00 2001 From: goodm2ice Date: Mon, 14 Mar 2022 10:48:36 +0500 Subject: [PATCH 02/21] =?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=B0=20=D1=81=D0=BE=D1=80=D1=82=D0=B8=D1=80?= =?UTF-8?q?=D0=BE=D0=B2=D0=BA=D0=B0=20=D0=BF=D0=BE=20=D1=81=D1=82=D0=BE?= =?UTF-8?q?=D0=BB=D0=B1=D1=86=D0=B0=D0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/Analytics/Statistics.jsx | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/pages/Analytics/Statistics.jsx b/src/pages/Analytics/Statistics.jsx index f52a77e..764e7ee 100644 --- a/src/pages/Analytics/Statistics.jsx +++ b/src/pages/Analytics/Statistics.jsx @@ -4,7 +4,7 @@ import { Fragment, memo, useCallback, useEffect, useState } from 'react' import LoaderPortal from '@components/LoaderPortal' import { WellSelector } from '@components/WellSelector' import { invokeWebApiWrapperAsync } from '@components/factory' -import { makeGroupColumn, makeNumericColumn, makeNumericRender, makeTextColumn, Table } from '@components/Table' +import { makeColumn, makeGroupColumn, makeNumericColumn, makeNumericRender, makeTextColumn, Table } from '@components/Table' import { OperationStatService, WellOperationService } from '@api' import { arrayOrDefault } from '@utils' @@ -18,10 +18,17 @@ const { Cell, Row } = Summary const numericRender = makeNumericRender() const speedNumericRender = (section) => numericRender(section?.speed) +const makeSectionSorter = (key, name) => (a, b) => (a?.[key]?.[name] ?? 0) - (b?.[key]?.[name] ?? 0) export const makeSectionColumn = (title, key, { speedRender } = {}) => makeGroupColumn(title, [ - makeNumericColumn('Проходка', key, null, null, (section => numericRender(section?.depth)), 100), - makeNumericColumn('Время', key, null, null, (section => numericRender(section?.time)), 100), - makeNumericColumn((<>Vрейсовая), key, null, null, speedRender ?? speedNumericRender, 100), + makeNumericColumn('Проходка', key, null, null, (section => numericRender(section?.depth)), 100, { + sorter: makeSectionSorter(key, 'depth'), + }), + makeNumericColumn('Время', key, null, null, (section => numericRender(section?.time)), 100, { + sorter: makeSectionSorter(key, 'time'), + }), + makeNumericColumn((<>Vрейсовая), key, null, null, speedRender ?? speedNumericRender, 100, { + sorter: makeSectionSorter(key, 'speed'), + }), ]) export const defaultColumns = [ From f4a3c0f293ebea47e0f99cf26c8f216a304a740d Mon Sep 17 00:00:00 2001 From: goodm2ice Date: Wed, 16 Mar 2022 16:10:28 +0500 Subject: [PATCH 03/21] =?UTF-8?q?=D0=90=D1=80=D0=B3=D1=83=D0=BC=D0=B5?= =?UTF-8?q?=D0=BD=D1=82=D1=8B=20=D1=81=D0=B5=D0=BB=D0=B5=D0=BA=D1=82=D0=BE?= =?UTF-8?q?=D1=80=D0=B0=20=D0=B4=D0=B0=D1=82=D1=8B=20=D0=B8=D0=B7=D0=BC?= =?UTF-8?q?=D0=B5=D0=BD=D0=B5=D0=BD=D1=8B=20=D0=BD=D0=B0=20=D0=BD=D0=B5?= =?UTF-8?q?=D0=BE=D0=B1=D1=8F=D0=B7=D0=B0=D1=82=D0=B5=D0=BB=D1=8C=D0=BD?= =?UTF-8?q?=D1=8B=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/Table/DatePickerWrapper.tsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/components/Table/DatePickerWrapper.tsx b/src/components/Table/DatePickerWrapper.tsx index 76b195b..a453fbc 100644 --- a/src/components/Table/DatePickerWrapper.tsx +++ b/src/components/Table/DatePickerWrapper.tsx @@ -6,8 +6,8 @@ import moment, { Moment } from 'moment' import { defaultFormat } from '@utils' export type DatePickerWrapperProps = PickerDateProps & { - value: Moment, - onChange: (date: Moment | null) => any + value?: Moment, + onChange?: (date: Moment | null) => any isUTC?: boolean } @@ -17,7 +17,7 @@ export const DatePickerWrapper = memo(({ value, onChange allowClear={false} format={defaultFormat} defaultValue={moment()} - onChange={(date) => onChange(date)} + onChange={(date) => onChange?.(date)} value={isUTC ? moment.utc(value).local() : moment(value)} {...other} /> From 4bacf7f9e12a351959030fe081eeabc9e118cc7f Mon Sep 17 00:00:00 2001 From: goodm2ice Date: Wed, 16 Mar 2022 16:12:02 +0500 Subject: [PATCH 04/21] =?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=D0=B2=D0=BE=D0=B7=D0=BC=D0=BE=D0=B6=D0=BD?= =?UTF-8?q?=D0=BE=D1=81=D1=82=D1=8C=20=D0=B8=D1=81=D0=BF=D0=BE=D0=BB=D1=8C?= =?UTF-8?q?=D0=B7=D0=BE=D0=B2=D0=B0=D1=82=D1=8C=20=D0=B2=D0=BD=D0=B5=D1=88?= =?UTF-8?q?=D0=BD=D0=B8=D0=B9=20onCell=20=D0=B2=20EditableTable?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/Table/EditableTable.jsx | 1 + 1 file changed, 1 insertion(+) diff --git a/src/components/Table/EditableTable.jsx b/src/components/Table/EditableTable.jsx index ff2378d..e93a36d 100644 --- a/src/components/Table/EditableTable.jsx +++ b/src/components/Table/EditableTable.jsx @@ -188,6 +188,7 @@ export const EditableTable = memo(({ return { ...col, onCell: (record) => ({ + ...col.onCell?.(record), editing: isEditing(record), record, dataIndex: col.dataIndex ?? col.key, From 7c5af125086cfa6e3ca6c5b0f655b73252c3a1f8 Mon Sep 17 00:00:00 2001 From: goodm2ice Date: Thu, 17 Mar 2022 06:39:59 +0500 Subject: [PATCH 05/21] =?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=84=D0=B0=D0=B1=D1=80=D0=B8=D0=BA=D0=B0?= =?UTF-8?q?=20=D0=BA=D0=BE=D0=BB=D0=BE=D0=BD=D0=BA=D0=B8=20=D0=B4=D0=B0?= =?UTF-8?q?=D1=82=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/Table/Columns/date.tsx | 25 +++++++++++++++++++++++++ src/components/Table/Columns/index.ts | 1 + src/components/Table/index.tsx | 1 + 3 files changed, 27 insertions(+) create mode 100644 src/components/Table/Columns/date.tsx diff --git a/src/components/Table/Columns/date.tsx b/src/components/Table/Columns/date.tsx new file mode 100644 index 0000000..c388cf6 --- /dev/null +++ b/src/components/Table/Columns/date.tsx @@ -0,0 +1,25 @@ +import { ReactNode } from 'react' + +import { formatDate } from '@utils' + +import makeColumn, { columnPropsOther } from '.' +import { DatePickerWrapper, makeDateSorter } from '..' + +export const makeDateColumn = ( + title: ReactNode, + key: string, + utc?: boolean, + format?: string, + other?: columnPropsOther +) => makeColumn(title, key, { + ...other, + render: (date) => ( +
+ {formatDate(date, utc, format) ?? '-'} +
+ ), + sorter: makeDateSorter(key), + input: , +}) + +export default makeDateColumn diff --git a/src/components/Table/Columns/index.ts b/src/components/Table/Columns/index.ts index fd0b327..babb1fd 100644 --- a/src/components/Table/Columns/index.ts +++ b/src/components/Table/Columns/index.ts @@ -2,6 +2,7 @@ import { ReactNode } from 'react' import { Rule } from 'antd/lib/form' import { ColumnProps } from 'antd/lib/table' +export { makeDateColumn } from './date' export { RegExpIsFloat, makeNumericRender, diff --git a/src/components/Table/index.tsx b/src/components/Table/index.tsx index 095c825..2e1fc8e 100644 --- a/src/components/Table/index.tsx +++ b/src/components/Table/index.tsx @@ -6,6 +6,7 @@ export { RegExpIsFloat, timezoneOptions, TimezoneSelect, + makeDateColumn, makeGroupColumn, makeColumn, makeColumnsPlanFact, From 2384f65999647a1a2f1023e8519dd244b513f686 Mon Sep 17 00:00:00 2001 From: goodm2ice Date: Thu, 17 Mar 2022 06:41:51 +0500 Subject: [PATCH 06/21] =?UTF-8?q?=D0=92=20WellOperationsEditor=20=D0=B4?= =?UTF-8?q?=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD=D0=B0=20=D0=B2=D0=BE?= =?UTF-8?q?=D0=B7=D0=BC=D0=BE=D0=B6=D0=BD=D0=BE=D1=81=D1=82=D1=8C=20=D0=B2?= =?UTF-8?q?=D1=8B=D0=B4=D0=B5=D0=BB=D0=B5=D0=BD=D0=B8=D1=8F=20=D0=B7=D0=B0?= =?UTF-8?q?=D0=BF=D0=B8=D1=81=D0=B5=D0=B9=20=D1=87=D0=B5=D1=80=D0=B5=D0=B7?= =?UTF-8?q?=20GET=20=D0=B0=D1=80=D0=B3=D1=83=D0=BC=D0=B5=D0=BD=D1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../WellOperations/WellOperationsEditor.jsx | 52 ++++++++++--------- 1 file changed, 28 insertions(+), 24 deletions(-) diff --git a/src/pages/WellOperations/WellOperationsEditor.jsx b/src/pages/WellOperations/WellOperationsEditor.jsx index 1266d49..4f0a6a9 100644 --- a/src/pages/WellOperations/WellOperationsEditor.jsx +++ b/src/pages/WellOperations/WellOperationsEditor.jsx @@ -1,21 +1,21 @@ import moment from 'moment' import { Input } from 'antd' -import { useState, useEffect, memo } from 'react' +import { useLocation } from 'react-router-dom' +import { useState, useEffect, memo, useMemo, useCallback } from 'react' import { EditableTable, - DatePickerWrapper, makeColumn, - makeDateSorter, makeNumericColumnOptions, makeSelectColumn, makeActionHandler, + makeDateColumn, } from '@components/Table' -import { WellOperationService} from '@api' import LoaderPortal from '@components/LoaderPortal' import { invokeWebApiWrapperAsync } from '@components/factory' import { hasPermission } from '@utils/permissions' -import { formatDate } from '@utils' +import { arrayOrDefault } from '@utils' +import { WellOperationService } from '@api' const { TextArea } = Input @@ -25,7 +25,7 @@ const defaultColumns = [ makeSelectColumn('Конструкция секции', 'idWellSectionType', [], undefined, { editable: true, width: 160, - formItemRules: [({ getFieldValue }) => ({ + formItemRules: [() => ({ validator(_, value) { if (value?.length > 0) return Promise.resolve() @@ -37,43 +37,41 @@ const defaultColumns = [ makeColumn('Доп. инфо', 'categoryInfo', { editable: true, width: 300, input: