Skip to content

Commit

Permalink
FIX-2582 Fix wellbore creation bug (#2583)
Browse files Browse the repository at this point in the history
  • Loading branch information
eliasbruvik authored Oct 30, 2024
1 parent 6d61e37 commit 78c23b8
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 137 deletions.
7 changes: 5 additions & 2 deletions Src/WitsmlExplorer.Frontend/__testUtils__/testUtils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ import Trajectory from "models/trajectory";
import Tubular from "models/tubular";
import WbGeometryObject from "models/wbGeometry";
import Well, { emptyWell } from "models/well";
import Wellbore, { emptyWellbore } from "models/wellbore";
import Wellbore from "models/wellbore";
import { SnackbarProvider } from "notistack";
import React from "react";
import { MemoryRouter } from "react-router-dom";
Expand Down Expand Up @@ -170,7 +170,10 @@ export function getWell(overrides?: Partial<Well>): Well {

export function getWellbore(overrides?: Partial<Wellbore>): Wellbore {
return {
...emptyWellbore(),
name: "wellboreName",
uid: "wellboreUid",
wellName: "wellName",
wellUid: "wellUid",
...overrides
};
}
Expand Down
2 changes: 1 addition & 1 deletion Src/WitsmlExplorer.Frontend/components/Breadcrumbs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ const StyledBreadcrumbs = styled(EdsBreadcrumbs)<{ isCompact: boolean }>`
padding-right: 0.5rem;
}
`}
}`;
`;

const Title = styled.p`
line-height: 1rem;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,6 @@ const WellContextMenu = (props: WellContextMenuProps): React.ReactElement => {
name: "",
wellUid: well.uid,
wellName: well.name,
wellboreStatus: "",
wellboreType: "",
isActive: false,
wellboreParentUid: "",
wellboreParentName: "",
wellborePurpose: "unknown"
};
openWellboreProperties(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,6 @@ const WellboreContextMenu = (
name: "",
wellUid: wellbore.wellUid,
wellName: wellbore.wellName,
wellboreStatus: "",
wellboreType: "",
isActive: false,
wellboreParentUid: wellbore.uid,
wellboreParentName: wellbore.name,
wellborePurpose: "unknown"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { QueryObserverResult } from "@tanstack/react-query";
import { useGetWellbores } from "hooks/query/useGetWellbores";
import Wellbore, { WellboreProperties } from "models/wellbore";
import Wellbore from "models/wellbore";
import { useMemo } from "react";
import {
WellboreFilterType,
Expand Down Expand Up @@ -28,9 +28,7 @@ export const useGetWellboreSearch = (

const filteredData = useMemo(() => {
const regex = getSearchRegex(value, true);
const property = filterTypeToProperty[
filterType
] as keyof WellboreProperties;
const property = filterTypeToProperty[filterType] as keyof Wellbore;
return (
wellbores?.filter(
(result) =>
Expand Down
106 changes: 5 additions & 101 deletions Src/WitsmlExplorer.Frontend/models/wellbore.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,17 @@ import {
WITSML_INDEX_TYPE_DATE_TIME,
WITSML_INDEX_TYPE_MD
} from "components/Constants";
import BhaRun from "models/bhaRun";
import ChangeLog from "models/changeLog";
import FluidsReport from "models/fluidsReport";
import FormationMarker from "models/formationMarker";
import LogObject from "models/logObject";
import Measure from "models/measure";
import MessageObject from "models/messageObject";
import MudLog from "models/mudLog";
import {
ObjectType,
ObjectTypeToModel,
pluralizeObjectType
} from "models/objectType";
import Rig from "models/rig";
import RiskObject from "models/riskObject";
import Trajectory from "models/trajectory";
import Tubular from "models/tubular";
import WbGeometryObject from "models/wbGeometry";
import { ObjectType } from "models/objectType";

export interface WellboreProperties {
export default interface Wellbore {
uid: string;
name: string;
wellUid: string;
wellName?: string;
wellboreStatus: string;
wellboreType: string;
isActive: boolean;
wellboreStatus?: string;
wellboreType?: string;
isActive?: boolean;
number?: string;
suffixAPI?: string;
numGovt?: string;
Expand All @@ -53,63 +37,8 @@ export interface WellboreProperties {
objectCount?: ExpandableObjectsCount;
}

export interface WellboreObjects {
bhaRuns?: BhaRun[];
changeLogs?: ChangeLog[];
fluidsReports?: FluidsReport[];
formationMarkers?: FormationMarker[];
logs?: LogObject[];
rigs?: Rig[];
trajectories?: Trajectory[];
messages?: MessageObject[];
mudLogs?: MudLog[];
tubulars?: Tubular[];
risks?: RiskObject[];
wbGeometries?: WbGeometryObject[];
}

export type ExpandableObjectsCount = Partial<Record<ObjectType, number>>;

export default interface Wellbore extends WellboreProperties, WellboreObjects {}

export function emptyWellbore(): Wellbore {
return {
uid: "",
name: "",
wellUid: "",
wellName: "",
wellboreStatus: "",
wellboreType: "",
isActive: false,
wellboreParentUid: "",
wellboreParentName: "",
wellborePurpose: "unknown",
dateTimeCreation: "",
dateTimeLastChange: "",
itemState: "",
bhaRuns: [],
changeLogs: [],
fluidsReports: [],
formationMarkers: [],
logs: [],
rigs: [],
trajectories: [],
tubulars: [],
messages: [],
mudLogs: [],
risks: [],
wbGeometries: [],
objectCount: null
};
}

export function wellboreHasChanges(
wellbore: WellboreProperties,
updatedWellbore: WellboreProperties
): boolean {
return JSON.stringify(wellbore) !== JSON.stringify(updatedWellbore);
}

export const calculateWellNodeId = (wellUid: string): string => {
return `w=${wellUid};`;
};
Expand Down Expand Up @@ -183,28 +112,3 @@ export const getWellboreProperties = (
["UID Wellbore", wellbore.uid]
]);
};

export function objectTypeToWellboreObjects(
objectType: ObjectType
): keyof WellboreObjects {
return (objectType.charAt(0).toLowerCase() +
pluralizeObjectType(objectType).slice(1)) as keyof WellboreObjects;
}

export function getObjectsFromWellbore<Key extends ObjectType>(
wellbore: Wellbore,
objectType: Key
): ObjectTypeToModel[Key][] {
return wellbore[
objectTypeToWellboreObjects(objectType)
] as ObjectTypeToModel[Key][];
}

export function getObjectFromWellbore<Key extends ObjectType>(
wellbore: Wellbore,
uid: string,
objectType: Key
): ObjectTypeToModel[Key] {
const objects = getObjectsFromWellbore(wellbore, objectType);
return objects?.find((object) => object.uid === uid);
}
22 changes: 1 addition & 21 deletions Src/WitsmlExplorer.Frontend/services/objectService.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@ import {
pluralizeObjectType
} from "models/objectType";
import { Server } from "models/server";
import Wellbore, {
ExpandableObjectsCount,
getObjectsFromWellbore
} from "models/wellbore";
import { ExpandableObjectsCount } from "models/wellbore";
import { ApiClient, throwError } from "services/apiClient";

export default class ObjectService {
Expand Down Expand Up @@ -105,23 +102,6 @@ export default class ObjectService {
}
}

public static async getObjectsIfMissing<Key extends ObjectType>(
wellbore: Wellbore,
objectType: Key,
abortSignal?: AbortSignal
): Promise<ObjectTypeToModel[Key][] | null> {
const objects = getObjectsFromWellbore(wellbore, objectType);
if (objects == null || objects.length == 0) {
return await ObjectService.getObjects(
wellbore.wellUid,
wellbore.uid,
objectType,
abortSignal
);
}
return null;
}

public static async getExpandableObjectsCount(
wellUid: string,
wellboreUid: string,
Expand Down

0 comments on commit 78c23b8

Please sign in to comment.