WellSelector применено к композитной скважине

This commit is contained in:
Александр Сироткин 2022-03-13 22:20:41 +05:00
parent 929fc50b35
commit 21149754c7

View File

@ -1,15 +1,14 @@
import { useState, useEffect, memo } from 'react' import { useState, useEffect, memo } from 'react'
import { Switch, useParams } from 'react-router-dom' import { Switch, useParams } from 'react-router-dom'
import { Col, Layout, Menu, Row, Tag, TreeSelect } from 'antd' import { Col, Layout, Menu, Row } from 'antd'
import { import {
DepositService,
OperationStatService, OperationStatService,
WellCompositeService, WellCompositeService,
} from '@api' } from '@api'
import { arrayOrDefault } from '@utils' import { arrayOrDefault } from '@utils'
import { hasPermission } from '@utils/permissions'
import LoaderPortal from '@components/LoaderPortal' import LoaderPortal from '@components/LoaderPortal'
import WellSelector from '@components/WellSelector'
import { invokeWebApiWrapperAsync } from '@components/factory' import { invokeWebApiWrapperAsync } from '@components/factory'
import { PrivateDefaultRoute, PrivateMenuItemLink, PrivateRoute } from '@components/Private' import { PrivateDefaultRoute, PrivateMenuItemLink, PrivateRoute } from '@components/Private'
@ -21,53 +20,25 @@ const { Content } = Layout
export const WellCompositeEditor = memo(({ idWell, rootPath }) => { export const WellCompositeEditor = memo(({ idWell, rootPath }) => {
const { tab } = useParams() const { tab } = useParams()
const [wellsTree, setWellsTree] = useState([])
const [wellLabels, setWellLabels] = useState([])
const [statsWells, setStatsWells] = useState([]) const [statsWells, setStatsWells] = useState([])
const [showLoader, setShowLoader] = useState(false) const [showLoader, setShowLoader] = useState(false)
const [showTabLoader, setShowTabLoader] = useState(false) const [showTabLoader, setShowTabLoader] = useState(false)
const [selectedIdWells, setSelectedIdWells] = useState([]) const [selectedIdWells, setSelectedIdWells] = useState([])
const [selectedSections, setSelectedSections] = useState([]) const [selectedSections, setSelectedSections] = useState([])
useEffect(() => { useEffect(() => invokeWebApiWrapperAsync(
invokeWebApiWrapperAsync( async () => {
async () => { try {
const deposits = await DepositService.getDeposits() const selected = await WellCompositeService.get(idWell)
const labels = {} setSelectedSections(arrayOrDefault(selected))
const wellsTree = deposits.map((deposit, dIdx) => ({ } catch(e) {
title: deposit.caption, setSelectedSections([])
key: `0-${dIdx}`, }
value: `0-${dIdx}`, },
children: deposit.clusters.map((cluster, cIdx) => ({ setShowLoader,
title: cluster.caption, 'Не удалось загрузить список скважин',
key: `0-${dIdx}-${cIdx}`, 'Получение списка скважин'
value: `0-${dIdx}-${cIdx}`, ), [idWell])
children: cluster.wells.map(well => {
labels[well.id] = `${deposit.caption}.${cluster.caption}.${well.caption}`
return ({
title: well.caption,
key: well.id,
value: well.id,
})
}),
})),
}))
setWellsTree(wellsTree)
setWellLabels(labels)
try {
const selected = await WellCompositeService.get(idWell)
setSelectedSections(arrayOrDefault(selected))
} catch(e) {
setSelectedSections([])
}
},
setShowLoader,
'Не удалось загрузить список скважин',
'Получение списка скважин'
)
}, [idWell])
useEffect(() => { useEffect(() => {
const wellIds = selectedSections.map((value) => value.idWellSrc) const wellIds = selectedSections.map((value) => value.idWellSrc)
@ -88,22 +59,10 @@ export const WellCompositeEditor = memo(({ idWell, rootPath }) => {
<LoaderPortal show={showLoader}> <LoaderPortal show={showLoader}>
<Row align={'middle'} justify={'space-between'} wrap={false} style={{ backgroundColor: 'white' }}> <Row align={'middle'} justify={'space-between'} wrap={false} style={{ backgroundColor: 'white' }}>
<Col span={18}> <Col span={18}>
<TreeSelect <WellSelector
multiple idWell={idWell}
treeCheckable onChange={setSelectedIdWells}
showCheckedStrategy={TreeSelect.SHOW_CHILD}
treeDefaultExpandAll
treeData={wellsTree}
treeLine={{ showLeafIcon: false }}
onChange={(value) => setSelectedIdWells(value)}
size={'middle'}
style={{ width: '100%' }}
value={selectedIdWells} value={selectedIdWells}
placeholder={'Выберите скважины'}
tagRender={(props) => (
<Tag {...props}>{wellLabels[props.value] ?? props.label}</Tag>
)}
disabled={!hasPermission('WellOperation.edit')}
/> />
</Col> </Col>
<Col span={6}> <Col span={6}>