diff --git a/src/components/selectors/WellSelector.jsx b/src/components/selectors/WellSelector.jsx index e6cf3b8..4fe00c1 100755 --- a/src/components/selectors/WellSelector.jsx +++ b/src/components/selectors/WellSelector.jsx @@ -36,7 +36,7 @@ export const getTreeLabels = (treeData) => { return labels } -export const WellSelector = memo(({ idWell, value, onChange, treeData, treeLabels, ...other }) => { +export const WellSelector = memo(({ value, onChange, treeData, treeLabels, ...other }) => { const [wellsTree, setWellsTree] = useState([]) const [wellLabels, setWellLabels] = useState([]) @@ -52,7 +52,7 @@ export const WellSelector = memo(({ idWell, value, onChange, treeData, treeLabel 'Не удалось загрузить список скважин', 'Получение списка скважин' ) - }, [idWell, treeData, treeLabels]) + }, [treeData, treeLabels]) return ( (null) +/** Контекст текущей скважины */ +export const WellContext = createContext<[WellDto, (well: WellDto) => void]>([{}, () => {}]) /** Контекст текущего корневого пути */ export const RootPathContext = createContext('') /** - * Получает текущий ID скважины + * Получение текущей скважины * - * @returns Текущий ID скважины, либо `null` + * @returns Текущая скважина, либо `null` */ -export const useIdWell = () => useContext(IdWellContext) +export const useWell = () => useContext(WellContext) /** * Получает текущий корневой путь diff --git a/src/pages/Analytics/Statistics.jsx b/src/pages/Analytics/Statistics.jsx index 1ec67e2..c3f6e11 100755 --- a/src/pages/Analytics/Statistics.jsx +++ b/src/pages/Analytics/Statistics.jsx @@ -1,7 +1,7 @@ import { Table as RawTable, Typography } from 'antd' import { Fragment, memo, useCallback, useEffect, useState } from 'react' -import { useIdWell } from '@asb/context' +import { useWell } from '@asb/context' import LoaderPortal from '@components/LoaderPortal' import { invokeWebApiWrapperAsync } from '@components/factory' import { WellSelector } from '@components/selectors/WellSelector' @@ -76,7 +76,7 @@ const Statistics = memo(() => { const [cmpData, setCmpData] = useState([]) const [avgRow, setAvgRow] = useState({}) - const idWell = useIdWell() + const [well] = useWell() const cmpSpeedRender = useCallback((key) => (section) => { let spanClass = '' @@ -99,14 +99,14 @@ const Statistics = memo(() => { useEffect(() => { invokeWebApiWrapperAsync( async () => { - const types = await WellOperationService.getSectionTypes(idWell) + const types = await WellOperationService.getSectionTypes(well.id) setSectionTypes(Object.entries(types)) }, setIsPageLoading, - `Не удалось получить типы секции`, + `Не удалось получить типы секции для скважины "${well.caption}"`, `Получение списка возможных секций`, ) - }, [idWell]) + }, [well]) useEffect(() => { invokeWebApiWrapperAsync( @@ -197,7 +197,6 @@ const Statistics = memo(() => {
Выберите скважины для расчёта средних значений: {
Выберите скважины сравнения: { const [showParamsLoader, setShowParamsLoader] = useState(false) const [isParamsModalVisible, setIsParamsModalVisible] = useState(false) - const idWell = useIdWell() + const [well] = useWell() useEffect(() => { - invokeWebApiWrapperAsync(async () => setParamsColumns(await getColumns(idWell))) - }, [idWell]) + invokeWebApiWrapperAsync(async () => setParamsColumns(await getColumns(well.id))) + }, [well]) const onParamButtonClick = useCallback(() => invokeWebApiWrapperAsync( async () => { setIsParamsModalVisible(true) - const params = await DrillParamsService.getCompositeAll(idWell) + const params = await DrillParamsService.getCompositeAll(well.id) setParams(params) }, setShowParamsLoader, - `Не удалось загрузить список режимов для скважины "${idWell}"`, + `Не удалось загрузить список режимов для скважины "${well.caption}"`, 'Получение списка режимов скважины' - ), [idWell]) + ), [well]) const onParamsAddClick = useCallback(() => invokeWebApiWrapperAsync( async () => { - await DrillParamsService.save(idWell, params) + await DrillParamsService.save(well.id, params) setIsParamsModalVisible(false) }, setShowParamsLoader, - `Не удалось добавить режимы в список скважины "${idWell}"`, + `Не удалось добавить режимы в список скважины "${well.caption}"`, 'Добавление режима скважины' - ), [idWell, params]) + ), [well, params]) return ( <> diff --git a/src/pages/Analytics/WellCompositeEditor/WellCompositeSections.jsx b/src/pages/Analytics/WellCompositeEditor/WellCompositeSections.jsx index 12d819b..76a8689 100644 --- a/src/pages/Analytics/WellCompositeEditor/WellCompositeSections.jsx +++ b/src/pages/Analytics/WellCompositeEditor/WellCompositeSections.jsx @@ -3,8 +3,7 @@ import { useState, useEffect, memo, useMemo } from 'react' import { LineChartOutlined, ProfileOutlined, TeamOutlined } from '@ant-design/icons' import { Table, Tag, Button, Badge, Divider, Modal, Row, Col } from 'antd' -import { useIdWell } from '@asb/context' -import { CompanyView } from '@components/views' +import { useWell } from '@asb/context' import LoaderPortal from '@components/LoaderPortal' import { invokeWebApiWrapperAsync } from '@components/factory' import { makeTextColumn, makeNumericColumnPlanFact, makeNumericColumn } from '@components/Table' @@ -37,13 +36,13 @@ const WellCompositeSections = memo(({ statsWells, selectedSections }) => { const [wellOperations, setWellOperations] = useState([]) const [companies, setCompanies] = useState([]) const [selectedWellsKeys, setSelectedWellsKeys] = useState([]) - const [selectedWellId, setSelectedWellId] = useState(0) + const [selectedWell, setSelectedWell] = useState(null) const [showLoader, setShowLoader] = useState(false) const [isTVDModalVisible, setIsTVDModalVisible] = useState(false) const [isOpsModalVisible, setIsOpsModalVisible] = useState(false) const [isCompaniesModalVisible, setIsCompaniesModalVisible] = useState(false) - const idWell = useIdWell() + const [well] = useWell() const location = useLocation() @@ -104,16 +103,16 @@ const WellCompositeSections = memo(({ statsWells, selectedSections }) => { }, [statsWells]) useEffect(() => { - if (isOpsModalVisible || selectedWellId <= 0) return + if (isOpsModalVisible || !selectedWell) return invokeWebApiWrapperAsync( async () => { - const { operations } = await getOperations(selectedWellId) + const { operations } = await getOperations(selectedWell.id) setWellOperations(operations) }, setShowLoader, - `Не удалось загрузить операции по скважине "${selectedWellId}"`, + `Не удалось загрузить операции по скважине "${selectedWell.caption}"`, ) - }, [selectedWellId, isOpsModalVisible]) + }, [selectedWell, isOpsModalVisible]) useEffect(() => { const selected = rows.filter((row) => selectedSections.some(section => ( @@ -128,17 +127,17 @@ const WellCompositeSections = memo(({ statsWells, selectedSections }) => { selectedRowKeys: selectedWellsKeys, onChange: (keys, items) => invokeWebApiWrapperAsync( async () => { - const selectedSections = items.map((row) => ({idWell, idWellSrc: row.id, idWellSectionType: row.sectionId})) - await WellCompositeService.save(idWell, selectedSections) + const selectedSections = items.map((row) => ({ idWell: well.id, idWellSrc: row.id, idWellSectionType: row.sectionId})) + await WellCompositeService.save(well.id, selectedSections) setSelectedWells(items) setSelectedWellsKeys(keys) }, setShowLoader, - `Не удалось сохранить изменения выбранных секций для композитной скважины "${idWell}"`, + `Не удалось сохранить изменения выбранных секций для композитной скважины "${well.caption}"`, 'Изменение выбранных секций скважины' ) - }, [idWell, selectedWellsKeys]) + }, [well, selectedWellsKeys]) const columns = useMemo(() => [ makeTextColumn('скв №', 'caption', null, null, @@ -157,7 +156,7 @@ const WellCompositeSections = memo(({ statsWells, selectedSections }) => { title: 'TVD', render: (value) => ( )} diff --git a/src/pages/Telemetry/TelemetryView/WirelineRunOut.jsx b/src/pages/Telemetry/TelemetryView/WirelineRunOut.jsx index bc5c40e..763c623 100644 --- a/src/pages/Telemetry/TelemetryView/WirelineRunOut.jsx +++ b/src/pages/Telemetry/TelemetryView/WirelineRunOut.jsx @@ -1,6 +1,6 @@ import { memo, useCallback, useEffect, useState } from 'react' -import { useIdWell } from '@asb/context' +import { useWell } from '@asb/context' import { WirelineView } from '@components/views' import { invokeWebApiWrapperAsync } from '@components/factory' import { TelemetryWirelineRunOutService } from '@api' @@ -10,16 +10,16 @@ export const WirelineRunOut = memo(() => { const [twro, setTwro] = useState({}) const [isLoading, setIsLoading] = useState(false) - const idWell = useIdWell() + const [well] = useWell() const update = useCallback(() => invokeWebApiWrapperAsync( async () => { - const twro = await TelemetryWirelineRunOutService.getData(idWell) + const twro = await TelemetryWirelineRunOutService.getData(well.id) setTwro(twro) }, setIsLoading, - 'Не удалось получить данные по талевому канату' - ), [idWell]) + `Не удалось получить данные по талевому канату скважины "${well.caption}"` + ), [well]) const onTooltipVisibleChanged = useCallback((visible) => { if (visible) update() diff --git a/src/pages/Telemetry/TelemetryView/index.jsx b/src/pages/Telemetry/TelemetryView/index.jsx index 6e69057..2220061 100755 --- a/src/pages/Telemetry/TelemetryView/index.jsx +++ b/src/pages/Telemetry/TelemetryView/index.jsx @@ -2,7 +2,7 @@ import { useState, useEffect, useCallback, memo, useMemo } from 'react' import { BehaviorSubject, buffer, throttleTime } from 'rxjs' import { Button, Select } from 'antd' -import { useIdWell } from '@asb/context' +import { useWell } from '@asb/context' import { makeDateSorter } from '@components/Table' import { D3MonitoringCharts } from '@components/d3/monitoring' import LoaderPortal from '@components/LoaderPortal' @@ -15,8 +15,7 @@ import { DrillFlowChartService, OperationStatService, TelemetryDataSaubService, - TelemetryDataSpinService, - WellService + TelemetryDataSpinService } from '@api' import ActiveMessagesOnline from './ActiveMessagesOnline' @@ -143,14 +142,13 @@ const TelemetryView = memo(() => { const [dataSaub, setDataSaub] = useState([]) const [dataSpin, setDataSpin] = useState([]) const [chartInterval, setChartInterval] = useState(defaultPeriod) - const [wellData, setWellData] = useState({ idState: 0 }) const [showLoader, setShowLoader] = useState(false) const [flowChartData, setFlowChartData] = useState([]) const [rop, setRop] = useState(null) const [domain, setDomain] = useState({}) const [chartMethods, setChartMethods] = useState() - const idWell = useIdWell() + const [well, updateWell] = useWell() const saubSubject$ = useMemo(() => new BehaviorSubject(), []) const spinSubject$ = useMemo(() => new BehaviorSubject(), []) @@ -187,53 +185,42 @@ const TelemetryView = memo(() => { useEffect(() => { invokeWebApiWrapperAsync( async () => { - const flowChart = await DrillFlowChartService.getByIdWell(idWell) - const dataSaub = await TelemetryDataSaubService.getData(idWell, null, chartInterval) - const dataSpin = await TelemetryDataSpinService.getData(idWell, null, chartInterval) + const flowChart = await DrillFlowChartService.getByIdWell(well.id) + const dataSaub = await TelemetryDataSaubService.getData(well.id, null, chartInterval) + const dataSpin = await TelemetryDataSpinService.getData(well.id, null, chartInterval) setFlowChartData(flowChart ?? []) handleDataSaub(dataSaub) handleDataSpin(dataSpin) }, null, - `Не удалось получить данные по скважине "${idWell}"`, + `Не удалось получить данные по скважине "${well.caption}"`, 'Получение данных по скважине' ) - }, [idWell, chartInterval, handleDataSpin, handleDataSaub]) + }, [well, chartInterval, handleDataSpin, handleDataSaub]) useEffect(() => { const unsubscribe = Subscribe( - 'hubs/telemetry', `well_${idWell}`, + 'hubs/telemetry', `well_${well.id}`, { methodName: 'ReceiveDataSaub', handler: (data) => saubSubject$.next(data) }, { methodName: 'ReceiveDataSpin', handler: (data) => spinSubject$.next(data) } ) return () => unsubscribe() - }, [idWell, saubSubject$, spinSubject$]) + }, [well.id, saubSubject$, spinSubject$]) useEffect(() => { invokeWebApiWrapperAsync( async () => { - const well = await WellService.get(idWell) - const rop = await OperationStatService.getClusterRopStatByIdWell(idWell) + const rop = await OperationStatService.getClusterRopStatByIdWell(well.id) setRop(rop) - setWellData(well ?? {}) }, setShowLoader, - `Не удалось загрузить данные по скважине "${idWell}"`, + `Не удалось загрузить данные по скважине "${well.caption}"`, 'Получение данных по скважине' ) - }, [idWell]) + }, [well]) - const onStatusChanged = useCallback((value) => invokeWebApiWrapperAsync( - async () => { - const well = { idWell, ...wellData, idState: value } - await WellService.updateWell(well) - setWellData(well) - }, - setShowLoader, - `Не удалось задать состояние скважины "${idWell}"`, - 'Задание состояния скважины' - ), [idWell, wellData]) + const onStatusChanged = useCallback((value) => updateWell({ idState: value }), [well]) useEffect(() => { if (dataSaub.length <= 0) return @@ -275,7 +262,7 @@ const TelemetryView = memo(() => {
Статус:  - @@ -316,7 +303,7 @@ const TelemetryView = memo(() => { /> - + diff --git a/src/pages/Well.jsx b/src/pages/Well.jsx index b98f636..347263d 100755 --- a/src/pages/Well.jsx +++ b/src/pages/Well.jsx @@ -5,13 +5,15 @@ import { DeploymentUnitOutlined, } from '@ant-design/icons' import { Layout } from 'antd' -import { memo, useMemo } from 'react' +import { memo, useCallback, useEffect, useMemo, useState } from 'react' import { Navigate, Route, Routes, useParams } from 'react-router-dom' -import { IdWellContext, RootPathContext, useRootPath } from '@asb/context' +import { WellContext, RootPathContext, useRootPath } from '@asb/context' import { LayoutPortal } from '@components/Layout' import { PrivateMenu } from '@components/Private' +import { invokeWebApiWrapperAsync } from '@components/factory' import { NoAccessComponent, wrapPrivateComponent } from '@utils' +import { WellService } from '@api' import Measure from './Measure' import Reports from './Reports' @@ -27,9 +29,33 @@ const { Content } = Layout const Well = memo(() => { const { idWell } = useParams() + + const [well, setWell] = useState({ id: idWell }) + const root = useRootPath() const rootPath = useMemo(() => `${root}/well/${idWell}`, [root, idWell]) + useEffect(() => { + invokeWebApiWrapperAsync( + async () => { + const well = await WellService.get(idWell) + setWell(well ?? { id: idWell }) + }, + undefined, + 'Не удалось получить данные по скважине' + ) + }, [idWell]) + + const updateWell = useCallback((data) => invokeWebApiWrapperAsync( + async () => { + const newWell = { ...well, ...data } + await WellService.updateWell(newWell) + setWell(newWell) + }, + undefined, + `Не удалось изменить данные скважины "${well.caption}"` + ), [well]) + return ( @@ -43,7 +69,7 @@ const Well = memo(() => { } /> - + @@ -60,7 +86,7 @@ const Well = memo(() => { - + ) diff --git a/src/pages/WellOperations/DrillProcessFlow.jsx b/src/pages/WellOperations/DrillProcessFlow.jsx index 6b050a1..798583f 100755 --- a/src/pages/WellOperations/DrillProcessFlow.jsx +++ b/src/pages/WellOperations/DrillProcessFlow.jsx @@ -1,6 +1,6 @@ -import { useState, useEffect, memo, useMemo } from 'react' +import { useState, useEffect, memo, useMemo, useCallback } from 'react' -import { useIdWell } from '@asb/context' +import { useWell } from '@asb/context' import LoaderPortal from '@components/LoaderPortal' import { invokeWebApiWrapperAsync } from '@components/factory' import { EditableTable, makeNumericMinMax, makeNumericStartEnd } from '@components/Table' @@ -21,21 +21,21 @@ export const DrillProcessFlow = memo(() => { const [flows, setFlows] = useState([]) const [showLoader, setShowLoader] = useState(false) - const idWell = useIdWell() + const [well] = useWell() - const updateFlows = () => invokeWebApiWrapperAsync( + const updateFlows = useCallback(() => invokeWebApiWrapperAsync( async () => { - const flows = await DrillFlowChartService.getByIdWell(idWell) + const flows = await DrillFlowChartService.getByIdWell(well.id) setFlows(arrayOrDefault(flows)) }, setShowLoader, - 'Не удалось загрузить режимно-технологическую карту скважины', + `Не удалось загрузить режимно-технологическую карту скважины "${well.caption}"`, 'Получение режимно-технологической карты скважины' - ) + ), [well]) useEffect(() => { updateFlows() - }, [idWell]) + }, [well]) const tableHandlers = useMemo(() => { const handlerProps = { @@ -45,14 +45,14 @@ export const DrillProcessFlow = memo(() => { permission: 'DrillFlowChart.edit', } - const recordParser = (record) => ({ idWell, ...record }) + const recordParser = (record) => ({ idWell: well.id, ...record }) return { add: { ...handlerProps, action: 'insert', actionName: 'Добавление месторождения', recordParser }, edit: { ...handlerProps, action: 'update', actionName: 'Редактирование месторождения', recordParser }, delete: { ...handlerProps, action: 'delete', actionName: 'Удаление месторождения', permission: 'DrillFlowChart.delete' }, } - }, [updateFlows, idWell]) + }, [updateFlows, well.di]) return ( diff --git a/src/pages/WellOperations/ImportExportBar.jsx b/src/pages/WellOperations/ImportExportBar.jsx index 6633363..3776ffd 100755 --- a/src/pages/WellOperations/ImportExportBar.jsx +++ b/src/pages/WellOperations/ImportExportBar.jsx @@ -1,8 +1,8 @@ -import { memo, useMemo, useState } from 'react' +import { memo, useCallback, useMemo, useState } from 'react' import { Button, Tooltip, Modal } from 'antd' import { FileOutlined, ImportOutlined, ExportOutlined } from '@ant-design/icons' -import { useIdWell } from '@asb/context' +import { useWell } from '@asb/context' import { download } from '@components/factory' import { hasPermission } from '@utils' @@ -10,19 +10,19 @@ import { ImportOperations } from './ImportOperations' const style = { margin: 4 } -export const ImportExportBar = memo(({ idWell: wellId, onImported, disabled }) => { +export const ImportExportBar = memo(({ well: givenWell, onImported, disabled }) => { const [isImportModalVisible, setIsImportModalVisible] = useState(false) - const idWellContext = useIdWell() - const idWell = useMemo(() => wellId ?? idWellContext, [idWellContext]) + const [wellContext] = useWell() + const well = useMemo(() => givenWell ?? wellContext, [givenWell, wellContext]) - const downloadTemplate = async () => await download(`/api/well/${idWell}/wellOperations/template`) - const downloadExport = async () => await download(`/api/well/${idWell}/wellOperations/export`) + const downloadTemplate = useCallback(async () => await download(`/api/well/${well.id}/wellOperations/template`), [well.id]) + const downloadExport = useCallback(async () => await download(`/api/well/${well.id}/wellOperations/export`), [well.id]) - const onDone = () => { + const onDone = useCallback(() => { setIsImportModalVisible(false) onImported?.() - } + }, [onImported]) return (
@@ -52,7 +52,7 @@ export const ImportExportBar = memo(({ idWell: wellId, onImported, disabled }) = onCancel={() => setIsImportModalVisible(false)} footer={null} > - +
) diff --git a/src/pages/WellOperations/ImportOperations.jsx b/src/pages/WellOperations/ImportOperations.jsx index 76e74e8..cc0062b 100755 --- a/src/pages/WellOperations/ImportOperations.jsx +++ b/src/pages/WellOperations/ImportOperations.jsx @@ -1,44 +1,47 @@ import { Switch } from 'antd' -import { memo, useState } from 'react' +import { memo, useCallback, useMemo, useState } from 'react' +import { useWell } from '@asb/context' import { ErrorFetch } from '@components/ErrorFetch' import { UploadForm } from '@components/UploadForm' const errorTextStyle = { color: 'red', fontWeight: 'bold' } const uploadFormStyle = { marginTop: '24px' } -export const ImportOperations = memo(({ idWell, onDone }) =>{ - const [deleteBeforeImport, setDeleteBeforeImport] = useState(false) - const [errorText, setErrorText] = useState('') +export const ImportOperations = memo(({ well: givenWell, onDone }) => { + const [deleteBeforeImport, setDeleteBeforeImport] = useState(false) + const [errorText, setErrorText] = useState('') - const url = `/api/well/${idWell}/wellOperations/import${deleteBeforeImport ? '/1' : '/0'}` + const [wellContext] = useWell() + const well = useMemo(() => givenWell ?? wellContext, [givenWell, wellContext]) - const onUploadSuccess = () => { - setErrorText('') - onDone?.() - } + const url = useMemo(() => `/api/well/${well.id}/wellOperations/import${deleteBeforeImport ? '/1' : '/0'}`, [well]) - const onUploadError = (error) => { - if(error instanceof ErrorFetch && error.status === 400) - setErrorText(`Не удалось импортировать.\n ${error?.message}`) - else - setErrorText(`Не удалось импортировать.`) - } + const onUploadSuccess = useCallback(() => { + setErrorText('') + onDone?.() + }, [onDone]) - return ( -
-

Загрузить файл excel с операциями на сервер

- Очистить список операций перед импортом  - - - {errorText} -
- ) + const onUploadError = useCallback((error) => { + if (error instanceof ErrorFetch && error.status === 400) + setErrorText(`Не удалось импортировать.\n ${error?.message}`) + else setErrorText(`Не удалось импортировать.`) + }, []) + + return ( +
+

Загрузить файл excel с операциями на сервер

+ Очистить список операций перед импортом  + + + {errorText} +
+ ) }) export default ImportOperations diff --git a/src/pages/WellOperations/Tvd/NetGraphExport.jsx b/src/pages/WellOperations/Tvd/NetGraphExport.jsx index 048a024..e574b0b 100755 --- a/src/pages/WellOperations/Tvd/NetGraphExport.jsx +++ b/src/pages/WellOperations/Tvd/NetGraphExport.jsx @@ -4,14 +4,14 @@ import { Button } from 'antd' import { download, invokeWebApiWrapperAsync } from '@components/factory' -export const NetGraphExport = memo(({ idWell, ...other }) => { +export const NetGraphExport = memo(({ well, ...other }) => { const [isFileExporting, setIsFileExporting] = useState(false) const onExport = useCallback(() => invokeWebApiWrapperAsync( - async () => await download(`/api/well/${idWell}/wellOperations/scheduleReport`), + async () => await download(`/api/well/${well.id}/wellOperations/scheduleReport`), setIsFileExporting, 'Не удалось загрузить файл' - ), [idWell]) + ), [well.id]) return (
diff --git a/src/pages/WellOperations/Tvd/StatExport.jsx b/src/pages/WellOperations/Tvd/StatExport.jsx index e425ecc..c0d51a3 100644 --- a/src/pages/WellOperations/Tvd/StatExport.jsx +++ b/src/pages/WellOperations/Tvd/StatExport.jsx @@ -1,31 +1,16 @@ -import { memo, useCallback, useEffect, useState } from 'react' +import { memo, useCallback, useState } from 'react' import { Button, Input } from 'antd' -import { useIdWell } from '@asb/context' import { download, invokeWebApiWrapperAsync } from '@components/factory' -import { WellService } from '@api' -export const StatExport = memo(() => { +export const StatExport = memo(({ well }) => { const [isFileExporting, setIsFileExporting] = useState(false) - const [idCluster, setIdCluster] = useState() - const idWell = useIdWell() - useEffect(() => { - invokeWebApiWrapperAsync( - async () => { - const { idCluster } = await WellService.get(idWell) - setIdCluster(idCluster) - }, - setIsFileExporting, - 'Не удалось загрузить ID куста' - ) - }, [idWell]) - - const onExport = useCallback((well) => invokeWebApiWrapperAsync( - async () => await download(`/api/DetectedOperation/export?${well ? 'idWell' : 'idCluster'}=${well ? idWell : idCluster}`), + const onExport = useCallback((isWell) => invokeWebApiWrapperAsync( + async () => await download(`/api/DetectedOperation/export?${isWell ? 'idWell' : 'idCluster'}=${isWell ? well.id : well.idCluster}`), setIsFileExporting, 'Не удалось загрузить файл' - ), [idWell, idCluster]) + ), [well]) return ( diff --git a/src/pages/WellOperations/Tvd/TLChart.jsx b/src/pages/WellOperations/Tvd/TLChart.jsx index 2d5feca..4d82890 100644 --- a/src/pages/WellOperations/Tvd/TLChart.jsx +++ b/src/pages/WellOperations/Tvd/TLChart.jsx @@ -4,7 +4,6 @@ import { Empty } from 'antd' import moment from 'moment' import * as d3 from 'd3' -import { useIdWell } from '@asb/context' import LoaderPortal from '@components/LoaderPortal' import { invokeWebApiWrapperAsync } from '@components/factory' import { DetectedOperationService } from '@api' @@ -44,6 +43,7 @@ const splitByDate = (startTime, endTime) => { } export const TLChart = memo(({ + well, backgroundColor = '#0000', barHeight = 15, offset = defaultOffset, @@ -59,8 +59,6 @@ export const TLChart = memo(({ const [rootRef, { width, height }] = useElementSize() - const idWell = useIdWell() - const dates = useMemo(() => { if (!data || data.length <= 0) return [0, 0] return [ @@ -82,7 +80,7 @@ export const TLChart = memo(({ useEffect(() => { invokeWebApiWrapperAsync( async () => { - const { operations } = await DetectedOperationService.get(idWell) + const { operations } = await DetectedOperationService.get(well.id) setData(operations.map((raw) => { const startTime = moment(raw.dateStart) const endTime = moment(raw.dateEnd) @@ -94,9 +92,9 @@ export const TLChart = memo(({ }).flat()) }, setIsLoading, - 'Не удалось загрузить список операций' + `Не удалось загрузить список операций по скважине "${well.caption}"` ) - }, [idWell]) + }, [well]) useEffect(() => { // Рисуем ось X const xAxisArea = d3.select(svgRef).select('.axis.x') diff --git a/src/pages/WellOperations/Tvd/TLPie.jsx b/src/pages/WellOperations/Tvd/TLPie.jsx index 828c856..bf3e2cf 100644 --- a/src/pages/WellOperations/Tvd/TLPie.jsx +++ b/src/pages/WellOperations/Tvd/TLPie.jsx @@ -3,7 +3,6 @@ import { useElementSize } from 'usehooks-ts' import { Empty } from 'antd' import * as d3 from 'd3' -import { useIdWell } from '@asb/context' import { makeColumn, makeNumericColumn, makeTextColumn, Table } from '@components/Table' import LoaderPortal from '@components/LoaderPortal' import { invokeWebApiWrapperAsync } from '@components/factory' @@ -24,7 +23,7 @@ const tableColumns = [ makeNumericColumn('Процент, %', 'percent', undefined, undefined, (d) => d ? d.toFixed(2) : '---', 100) ] -export const TLPie = memo(() => { +export const TLPie = memo(({ well }) => { const [isLoading, setIsLoading] = useState(false) const [svgRef, setSvgRef] = useState() const [stats, setStats] = useState([]) @@ -32,8 +31,6 @@ export const TLPie = memo(() => { const [rootRef, { width, height }] = useElementSize() - const idWell = useIdWell() - const pie = useMemo(() => d3.pie().value((d) => d.minutesTotal), []) const getColor = useMemo(() => makeGetColor(stats?.map((row) => row.idCategory).filter(unique)), [stats]) @@ -83,13 +80,13 @@ export const TLPie = memo(() => { useEffect(() => { invokeWebApiWrapperAsync( async () => { - const stats = await DetectedOperationService.getStat(idWell) + const stats = await DetectedOperationService.getStat(well.id) setStats(stats) }, setIsLoading, - 'Не удалось загрузить статистику автоопределённых операций' + `Не удалось загрузить статистику автоопределённых операций по скважине "${well.caption}"` ) - }, [idWell]) + }, [well]) useEffect(() => { if (!data) return diff --git a/src/pages/WellOperations/Tvd/index.jsx b/src/pages/WellOperations/Tvd/index.jsx index 550de4c..aafbd7a 100644 --- a/src/pages/WellOperations/Tvd/index.jsx +++ b/src/pages/WellOperations/Tvd/index.jsx @@ -4,7 +4,7 @@ import { Switch, Segmented, Button } from 'antd' import { Link } from 'react-router-dom' import * as d3 from 'd3' -import { useIdWell } from '@asb/context' +import { useWell } from '@asb/context' import { D3Chart } from '@components/d3' import LoaderPortal from '@components/LoaderPortal' import { invokeWebApiWrapperAsync } from '@components/factory' @@ -149,15 +149,15 @@ const makeDataset = (key, label, color, width, radius, dash) => ({ }, }) -const Tvd = memo(({ idWell: wellId, title, ...other }) => { +const Tvd = memo(({ well: givenWell, title, ...other }) => { const [xLabel, setXLabel] = useState('day') const [operations, setOperations] = useState({}) const [isLoading, setIsLoading] = useState(false) const [pointsEnabled, setPointsEnabled] = useState(true) const [selectedTab, setSelectedTab] = useState('Скрыть') - const idWellContext = useIdWell() - const idWell = useMemo(() => wellId ?? idWellContext, [wellId, idWellContext]) + const [wellContext] = useWell() + const well = useMemo(() => givenWell ?? wellContext, [givenWell, wellContext]) const chartData = useMemo(() => { const withoutNpt = [] @@ -187,12 +187,12 @@ const Tvd = memo(({ idWell: wellId, title, ...other }) => { useEffect(() => { invokeWebApiWrapperAsync( - async () => setOperations(await getOperations(idWell)), + async () => setOperations(await getOperations(well.id)), setIsLoading, - `Не удалось загрузить операции по скважине "${idWell}"`, + `Не удалось загрузить операции по скважине "${well.caption}"`, 'Получение списка опервций по скважине' ) - }, [idWell]) + }, [well]) return (
@@ -216,8 +216,8 @@ const Tvd = memo(({ idWell: wellId, title, ...other }) => {
- - + + { />
{selectedTab === 'НПВ' && } - {selectedTab === 'ЕСО' && } - {selectedTab === 'Статистика' && } + {selectedTab === 'ЕСО' && } + {selectedTab === 'Статистика' && }
diff --git a/src/pages/WellOperations/WellDrillParams.jsx b/src/pages/WellOperations/WellDrillParams.jsx index 2ee9f7e..1387584 100755 --- a/src/pages/WellOperations/WellDrillParams.jsx +++ b/src/pages/WellOperations/WellDrillParams.jsx @@ -1,6 +1,6 @@ import { useState, useEffect, useCallback, memo, useMemo } from 'react' -import { useIdWell } from '@asb/context' +import { useWell } from '@asb/context' import { EditableTable, makeSelectColumn, @@ -39,28 +39,28 @@ export const WellDrillParams = memo(() => { const [showLoader, setShowLoader] = useState(false) const [columns, setColumns] = useState([]) - const idWell = useIdWell() + const [well] = useWell() const updateParams = useCallback(async () => await invokeWebApiWrapperAsync( async () => { - const params = arrayOrDefault(await DrillParamsService.getAll(idWell)) + const params = arrayOrDefault(await DrillParamsService.getAll(well.id)) // Typescript против использования числа в качестве типа значения select params.forEach((param) => param.idWellSectionType = `${param.idWellSectionType}`) setParams(params) }, setShowLoader, - 'Не удалось загрузить список режимов бурения скважины', + `Не удалось загрузить список режимов бурения скважины "${well.caption}"`, 'Получение списка режимов бурения скважины' - ), [idWell]) + ), [well]) useEffect(() => { (async () => { - setColumns(await getColumns(idWell)) + setColumns(await getColumns(well.id)) await updateParams() })() - }, [idWell, updateParams]) + }, [well.id, updateParams]) - const recordParser = useCallback((record) => ({ ...record, idWell }), [idWell]) + const recordParser = useCallback((record) => ({ ...record, idWell: well.id }), [well.id]) const tableHandlers = useMemo(() => { const handlerProps = { @@ -68,7 +68,7 @@ export const WellDrillParams = memo(() => { setLoader: setShowLoader, onComplete: updateParams, permission: 'DrillParams.edit', - idWell, + idWell: well.id, idRecord: true, } @@ -77,7 +77,7 @@ export const WellDrillParams = memo(() => { edit: { ...handlerProps, action: 'update', actionName: 'Редактирование режима бурения', recordParser }, delete: { ...handlerProps, action: 'delete', actionName: 'Удаление режима бурения', permission: 'DrillParams.delete' }, } - }, [idWell, updateParams, recordParser]) + }, [well.id, updateParams, recordParser]) return ( diff --git a/src/pages/WellOperations/WellOperationsEditor.jsx b/src/pages/WellOperations/WellOperationsEditor.jsx index 7c7ec85..da471b1 100755 --- a/src/pages/WellOperations/WellOperationsEditor.jsx +++ b/src/pages/WellOperations/WellOperationsEditor.jsx @@ -3,7 +3,7 @@ import { Input } from 'antd' import { useLocation } from 'react-router-dom' import { useState, useEffect, memo, useMemo, useCallback } from 'react' -import { useIdWell } from '@asb/context' +import { useWell } from '@asb/context' import { EditableTable, makeColumn, @@ -57,7 +57,7 @@ const WellOperationsEditor = memo(({ idType, showNpt, ...other }) => { const [operations, setOperations] = useState([]) const [showLoader, setShowLoader] = useState(false) - const idWell = useIdWell() + const [well] = useWell() const [categories, setCategories] = useState([]) const [sectionTypes, setSectionTypes] = useState([]) @@ -73,23 +73,23 @@ const WellOperationsEditor = memo(({ idType, showNpt, ...other }) => { useEffect(() => { invokeWebApiWrapperAsync( async () => { - const categories = arrayOrDefault(await WellOperationService.getCategories(idWell)) + const categories = arrayOrDefault(await WellOperationService.getCategories(well.id)) setCategories(categories.map((item) => ({ value: item.id, label: item.name }))) - const sectionTypes = Object.entries(await WellOperationService.getSectionTypes(idWell) ?? {}) + const sectionTypes = Object.entries(await WellOperationService.getSectionTypes(well.id) ?? {}) setSectionTypes(sectionTypes.map(([id, label]) => ({ value: parseInt(id), label }))) }, setShowLoader, - 'Не удалось загрузить список операций по скважине', + `Не удалось загрузить список операций по скважине "${well.caption}"`, 'Получение списка операций по скважине' ) - }, [idWell]) + }, [well]) const updateOperations = useCallback(() => invokeWebApiWrapperAsync( async () => { const skip = ((pageNumAndPageSize.current - 1) * pageNumAndPageSize.pageSize) || 0 const take = pageNumAndPageSize.pageSize - const paginatedOperations = await WellOperationService.getOperations(idWell, + const paginatedOperations = await WellOperationService.getOperations(well.id, idType, undefined, undefined, undefined, undefined, undefined, undefined, skip, take) const operations = paginatedOperations?.items ?? [] @@ -98,9 +98,9 @@ const WellOperationsEditor = memo(({ idType, showNpt, ...other }) => { setPaginationTotal(total) }, setShowLoader, - 'Не удалось загрузить список операций по скважине', + `Не удалось загрузить список операций по скважине ${well.caption}`, 'Получение списка операций по скважине' - ), [idWell, idType, pageNumAndPageSize]) + ), [well, idType, pageNumAndPageSize]) useEffect(() => { updateOperations() @@ -125,7 +125,7 @@ const WellOperationsEditor = memo(({ idType, showNpt, ...other }) => { onComplete: updateOperations, permission: 'WellOperation.edit', idRecord: true, - idWell, + idWell: well.id, } return { @@ -133,7 +133,7 @@ const WellOperationsEditor = memo(({ idType, showNpt, ...other }) => { edit: { ...handlerProps, action: 'update', actionName: 'Редактирование операции по скважине', recordParser }, delete: { ...handlerProps, action: 'delete', actionName: 'Удаление операции по скважине', permission: 'WellOperation.delete' }, } - }, [updateOperations, idWell, recordParser]) + }, [updateOperations, well.id, recordParser]) return ( diff --git a/src/pages/WellOperations/WellSectionsStat.jsx b/src/pages/WellOperations/WellSectionsStat.jsx index b683f5f..59d874f 100755 --- a/src/pages/WellOperations/WellSectionsStat.jsx +++ b/src/pages/WellOperations/WellSectionsStat.jsx @@ -1,6 +1,6 @@ import { useState, useEffect, memo } from 'react' -import { useIdWell } from '@asb/context' +import { useWell } from '@asb/context' import LoaderPortal from '@components/LoaderPortal' import { invokeWebApiWrapperAsync } from '@components/factory' import { Table, makeColumn, makeColumnsPlanFact, makeNumericRender } from '@components/Table' @@ -25,12 +25,12 @@ export const WellSectionsStat = memo(() => { const [sections, setSections] = useState([]) const [showLoader, setShowLoader] = useState(false) - const idWell = useIdWell() + const [well] = useWell() useEffect(() => { invokeWebApiWrapperAsync( async () => { - const sectionsResponse = await OperationStatService.getStatWell(idWell) + const sectionsResponse = await OperationStatService.getStatWell(well.id) if(sectionsResponse?.sections){ const sections = sectionsResponse.sections.map(s => ({ @@ -57,10 +57,10 @@ export const WellSectionsStat = memo(() => { } }, setShowLoader, - `Не удалось получить статистику по секциям скважины "${idWell}"`, + `Не удалось получить статистику по секциям скважины "${well.caption}"`, 'Получение статистики по секциям скважины' ) - }, [idWell]) + }, [well]) return (