dictionary.js удалён

Исправлен баг с /cluster/*/all
Конструирование колонок WellDrillParams обёрнуто в функцию
This commit is contained in:
Александр Сироткин 2021-12-29 11:11:49 +05:00
parent 5007398e6e
commit 604ecd346b
5 changed files with 74 additions and 65 deletions

View File

@ -1,14 +1,17 @@
import { Map, Overlay } from "pigeon-maps"
import { PointerIcon } from '../components/icons/PointerIcon'
import { Link } from "react-router-dom";
import { Map, Overlay } from 'pigeon-maps'
import { Link } from 'react-router-dom'
import { useState, useEffect, memo } from 'react'
import { PointerIcon } from '../components/icons'
import LoaderPortal from '../components/LoaderPortal'
import { useState, useEffect } from "react";
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) => {
if ((!clusters) || clusters.length === 0)
return { center: [60.81226, 70.0562], zoom: 5 }
if ((clusters?.length ?? 0) <= 0)
return defaultViewParams
const center = clusters.reduce((sum, cluster) => {
sum[0] += (cluster.latitude / clusters.length)
@ -27,26 +30,25 @@ const calcViewParams = (clusters) => {
// zoom min = 1 (mega far)
// 4 - full Russia (161.6 deg)
// 13.5 - Khanty-Mansiysk
let zoom = 5 + 5 / (maxDeg + 0.5)
zoom = zoom < 5 ? 5 : zoom
zoom = zoom > 15 ? 15 : zoom
const zoom = Math.min(Math.max(5, 5 + 5 / (maxDeg + 0.5)), 15)
return { center, zoom }
}
export default function Deposit() {
export const Deposit = memo(() => {
const [clustersData, setClustersData] = useState([])
const [showLoader, setShowLoader] = useState(false)
const [viewParams, setViewParams] = useState(defaultViewParams)
useEffect(() => invokeWebApiWrapperAsync(async () => {
const data = await ClusterService.getClusters()
setClustersData(data)
},
useEffect(() => invokeWebApiWrapperAsync(
async () => {
const data = await ClusterService.getClusters()
setClustersData(data)
setViewParams(calcViewParams(data))
},
setShowLoader,
`Не удалось загрузить список кустов`),
[])
const viewParams = calcViewParams(clustersData)
`Не удалось загрузить список кустов`
), [])
return (
<LoaderPortal show={showLoader}>
@ -56,15 +58,18 @@ export default function Deposit() {
<Overlay
width={32}
anchor={[cluster.latitude, cluster.longitude]}
key={`${cluster.latitude} ${cluster.longitude}`}>
<Link to={`/cluster/${cluster.id}/all`}>
<PointerIcon state={'active'} width={48} height={59}/>
key={`${cluster.latitude} ${cluster.longitude}`}
>
<Link to={`/cluster/${cluster.id}`}>
<PointerIcon state={'active'} width={48} height={59} />
<span>{cluster.caption}</span>
</Link>
</Overlay >
</Overlay>
)}
</Map>
</div>
</LoaderPortal>
)
}
})
export default Deposit

View File

@ -54,8 +54,10 @@ export const SetpointSender = ({ idWell, onClose, visible, setpointNames }) => {
const onModalOk = () => invokeWebApiWrapperAsync(
async () => {
// eslint-disable-next-line no-sequences
const setpointsObject = setpoints.reduce((obj, sp) => (obj[sp.name] = sp.value, obj), {})
const setpointsObject = setpoints.reduce((obj, sp) => {
obj[sp.name] = sp.value
return obj
}, {})
const request = {
uploadDate: new Date(),
obsolescenceSec: expirePeriod,

View File

@ -16,7 +16,7 @@ import {
} from '../../Cluster/functions'
import { Tvd } from '../Tvd'
import WellOperationsTable from '../../Cluster/WellOperationsTable'
import { columns as paramsColumns } from '../WellDrillParams'
import { getColumns } from '../WellDrillParams'
const filtersMinMax = [
@ -27,7 +27,7 @@ const filtersMinMax = [
const filtersSectionsType = []
const DAY_IN_MS = 1000 * 60 * 60 * 24
export const WellCompositeSections = ({idWell, statsWells, selectedSections}) => {
export const WellCompositeSections = ({ idWell, statsWells, selectedSections }) => {
const [showLoader, setShowLoader] = useState(false)
const [showParamsLoader, setShowParamsLoader] = useState(false)
@ -40,6 +40,9 @@ export const WellCompositeSections = ({idWell, statsWells, selectedSections}) =>
const [wellOperations, setWellOperations] = useState([])
const [rows, setRows] = useState([])
const [params, setParams] = useState([])
const [paramsColumns, setParamsColumns] = useState([])
useEffect(() => setParamsColumns(getColumns(idWell)), [idWell])
useEffect(() => {
if (isOpsModalVisible || selectedWellId <= 0) return

View File

@ -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 { invokeWebApiWrapperAsync } from '../../components/factory'
import { EditableTable, SelectFromDictionary } from '../../components/Table'
import { makeActionHandler, makeColumn, makeNumericAvgRange } from '../../components/Table'
import {
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 = [
makeColumn('Конструкция секции','idWellSectionType', {
editable: true,
input: <SelectFromDictionary dictionary={dictionarySectionType}/>,
width: 160,
render: (_, record) => getByKeyOrReturnKey(dictionarySectionType, record.idWellSectionType)
}),
makeNumericAvgRange('Нагрузка, т', 'axialLoad', 1),
makeNumericAvgRange('Давление, атм', 'pressure', 1),
makeNumericAvgRange('Момент на ВСП, кН·м', 'rotorTorque', 1),
makeNumericAvgRange('Обороты на ВСП, об/мин', 'rotorSpeed', 1),
makeNumericAvgRange('Расход, л/с', 'flow', 1)
]
return [
makeSelectColumn('Конструкция секции','idWellSectionType', sectionTypes, null, {
editable: true,
width: 160,
}),
makeNumericAvgRange('Нагрузка, т', 'axialLoad', 1),
makeNumericAvgRange('Давление, атм', 'pressure', 1),
makeNumericAvgRange('Момент на ВСП, кН·м', 'rotorTorque', 1),
makeNumericAvgRange('Обороты на ВСП, об/мин', 'rotorSpeed', 1),
makeNumericAvgRange('Расход, л/с', 'flow', 1),
]
}
export const WellDrillParams = ({ idWell }) => {
const [params, setParams] = useState([])
const [showLoader, setShowLoader] = useState(false)
const [columns, setColumns] = useState([])
const updateParams = () => invokeWebApiWrapperAsync(
const updateParams = useCallback(async () => await invokeWebApiWrapperAsync(
async () => {
const params = await DrillParamsService.getAll(idWell)
setParams(Array.isArray(params) ? params : [])
const params = arrayOrDefault(await DrillParamsService.getAll(idWell))
setParams(params)
},
setShowLoader,
'Не удалось загрузить список режимов бурения скважины'
)
), [idWell])
useEffect(updateParams, [idWell])
useEffect(() => {
setColumns(getColumns(idWell))
updateParams()
}, [idWell, updateParams])
const handlerProps = {
service: DrillParamsService,

View File

@ -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
}