forked from ddrilling/asb_cloud_front
goodm2ice
da382ba9c8
Координаты округлены до 8 знаков после запятой На журнале посещений кол-во записей изменено на 16 и добавлен селектор кол-ва строк
81 lines
2.8 KiB
JavaScript
81 lines
2.8 KiB
JavaScript
import { useEffect, useState } from 'react'
|
||
|
||
import { invokeWebApiWrapperAsync } from '../../components/factory'
|
||
import LoaderPortal from '../../components/LoaderPortal'
|
||
import {
|
||
EditableTable,
|
||
makeColumn,
|
||
makeSelectColumn,
|
||
makeActionHandler,
|
||
makeStringSorter
|
||
} from '../../components/Table'
|
||
import { AdminClusterService, AdminDepositService } from '../../services/api'
|
||
import { arrayOrDefault } from '../../utils'
|
||
import { min3 } from '../../utils/validationRules'
|
||
|
||
import { coordsFixed } from './DepositController'
|
||
|
||
export default function ClusterController() {
|
||
const [deposits, setDeposits] = useState([])
|
||
const [clusters, setClusters] = useState([])
|
||
const [showLoader, setShowLoader] = useState(false)
|
||
|
||
const clusterColumns = [
|
||
makeSelectColumn('Месторождение', 'idDeposit', deposits, '--', {
|
||
width: 200,
|
||
editable: true,
|
||
sorter: makeStringSorter('idDeposit')
|
||
}),
|
||
makeColumn('Название', 'caption', {
|
||
width: 200,
|
||
editable: true,
|
||
sorter: makeStringSorter('caption'),
|
||
formItemRules: min3,
|
||
}),
|
||
makeColumn('Широта', 'latitude', { width: 150, editable: true, render: coordsFixed }),
|
||
makeColumn('Долгота', 'longitude', { width: 150, editable: true, render: coordsFixed }),
|
||
]
|
||
|
||
const updateTable = () => invokeWebApiWrapperAsync(
|
||
async () => {
|
||
const clusters = await AdminClusterService.getAll()
|
||
setClusters(arrayOrDefault(clusters))
|
||
},
|
||
setShowLoader,
|
||
`Не удалось загрузить список кустов`
|
||
)
|
||
|
||
useEffect(() => invokeWebApiWrapperAsync(
|
||
async () => {
|
||
let deposits = arrayOrDefault(await AdminDepositService.getAll())
|
||
deposits = deposits.map((deposit) => ({ value: deposit.id, label: deposit.caption }))
|
||
setDeposits(deposits)
|
||
},
|
||
setShowLoader,
|
||
`Не удалось загрузить список месторождений`
|
||
), [])
|
||
|
||
useEffect(updateTable, [])
|
||
|
||
const handlerProps = {
|
||
service: AdminClusterService,
|
||
setLoader: setShowLoader,
|
||
errorMsg: `Не удалось выполнить операцию`,
|
||
onComplete: updateTable,
|
||
}
|
||
|
||
return (
|
||
<LoaderPortal show={showLoader}>
|
||
<EditableTable
|
||
size={'small'}
|
||
bordered
|
||
columns={clusterColumns}
|
||
dataSource={clusters}
|
||
onRowAdd={makeActionHandler('insert', handlerProps)}
|
||
onRowEdit={makeActionHandler('update', handlerProps)}
|
||
onRowDelete={makeActionHandler('delete', handlerProps)}
|
||
/>
|
||
</LoaderPortal>
|
||
)
|
||
}
|