2022-02-07 14:58:38 +05:00
|
|
|
|
import { useState, useEffect, useCallback, memo } from 'react'
|
2021-10-12 11:10:33 +05:00
|
|
|
|
|
2021-12-29 11:11:49 +05:00
|
|
|
|
import {
|
|
|
|
|
EditableTable,
|
|
|
|
|
makeSelectColumn,
|
|
|
|
|
makeActionHandler,
|
|
|
|
|
makeNumericAvgRange,
|
2022-02-07 14:58:38 +05:00
|
|
|
|
} from '@components/Table'
|
|
|
|
|
import LoaderPortal from '@components/LoaderPortal'
|
|
|
|
|
import { invokeWebApiWrapperAsync } from '@components/factory'
|
|
|
|
|
import { DrillParamsService, WellOperationService } from '@api'
|
|
|
|
|
import { hasPermission } from '@utils/permissions'
|
|
|
|
|
import { arrayOrDefault } from '@utils'
|
2021-12-27 15:18:20 +05:00
|
|
|
|
|
2021-12-29 11:11:49 +05:00
|
|
|
|
export const getColumns = async (idWell) => {
|
|
|
|
|
let sectionTypes = await WellOperationService.getSectionTypes(idWell)
|
|
|
|
|
sectionTypes = Object.keys(sectionTypes).map((id) => ({
|
|
|
|
|
label: sectionTypes[id],
|
|
|
|
|
value: id,
|
|
|
|
|
}))
|
2021-10-12 11:10:33 +05:00
|
|
|
|
|
2021-12-29 11:11:49 +05:00
|
|
|
|
return [
|
|
|
|
|
makeSelectColumn('Конструкция секции','idWellSectionType', sectionTypes, null, {
|
|
|
|
|
editable: true,
|
|
|
|
|
width: 160,
|
|
|
|
|
}),
|
|
|
|
|
makeNumericAvgRange('Нагрузка, т', 'axialLoad', 1),
|
|
|
|
|
makeNumericAvgRange('Давление, атм', 'pressure', 1),
|
|
|
|
|
makeNumericAvgRange('Момент на ВСП, кН·м', 'rotorTorque', 1),
|
|
|
|
|
makeNumericAvgRange('Обороты на ВСП, об/мин', 'rotorSpeed', 1),
|
|
|
|
|
makeNumericAvgRange('Расход, л/с', 'flow', 1),
|
|
|
|
|
]
|
|
|
|
|
}
|
2021-10-12 11:10:33 +05:00
|
|
|
|
|
2022-02-07 14:58:38 +05:00
|
|
|
|
export const WellDrillParams = memo(({ idWell }) => {
|
2021-10-12 11:10:33 +05:00
|
|
|
|
const [params, setParams] = useState([])
|
|
|
|
|
const [showLoader, setShowLoader] = useState(false)
|
2021-12-29 11:11:49 +05:00
|
|
|
|
const [columns, setColumns] = useState([])
|
2021-10-12 11:10:33 +05:00
|
|
|
|
|
2021-12-29 11:11:49 +05:00
|
|
|
|
const updateParams = useCallback(async () => await invokeWebApiWrapperAsync(
|
2021-10-12 11:10:33 +05:00
|
|
|
|
async () => {
|
2021-12-29 11:11:49 +05:00
|
|
|
|
const params = arrayOrDefault(await DrillParamsService.getAll(idWell))
|
2021-12-29 14:56:53 +05:00
|
|
|
|
// Typescript против использования числа в качестве типа значения select
|
|
|
|
|
params.forEach((param) => param.idWellSectionType = `${param.idWellSectionType}`)
|
2021-12-29 11:11:49 +05:00
|
|
|
|
setParams(params)
|
2021-10-12 11:10:33 +05:00
|
|
|
|
},
|
|
|
|
|
setShowLoader,
|
2022-02-07 17:44:46 +05:00
|
|
|
|
'Не удалось загрузить список режимов бурения скважины',
|
|
|
|
|
'Получение списка режимов бурения скважины'
|
2021-12-29 11:11:49 +05:00
|
|
|
|
), [idWell])
|
2021-10-12 11:10:33 +05:00
|
|
|
|
|
2021-12-29 14:56:53 +05:00
|
|
|
|
useEffect(() => (async () => {
|
|
|
|
|
setColumns(await getColumns(idWell))
|
|
|
|
|
await updateParams()
|
|
|
|
|
})(), [idWell, updateParams])
|
2021-10-12 11:10:33 +05:00
|
|
|
|
|
2021-12-27 15:18:20 +05:00
|
|
|
|
const handlerProps = {
|
|
|
|
|
service: DrillParamsService,
|
|
|
|
|
setLoader: setShowLoader,
|
|
|
|
|
errorMsg: `Не удалось выполнить операцию`,
|
|
|
|
|
onComplete: updateParams,
|
|
|
|
|
idWell
|
2021-10-12 11:10:33 +05:00
|
|
|
|
}
|
|
|
|
|
|
2021-12-27 15:18:20 +05:00
|
|
|
|
const recordParser = (record) => ({ ...record, idWell })
|
2021-10-12 11:10:33 +05:00
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<LoaderPortal show={showLoader}>
|
|
|
|
|
<EditableTable
|
|
|
|
|
size={'small'}
|
|
|
|
|
bordered
|
|
|
|
|
columns={columns}
|
|
|
|
|
dataSource={params}
|
2022-03-10 20:46:02 +05:00
|
|
|
|
tableName={'well_drill_params'}
|
2022-02-07 17:44:46 +05:00
|
|
|
|
onRowAdd={hasPermission('DrillParams.edit') && makeActionHandler('insert', handlerProps, recordParser, 'Добавление режима бурения')}
|
|
|
|
|
onRowEdit={hasPermission('DrillParams.edit') && makeActionHandler('update', handlerProps, recordParser, 'Редактирование режима бурения')}
|
|
|
|
|
onRowDelete={hasPermission('DrillParams.delete') && makeActionHandler('delete', handlerProps, recordParser, 'Удаление режима бурения')}
|
2021-10-12 16:51:25 +05:00
|
|
|
|
pagination={false}
|
2021-10-12 11:10:33 +05:00
|
|
|
|
/>
|
|
|
|
|
</LoaderPortal>
|
|
|
|
|
)
|
2022-02-07 14:58:38 +05:00
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
export default WellDrillParams
|