Обновлено использование WellService и DrillFlowChartService

This commit is contained in:
goodmice 2022-06-10 20:37:30 +05:00
parent 69fc308352
commit f133728e1b
2 changed files with 21 additions and 27 deletions

View File

@ -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,

View File

@ -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 (
<LoaderPortal show={showLoader}>
@ -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}
/>
</LoaderPortal>