From f133728e1b86d742a34f4206aaea46786fd3cb30 Mon Sep 17 00:00:00 2001 From: goodmice Date: Fri, 10 Jun 2022 20:37:30 +0500 Subject: [PATCH] =?UTF-8?q?=D0=9E=D0=B1=D0=BD=D0=BE=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=BE=20=D0=B8=D1=81=D0=BF=D0=BE=D0=BB=D1=8C=D0=B7=D0=BE?= =?UTF-8?q?=D0=B2=D0=B0=D0=BD=D0=B8=D0=B5=20WellService=20=D0=B8=20DrillFl?= =?UTF-8?q?owChartService?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/Telemetry/TelemetryView/index.jsx | 4 +- src/pages/WellOperations/DrillProcessFlow.jsx | 44 ++++++++----------- 2 files changed, 21 insertions(+), 27 deletions(-) diff --git a/src/pages/Telemetry/TelemetryView/index.jsx b/src/pages/Telemetry/TelemetryView/index.jsx index 05df142..076e3f9 100755 --- a/src/pages/Telemetry/TelemetryView/index.jsx +++ b/src/pages/Telemetry/TelemetryView/index.jsx @@ -363,8 +363,8 @@ const TelemetryView = memo(() => { const onStatusChanged = useCallback((value) => invokeWebApiWrapperAsync( async () => { - const well = { ...wellData, idState: value } - await WellService.updateWell(idWell, well) + const well = { idWell, ...wellData, idState: value } + await WellService.updateWell(well) setWellData(well) }, setShowLoader, diff --git a/src/pages/WellOperations/DrillProcessFlow.jsx b/src/pages/WellOperations/DrillProcessFlow.jsx index 2d2f155..be53286 100755 --- a/src/pages/WellOperations/DrillProcessFlow.jsx +++ b/src/pages/WellOperations/DrillProcessFlow.jsx @@ -1,15 +1,11 @@ import { useState, useEffect, memo } from 'react' import { useIdWell } from '@asb/context' -import { - EditableTable, - makeNumericMinMax, - makeNumericStartEnd, -} from '@components/Table' import LoaderPortal from '@components/LoaderPortal' import { invokeWebApiWrapperAsync } from '@components/factory' -import { hasPermission, arrayOrDefault } from '@utils' +import { EditableTable, makeNumericMinMax, makeNumericStartEnd } from '@components/Table' import { DrillFlowChartService } from '@api' +import { arrayOrDefault } from '@utils' const columns = [ @@ -41,24 +37,22 @@ export const DrillProcessFlow = memo(() => { updateFlows() }, [idWell]) - const onAdd = async (flow) => { - flow.idWell = idWell - await DrillFlowChartService.insert(idWell, flow) - updateFlows() - } + const tableHandlers = useMemo(() => { + const handlerProps = { + service: DrillFlowChartService, + setLoader: setShowLoader, + onComplete: updateFlows, + permission: 'DrillFlowChart.edit', + } - const onEdit = async (flow) => { - if (!flow.id) return - flow.idWell = idWell - await DrillFlowChartService.edit(idWell, flow) - updateFlows() - } + const recordParser = (record) => ({ idWell, ...record }) - const onDelete = async (flow) => { - if (!flow.id) return - await DrillFlowChartService.delete(idWell, flow.id) - updateFlows() - } + return { + add: { ...handlerProps, action: 'insert', actionName: 'Добавление месторождения', recordParser }, + edit: { ...handlerProps, action: 'update', actionName: 'Редактирование месторождения', recordParser }, + delete: { ...handlerProps, action: 'delete', actionName: 'Удаление месторождения', permission: 'DrillFlowChart.delete' }, + } + }, [updateFlows, idWell]) return ( @@ -67,10 +61,10 @@ export const DrillProcessFlow = memo(() => { size={'small'} columns={columns} dataSource={flows} + onRowAdd={tableHandlers.add} + onRowEdit={tableHandlers.edit} + onRowDelete={tableHandlers.delete} tableName={'well_operations_flow'} - onRowAdd={hasPermission('DrillFlowChart.edit') && onAdd} - onRowEdit={hasPermission('DrillFlowChart.edit') && onEdit} - onRowDelete={hasPermission('DrillFlowChart.delete') && onDelete} pagination={false} />