Удалена пагинация

This commit is contained in:
goodmice 2021-10-12 16:48:17 +05:00
parent 279b375ea9
commit a60b73d408

View File

@ -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:<SelectFromDictionary dictionary={dictionarySectionType}/>,
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})
}}
/>
</LoaderPortal>
)