From a60b73d408cb94d1c2ec58e7668458cfe1e48d70 Mon Sep 17 00:00:00 2001 From: goodmice Date: Tue, 12 Oct 2021 16:48:17 +0500 Subject: [PATCH] =?UTF-8?q?=D0=A3=D0=B4=D0=B0=D0=BB=D0=B5=D0=BD=D0=B0=20?= =?UTF-8?q?=D0=BF=D0=B0=D0=B3=D0=B8=D0=BD=D0=B0=D1=86=D0=B8=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/WellOperations/WellDrillParams.jsx | 48 ++++++-------------- 1 file changed, 15 insertions(+), 33 deletions(-) diff --git a/src/pages/WellOperations/WellDrillParams.jsx b/src/pages/WellOperations/WellDrillParams.jsx index 3e43fea..edd8c25 100644 --- a/src/pages/WellOperations/WellDrillParams.jsx +++ b/src/pages/WellOperations/WellDrillParams.jsx @@ -2,8 +2,7 @@ import { useState, useEffect } from 'react' import { makeColumn, - makeNumericAvgRange, - makeNumericStartEnd + makeNumericAvgRange } from '../../components/Table' import LoaderPortal from '../../components/LoaderPortal' import { invokeWebApiWrapperAsync } from '../../components/factory' @@ -11,33 +10,24 @@ import { EditableTable, SelectFromDictionary } from '../../components/Table' import { DrillParamsService } from '../../services/api' import { dictionarySectionType, getByKeyOrReturnKey } from './dictionary' -const basePageSize = 160; - export const WellDrillParams = ({idWell}) => { - const [pageNumAndPageSize, setPageNumAndPageSize] = useState({current:1, pageSize:basePageSize}) - const [paginationTotal, setPaginationTotal] = useState(0) const [params, setParams] = useState([]) const [showLoader, setShowLoader] = useState(false) - const updatePrograms = () => invokeWebApiWrapperAsync( + const updateParams = () => invokeWebApiWrapperAsync( async () => { - const skip = ((pageNumAndPageSize.current - 1) * pageNumAndPageSize.pageSize) || 0 - const take = pageNumAndPageSize.pageSize - const paginatedParams = await DrillParamsService.getParams(idWell, skip, take) - const params = paginatedParams?.items ?? [] + const params = await DrillParamsService.getAll(idWell) setParams(params) - const total = paginatedParams.count?? paginatedParams.items?.length ?? 0 - setPaginationTotal(total) }, setShowLoader, 'Не удалось загрузить список режимов бурения скважины' ) - useEffect(updatePrograms, [idWell, pageNumAndPageSize]) + useEffect(updateParams, [idWell]) const columns = [ - makeColumn('Конструкция секции','id_wellsection_type', { + makeColumn('Конструкция секции','idWellSectionType', { editable:true, input:, width:160, @@ -46,29 +36,28 @@ export const WellDrillParams = ({idWell}) => { // makeNumericStartEnd('Глубина', 'depth'), makeNumericAvgRange('Нагрузка', 'axialLoad'), makeNumericAvgRange('Давление', 'pressure'), - makeNumericAvgRange('Момент на ВПС', 'topDriveTorque'), - makeNumericAvgRange('Обороты на ВПС', 'topDriveSpeed'), + makeNumericAvgRange('Момент на ВПС', 'rotorTorque'), + makeNumericAvgRange('Обороты на ВПС', 'rotorSpeed'), makeNumericAvgRange('Расход', 'flow') ] const onAdd = async (param) => { - if (!param.id) return - // TODO: Add row - await DrillParamsService.saveDrillParams(idWell, param) - updatePrograms() + param.idWell = idWell + await DrillParamsService.save(idWell, param) + updateParams() } const onEdit = async (param) => { if (!param.id) return - // TODO: Edit row - await DrillParamsService.update(idWell, param.id, param) - updatePrograms() + param.idWell = idWell + await DrillParamsService.update(idWell, param) + updateParams() } const onDelete = async (param) => { if (!param.id) return await DrillParamsService.delete(idWell, param.id) - updatePrograms() + updateParams() } return ( @@ -78,16 +67,9 @@ export const WellDrillParams = ({idWell}) => { bordered columns={columns} dataSource={params} - //onRowAdd={onAdd} + onRowAdd={onAdd} onRowEdit={onEdit} onRowDelete={onDelete} - pagination={{ - current: pageNumAndPageSize.current, - pageSize: pageNumAndPageSize.pageSize, - showSizeChanger: false, - total: paginationTotal, - onChange: (page, pageSize) => setPageNumAndPageSize({current: page, pageSize: pageSize}) - }} /> )