В WellOperationsEditor добавлена возможность выделения записей через GET аргумент

This commit is contained in:
Александр Сироткин 2022-03-17 06:41:51 +05:00
parent 7c5af12508
commit 2384f65999

View File

@ -1,21 +1,21 @@
import moment from 'moment'
import { Input } from 'antd'
import { useState, useEffect, memo } from 'react'
import { useLocation } from 'react-router-dom'
import { useState, useEffect, memo, useMemo, useCallback } from 'react'
import {
EditableTable,
DatePickerWrapper,
makeColumn,
makeDateSorter,
makeNumericColumnOptions,
makeSelectColumn,
makeActionHandler,
makeDateColumn,
} from '@components/Table'
import { WellOperationService} from '@api'
import LoaderPortal from '@components/LoaderPortal'
import { invokeWebApiWrapperAsync } from '@components/factory'
import { hasPermission } from '@utils/permissions'
import { formatDate } from '@utils'
import { arrayOrDefault } from '@utils'
import { WellOperationService } from '@api'
const { TextArea } = Input
@ -25,7 +25,7 @@ const defaultColumns = [
makeSelectColumn('Конструкция секции', 'idWellSectionType', [], undefined, {
editable: true,
width: 160,
formItemRules: [({ getFieldValue }) => ({
formItemRules: [() => ({
validator(_, value) {
if (value?.length > 0)
return Promise.resolve()
@ -37,43 +37,41 @@ const defaultColumns = [
makeColumn('Доп. инфо', 'categoryInfo', { editable: true, width: 300, input: <TextArea/> }),
makeColumn('Глубина забоя на начало, м', 'depthStart', makeNumericColumnOptions(2, 'depthStart')),
makeColumn('Глубина забоя при завершении, м', 'depthEnd', makeNumericColumnOptions(2, 'depthEnd')),
makeColumn('Время начала', 'dateStart', {
makeDateColumn('Время начала', 'dateStart', undefined, undefined, {
editable: true,
width: 200,
input: <DatePickerWrapper/>,
initialValue: moment().format(),
sorter: makeDateSorter('dateStart'),
render: (_, record) => (
<div className={'text-align-r-container'}>
<span>{formatDate(record.dateStart)}</span>
</div>
)
}),
makeColumn('Часы', 'durationHours', makeNumericColumnOptions(2, 'durationHours')),
makeColumn('Комментарий', 'comment', { editable: true, input: <TextArea/> }),
]
export const WellOperationsEditor = memo(({ idWell, idType, ...other }) => {
const [pageNumAndPageSize, setPageNumAndPageSize] = useState({current:1, pageSize:basePageSize})
const [pageNumAndPageSize, setPageNumAndPageSize] = useState({ current: 1, pageSize: basePageSize })
const [paginationTotal, setPaginationTotal] = useState(0)
const [operations, setOperations] = useState([])
const [showLoader, setShowLoader] = useState(false)
const [columns, setColumns] = useState(defaultColumns)
const location = useLocation()
const selectedIds = useMemo(() => {
const query = new URLSearchParams(location.search)
return arrayOrDefault(query.get('selectedId')?.split(',')?.map(parseInt))
}, [location])
useEffect(() => invokeWebApiWrapperAsync(
async () => {
let categories = await WellOperationService.getCategories(idWell) ?? []
let categories = arrayOrDefault(await WellOperationService.getCategories(idWell))
categories = categories.map((item) => ({ value: item.id, label: item.name }))
let sectionTypes = await WellOperationService.getSectionTypes(idWell) ?? []
sectionTypes = Object.keys(sectionTypes).map((key) => ({ value: parseInt(key), label: sectionTypes[key] }))
let sectionTypes = await WellOperationService.getSectionTypes(idWell) ?? {}
sectionTypes = Object.entries(sectionTypes).map(([id, label]) => ({ value: parseInt(id), label }))
setColumns(preColumns => {
const newColumns = [...preColumns]
newColumns[0] = makeSelectColumn('Конструкция секции', 'idWellSectionType', sectionTypes, undefined, { editable: true, width: 160 })
newColumns[1] = makeSelectColumn('Операция', 'idCategory', categories, undefined, { editable: true, width: 200 })
return newColumns
})
setColumns(preColumns => [
makeSelectColumn('Конструкция секции', 'idWellSectionType', sectionTypes, undefined, { editable: true, width: 160 }),
makeSelectColumn('Операция', 'idCategory', categories, undefined, { editable: true, width: 200 }),
...preColumns.slice(2),
])
},
setShowLoader,
'Не удалось загрузить список операций по скважине',
@ -107,6 +105,11 @@ export const WellOperationsEditor = memo(({ idWell, idType, ...other }) => {
idWell
}
const onRow = useCallback((record) => {
if (selectedIds?.includes(record.id))
return { style: { background: '#BF0000A0' } }
}, [selectedIds])
const recordParser = (record) => ({
...record,
idType,
@ -133,6 +136,7 @@ export const WellOperationsEditor = memo(({ idWell, idType, ...other }) => {
onChange: (page, pageSize) => setPageNumAndPageSize({ current: page, pageSize })
}}
tableName={'well_operationse_editor'}
onRow={onRow}
/>
</LoaderPortal>
)