forked from ddrilling/asb_cloud_front
dictionary.js удалён
Исправлен баг с /cluster/*/all Конструирование колонок WellDrillParams обёрнуто в функцию
This commit is contained in:
parent
5007398e6e
commit
604ecd346b
@ -1,14 +1,17 @@
|
|||||||
import { Map, Overlay } from "pigeon-maps"
|
import { Map, Overlay } from 'pigeon-maps'
|
||||||
import { PointerIcon } from '../components/icons/PointerIcon'
|
import { Link } from 'react-router-dom'
|
||||||
import { Link } from "react-router-dom";
|
import { useState, useEffect, memo } from 'react'
|
||||||
|
|
||||||
|
import { PointerIcon } from '../components/icons'
|
||||||
import LoaderPortal from '../components/LoaderPortal'
|
import LoaderPortal from '../components/LoaderPortal'
|
||||||
import { useState, useEffect } from "react";
|
|
||||||
import { ClusterService } from '../services/api'
|
import { ClusterService } from '../services/api'
|
||||||
import { invokeWebApiWrapperAsync } from "../components/factory"
|
import { invokeWebApiWrapperAsync } from '../components/factory'
|
||||||
|
|
||||||
|
const defaultViewParams = { center: [60.81226, 70.0562], zoom: 5 }
|
||||||
|
|
||||||
const calcViewParams = (clusters) => {
|
const calcViewParams = (clusters) => {
|
||||||
if ((!clusters) || clusters.length === 0)
|
if ((clusters?.length ?? 0) <= 0)
|
||||||
return { center: [60.81226, 70.0562], zoom: 5 }
|
return defaultViewParams
|
||||||
|
|
||||||
const center = clusters.reduce((sum, cluster) => {
|
const center = clusters.reduce((sum, cluster) => {
|
||||||
sum[0] += (cluster.latitude / clusters.length)
|
sum[0] += (cluster.latitude / clusters.length)
|
||||||
@ -27,26 +30,25 @@ const calcViewParams = (clusters) => {
|
|||||||
// zoom min = 1 (mega far)
|
// zoom min = 1 (mega far)
|
||||||
// 4 - full Russia (161.6 deg)
|
// 4 - full Russia (161.6 deg)
|
||||||
// 13.5 - Khanty-Mansiysk
|
// 13.5 - Khanty-Mansiysk
|
||||||
let zoom = 5 + 5 / (maxDeg + 0.5)
|
const zoom = Math.min(Math.max(5, 5 + 5 / (maxDeg + 0.5)), 15)
|
||||||
zoom = zoom < 5 ? 5 : zoom
|
|
||||||
zoom = zoom > 15 ? 15 : zoom
|
|
||||||
|
|
||||||
return { center, zoom }
|
return { center, zoom }
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function Deposit() {
|
export const Deposit = memo(() => {
|
||||||
const [clustersData, setClustersData] = useState([])
|
const [clustersData, setClustersData] = useState([])
|
||||||
const [showLoader, setShowLoader] = useState(false)
|
const [showLoader, setShowLoader] = useState(false)
|
||||||
|
const [viewParams, setViewParams] = useState(defaultViewParams)
|
||||||
|
|
||||||
useEffect(() => invokeWebApiWrapperAsync(async () => {
|
useEffect(() => invokeWebApiWrapperAsync(
|
||||||
|
async () => {
|
||||||
const data = await ClusterService.getClusters()
|
const data = await ClusterService.getClusters()
|
||||||
setClustersData(data)
|
setClustersData(data)
|
||||||
|
setViewParams(calcViewParams(data))
|
||||||
},
|
},
|
||||||
setShowLoader,
|
setShowLoader,
|
||||||
`Не удалось загрузить список кустов`),
|
`Не удалось загрузить список кустов`
|
||||||
[])
|
), [])
|
||||||
|
|
||||||
const viewParams = calcViewParams(clustersData)
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<LoaderPortal show={showLoader}>
|
<LoaderPortal show={showLoader}>
|
||||||
@ -56,8 +58,9 @@ export default function Deposit() {
|
|||||||
<Overlay
|
<Overlay
|
||||||
width={32}
|
width={32}
|
||||||
anchor={[cluster.latitude, cluster.longitude]}
|
anchor={[cluster.latitude, cluster.longitude]}
|
||||||
key={`${cluster.latitude} ${cluster.longitude}`}>
|
key={`${cluster.latitude} ${cluster.longitude}`}
|
||||||
<Link to={`/cluster/${cluster.id}/all`}>
|
>
|
||||||
|
<Link to={`/cluster/${cluster.id}`}>
|
||||||
<PointerIcon state={'active'} width={48} height={59} />
|
<PointerIcon state={'active'} width={48} height={59} />
|
||||||
<span>{cluster.caption}</span>
|
<span>{cluster.caption}</span>
|
||||||
</Link>
|
</Link>
|
||||||
@ -67,4 +70,6 @@ export default function Deposit() {
|
|||||||
</div>
|
</div>
|
||||||
</LoaderPortal>
|
</LoaderPortal>
|
||||||
)
|
)
|
||||||
}
|
})
|
||||||
|
|
||||||
|
export default Deposit
|
||||||
|
@ -54,8 +54,10 @@ export const SetpointSender = ({ idWell, onClose, visible, setpointNames }) => {
|
|||||||
|
|
||||||
const onModalOk = () => invokeWebApiWrapperAsync(
|
const onModalOk = () => invokeWebApiWrapperAsync(
|
||||||
async () => {
|
async () => {
|
||||||
// eslint-disable-next-line no-sequences
|
const setpointsObject = setpoints.reduce((obj, sp) => {
|
||||||
const setpointsObject = setpoints.reduce((obj, sp) => (obj[sp.name] = sp.value, obj), {})
|
obj[sp.name] = sp.value
|
||||||
|
return obj
|
||||||
|
}, {})
|
||||||
const request = {
|
const request = {
|
||||||
uploadDate: new Date(),
|
uploadDate: new Date(),
|
||||||
obsolescenceSec: expirePeriod,
|
obsolescenceSec: expirePeriod,
|
||||||
|
@ -16,7 +16,7 @@ import {
|
|||||||
} from '../../Cluster/functions'
|
} from '../../Cluster/functions'
|
||||||
import { Tvd } from '../Tvd'
|
import { Tvd } from '../Tvd'
|
||||||
import WellOperationsTable from '../../Cluster/WellOperationsTable'
|
import WellOperationsTable from '../../Cluster/WellOperationsTable'
|
||||||
import { columns as paramsColumns } from '../WellDrillParams'
|
import { getColumns } from '../WellDrillParams'
|
||||||
|
|
||||||
|
|
||||||
const filtersMinMax = [
|
const filtersMinMax = [
|
||||||
@ -40,6 +40,9 @@ export const WellCompositeSections = ({idWell, statsWells, selectedSections}) =>
|
|||||||
const [wellOperations, setWellOperations] = useState([])
|
const [wellOperations, setWellOperations] = useState([])
|
||||||
const [rows, setRows] = useState([])
|
const [rows, setRows] = useState([])
|
||||||
const [params, setParams] = useState([])
|
const [params, setParams] = useState([])
|
||||||
|
const [paramsColumns, setParamsColumns] = useState([])
|
||||||
|
|
||||||
|
useEffect(() => setParamsColumns(getColumns(idWell)), [idWell])
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (isOpsModalVisible || selectedWellId <= 0) return
|
if (isOpsModalVisible || selectedWellId <= 0) return
|
||||||
|
@ -1,41 +1,54 @@
|
|||||||
import { useState, useEffect } from 'react'
|
import { useState, useEffect, useCallback } from 'react'
|
||||||
|
|
||||||
import { DrillParamsService } from '../../services/api'
|
import { DrillParamsService, WellOperationService } from '../../services/api'
|
||||||
import LoaderPortal from '../../components/LoaderPortal'
|
import LoaderPortal from '../../components/LoaderPortal'
|
||||||
import { invokeWebApiWrapperAsync } from '../../components/factory'
|
import { invokeWebApiWrapperAsync } from '../../components/factory'
|
||||||
import { EditableTable, SelectFromDictionary } from '../../components/Table'
|
import {
|
||||||
import { makeActionHandler, makeColumn, makeNumericAvgRange } from '../../components/Table'
|
EditableTable,
|
||||||
|
makeSelectColumn,
|
||||||
|
makeActionHandler,
|
||||||
|
makeNumericAvgRange,
|
||||||
|
} from '../../components/Table'
|
||||||
|
import { arrayOrDefault } from '../../utils'
|
||||||
|
|
||||||
import { dictionarySectionType, getByKeyOrReturnKey } from './dictionary'
|
export const getColumns = async (idWell) => {
|
||||||
|
let sectionTypes = await WellOperationService.getSectionTypes(idWell)
|
||||||
|
sectionTypes = Object.keys(sectionTypes).map((id) => ({
|
||||||
|
label: sectionTypes[id],
|
||||||
|
value: id,
|
||||||
|
}))
|
||||||
|
|
||||||
export const columns = [
|
return [
|
||||||
makeColumn('Конструкция секции','idWellSectionType', {
|
makeSelectColumn('Конструкция секции','idWellSectionType', sectionTypes, null, {
|
||||||
editable: true,
|
editable: true,
|
||||||
input: <SelectFromDictionary dictionary={dictionarySectionType}/>,
|
|
||||||
width: 160,
|
width: 160,
|
||||||
render: (_, record) => getByKeyOrReturnKey(dictionarySectionType, record.idWellSectionType)
|
|
||||||
}),
|
}),
|
||||||
makeNumericAvgRange('Нагрузка, т', 'axialLoad', 1),
|
makeNumericAvgRange('Нагрузка, т', 'axialLoad', 1),
|
||||||
makeNumericAvgRange('Давление, атм', 'pressure', 1),
|
makeNumericAvgRange('Давление, атм', 'pressure', 1),
|
||||||
makeNumericAvgRange('Момент на ВСП, кН·м', 'rotorTorque', 1),
|
makeNumericAvgRange('Момент на ВСП, кН·м', 'rotorTorque', 1),
|
||||||
makeNumericAvgRange('Обороты на ВСП, об/мин', 'rotorSpeed', 1),
|
makeNumericAvgRange('Обороты на ВСП, об/мин', 'rotorSpeed', 1),
|
||||||
makeNumericAvgRange('Расход, л/с', 'flow', 1)
|
makeNumericAvgRange('Расход, л/с', 'flow', 1),
|
||||||
]
|
]
|
||||||
|
}
|
||||||
|
|
||||||
export const WellDrillParams = ({ idWell }) => {
|
export const WellDrillParams = ({ idWell }) => {
|
||||||
const [params, setParams] = useState([])
|
const [params, setParams] = useState([])
|
||||||
const [showLoader, setShowLoader] = useState(false)
|
const [showLoader, setShowLoader] = useState(false)
|
||||||
|
const [columns, setColumns] = useState([])
|
||||||
|
|
||||||
const updateParams = () => invokeWebApiWrapperAsync(
|
const updateParams = useCallback(async () => await invokeWebApiWrapperAsync(
|
||||||
async () => {
|
async () => {
|
||||||
const params = await DrillParamsService.getAll(idWell)
|
const params = arrayOrDefault(await DrillParamsService.getAll(idWell))
|
||||||
setParams(Array.isArray(params) ? params : [])
|
setParams(params)
|
||||||
},
|
},
|
||||||
setShowLoader,
|
setShowLoader,
|
||||||
'Не удалось загрузить список режимов бурения скважины'
|
'Не удалось загрузить список режимов бурения скважины'
|
||||||
)
|
), [idWell])
|
||||||
|
|
||||||
useEffect(updateParams, [idWell])
|
useEffect(() => {
|
||||||
|
setColumns(getColumns(idWell))
|
||||||
|
updateParams()
|
||||||
|
}, [idWell, updateParams])
|
||||||
|
|
||||||
const handlerProps = {
|
const handlerProps = {
|
||||||
service: DrillParamsService,
|
service: DrillParamsService,
|
||||||
|
@ -1,14 +0,0 @@
|
|||||||
export const dictionarySectionType = new Map([
|
|
||||||
[1, 'Пилотный ствол'],
|
|
||||||
[2, 'Направление'],
|
|
||||||
[3, 'Кондуктор'],
|
|
||||||
[4, 'Эксплуатационная колонна'],
|
|
||||||
[5, 'Транспортный ствол'],
|
|
||||||
[6, 'Хвостовик'],
|
|
||||||
])
|
|
||||||
|
|
||||||
export const getByKeyOrReturnKey = (dictionary, key) => {
|
|
||||||
if(!dictionary)
|
|
||||||
return key
|
|
||||||
return dictionary.get(key) ?? key
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user