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} />