diff --git a/src/pages/Deposit.jsx b/src/pages/Deposit.jsx
index 40fb0ef..e0f4ac6 100644
--- a/src/pages/Deposit.jsx
+++ b/src/pages/Deposit.jsx
@@ -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 (
@@ -56,15 +58,18 @@ export default function Deposit() {
-
-
+ key={`${cluster.latitude} ${cluster.longitude}`}
+ >
+
+
{cluster.caption}
-
+
)}
)
-}
+})
+
+export default Deposit
diff --git a/src/pages/TelemetryView/SetpointSender.jsx b/src/pages/TelemetryView/SetpointSender.jsx
index 8757e5d..a45fc63 100644
--- a/src/pages/TelemetryView/SetpointSender.jsx
+++ b/src/pages/TelemetryView/SetpointSender.jsx
@@ -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,
diff --git a/src/pages/WellOperations/WellCompositeEditor/WellCompositeSections.jsx b/src/pages/WellOperations/WellCompositeEditor/WellCompositeSections.jsx
index 8782669..0dc49f0 100644
--- a/src/pages/WellOperations/WellCompositeEditor/WellCompositeSections.jsx
+++ b/src/pages/WellOperations/WellCompositeEditor/WellCompositeSections.jsx
@@ -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
diff --git a/src/pages/WellOperations/WellDrillParams.jsx b/src/pages/WellOperations/WellDrillParams.jsx
index a44c835..0c4524c 100644
--- a/src/pages/WellOperations/WellDrillParams.jsx
+++ b/src/pages/WellOperations/WellDrillParams.jsx
@@ -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: ,
- 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,
diff --git a/src/pages/WellOperations/dictionary.js b/src/pages/WellOperations/dictionary.js
deleted file mode 100644
index bf4a39f..0000000
--- a/src/pages/WellOperations/dictionary.js
+++ /dev/null
@@ -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
-}