Skip to content

Commit

Permalink
Merge pull request #2073 from janmarius/FIX-1940
Browse files Browse the repository at this point in the history
Fix 1940 Refresh well/wells
  • Loading branch information
janmarius authored Oct 10, 2023
2 parents ddbbbed + 04b7d55 commit 6a78e69
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ export const WellboresListView = (): React.ReactElement => {
onContextMenu={onContextMenu}
downloadToCsvFileName="Wellbores"
checkableRows
showRefresh
/>
))
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ export const WellsListView = (): React.ReactElement => {
onContextMenu={onContextMenu}
checkableRows
downloadToCsvFileName="Wells"
showRefresh
/>
)}
</WellProgress>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import { Button, Icon, Typography } from "@equinor/eds-core-react";
import { Table } from "@tanstack/react-table";
import React, { useCallback, useContext, useState } from "react";
import React, { useCallback, useContext, useEffect, useState } from "react";
import styled from "styled-components";
import { ContentTableColumn } from ".";
import ModificationType from "../../../contexts/modificationType";
import NavigationContext from "../../../contexts/navigationContext";
import { treeNodeIsExpanded } from "../../../contexts/navigationStateReducer";
import NavigationType from "../../../contexts/navigationType";
import useExport, { encloseCell } from "../../../hooks/useExport";
import ObjectService from "../../../services/objectService";
import WellService from "../../../services/wellService";
import { ColumnOptionsMenu } from "./ColumnOptionsMenu";

export interface PanelProps {
Expand Down Expand Up @@ -40,18 +43,55 @@ const Panel = (props: PanelProps) => {
stickyLeftColumns
} = props;
const { navigationState, dispatchNavigation } = useContext(NavigationContext);
const { selectedWellbore, selectedObjectGroup } = navigationState;
const { selectedServer, selectedWell, selectedWellbore, selectedObjectGroup, currentSelected, expandedTreeNodes } = navigationState;
const [isRefreshing, setIsRefreshing] = useState<boolean>(false);
const { exportData, exportOptions } = useExport();
const abortRefreshControllerRef = React.useRef<AbortController>();

const selectedItemsText = checkableRows ? `Selected: ${numberOfCheckedItems}/${numberOfItems}` : `Items: ${numberOfItems}`;

const onClickRefresh = async () => {
setIsRefreshing(true);
useEffect(() => {
return () => {
abortRefreshControllerRef.current?.abort();
};
}, []);

const refreshObjects = async () => {
abortRefreshControllerRef.current = new AbortController();
const wellUid = selectedWellbore.wellUid;
const wellboreUid = selectedWellbore.uid;
const wellboreObjects = await ObjectService.getObjects(wellUid, wellboreUid, selectedObjectGroup);
const wellboreObjects = await ObjectService.getObjects(wellUid, wellboreUid, selectedObjectGroup, abortRefreshControllerRef.current.signal);
dispatchNavigation({ type: ModificationType.UpdateWellboreObjects, payload: { wellboreObjects, wellUid, wellboreUid, objectType: selectedObjectGroup } });
};

const refreshWells = async () => {
abortRefreshControllerRef.current = new AbortController();
const wells = await WellService.getWells(abortRefreshControllerRef.current.signal);
dispatchNavigation({ type: ModificationType.UpdateWells, payload: { wells } });
dispatchNavigation({ type: NavigationType.SelectServer, payload: { server: selectedServer } });
};

const refreshWell = async () => {
abortRefreshControllerRef.current = new AbortController();
const nodeId = selectedWell.uid;
if (treeNodeIsExpanded(expandedTreeNodes, nodeId)) {
dispatchNavigation({ type: NavigationType.CollapseTreeNodeChildren, payload: { nodeId } });
}

const well = await WellService.getWell(nodeId, abortRefreshControllerRef.current.signal);
dispatchNavigation({ type: ModificationType.UpdateWell, payload: { well, overrideWellbores: true } });
dispatchNavigation({ type: NavigationType.SelectWell, payload: { well } });
};

const onClickRefresh = async () => {
setIsRefreshing(true);
if (currentSelected === selectedServer) {
await refreshWells();
} else if (currentSelected === selectedWell) {
await refreshWell();
} else {
await refreshObjects();
}
setIsRefreshing(false);
};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
import { Typography } from "@equinor/eds-core-react";
import { Divider, MenuItem } from "@material-ui/core";
import React from "react";
import React, { useContext } from "react";
import { v4 as uuid } from "uuid";
import ModificationType from "../../contexts/modificationType";
import NavigationContext from "../../contexts/navigationContext";
import { treeNodeIsExpanded } from "../../contexts/navigationStateReducer";
import NavigationType from "../../contexts/navigationType";
import { DisplayModalAction, HideContextMenuAction, HideModalAction } from "../../contexts/operationStateReducer";
import OperationType from "../../contexts/operationType";
import { DeleteWellJob } from "../../models/jobs/deleteJobs";
import { Server } from "../../models/server";
import Well from "../../models/well";
import Wellbore from "../../models/wellbore";
import JobService, { JobType } from "../../services/jobService";
import WellService from "../../services/wellService";
import { colors } from "../../styles/Colors";
import { WellRow } from "../ContentViews/WellsListView";
import ConfirmModal from "../Modals/ConfirmModal";
Expand All @@ -31,6 +36,10 @@ export interface WellContextMenuProps {

const WellContextMenu = (props: WellContextMenuProps): React.ReactElement => {
const { dispatchOperation, well, servers, checkedWellRows } = props;
const {
dispatchNavigation,
navigationState: { expandedTreeNodes, selectedServer, selectedWell }
} = useContext(NavigationContext);

const onClickNewWell = () => {
const newWell: Well = {
Expand All @@ -45,6 +54,27 @@ const WellContextMenu = (props: WellContextMenuProps): React.ReactElement => {
dispatchOperation({ type: OperationType.DisplayModal, payload: <WellPropertiesModal {...wellPropertiesModalProps} /> });
};

const onClickRefresh = async () => {
dispatchOperation({ type: OperationType.HideContextMenu });
const nodeId = well.uid;
if (treeNodeIsExpanded(expandedTreeNodes, nodeId)) {
dispatchNavigation({ type: NavigationType.CollapseTreeNodeChildren, payload: { nodeId } });
}
if (selectedWell?.uid == well.uid) {
dispatchNavigation({ type: NavigationType.SelectWell, payload: { well } });
}

const updatedWell = await WellService.getWell(well.uid);
dispatchNavigation({ type: ModificationType.UpdateWell, payload: { well: updatedWell, overrideWellbores: true } });
};

const onClickRefreshAll = async () => {
dispatchOperation({ type: OperationType.HideContextMenu });
const updatedWells = await WellService.getWells();
dispatchNavigation({ type: ModificationType.UpdateWells, payload: { wells: updatedWells } });
dispatchNavigation({ type: NavigationType.SelectServer, payload: { server: selectedServer } });
};

const onClickNewWellbore = () => {
const newWellbore: Wellbore = {
uid: uuid(),
Expand Down Expand Up @@ -132,6 +162,14 @@ const WellContextMenu = (props: WellContextMenuProps): React.ReactElement => {
return (
<ContextMenu
menuItems={[
<MenuItem key={"refreshwell"} onClick={onClickRefresh}>
<StyledIcon name="refresh" color={colors.interactive.primaryResting} />
<Typography color={"primary"}>Refresh well</Typography>
</MenuItem>,
<MenuItem key={"refreshallwells"} onClick={onClickRefreshAll}>
<StyledIcon name="refresh" color={colors.interactive.primaryResting} />
<Typography color={"primary"}>Refresh all wells</Typography>
</MenuItem>,
<MenuItem key={"newWell"} onClick={onClickNewWell}>
<StyledIcon name="add" color={colors.interactive.primaryResting} />
<Typography color={"primary"}>New Well</Typography>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export interface AddWellAction extends Action {

export interface UpdateWellAction extends Action {
type: ModificationType.UpdateWell;
payload: { well: Well };
payload: { well: Well; overrideWellbores?: boolean };
}

export interface UpdateWellsAction extends Action {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,12 +123,13 @@ const addWell = (state: NavigationState, { payload }: AddWellAction) => {
};

const updateWell = (state: NavigationState, { payload }: UpdateWellAction) => {
const { well } = payload;
const { well, overrideWellbores } = payload;
const wells = [...state.wells];
const wellIndex = getWellIndex(wells, well.uid);
const { wellbores } = wells[wellIndex];
const { wellbores: oldWellbores } = wells[wellIndex];
const updatedWell = overrideWellbores ? { ...well } : { ...well, wellbores: oldWellbores };
wells[wellIndex] = updatedWell;

wells[wellIndex] = { ...well, wellbores };
const refreshedWellIsSelected = state.selectedWell?.uid === well.uid;

return {
Expand Down

0 comments on commit 6a78e69

Please sign in to comment.