Skip to content

Commit

Permalink
Updated query-atoms to use new backend endpoints for survey data
Browse files Browse the repository at this point in the history
  • Loading branch information
Anders2303 committed Dec 4, 2024
1 parent 5c0c5dd commit d5a0412
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 30 deletions.
25 changes: 23 additions & 2 deletions frontend/src/modules/WellLogViewer/settings/atoms/derivedAtoms.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { WellboreHeader_api, WellboreLogCurveHeader_api } from "@api";
import { transformFormationData } from "@equinor/esv-intersection";
import { EnsembleSetAtom } from "@framework/GlobalAtoms";
import { WellPicksLayerData } from "@modules/Intersection/utils/layers/WellpicksLayer";
import { TemplatePlot, TemplateTrack } from "@webviz/well-log-viewer/dist/components/WellLogTemplateTypes";
Expand All @@ -16,9 +17,15 @@ import { logViewerTrackConfigs } from "./persistedAtoms";
import {
drilledWellboreHeadersQueryAtom,
wellLogCurveHeadersQueryAtom,
wellborePicksAndStratigraphyQueryAtom,
wellborePicksQueryAtom,
wellboreStratigraphicUnitsQueryAtom,
} from "./queryAtoms";

/**
* Exposing the return type of esv-intersection's transformFormationData, since they don't export that anywhere
*/
export type TransformFormationDataResult = ReturnType<typeof transformFormationData>;

export const firstEnsembleInSelectedFieldAtom = atom((get) => {
const selectedFieldId = get(userSelectedFieldIdentifierAtom);
const ensembleSetArr = get(EnsembleSetAtom).getEnsembleArr();
Expand Down Expand Up @@ -47,8 +54,22 @@ export const selectedWellboreHeaderAtom = atom<WellboreHeader_api | null>((get)
return availableWellboreHeaders.find((wh) => wh.wellboreUuid === selectedWellboreId) ?? availableWellboreHeaders[0];
});

export const availableWellPicksAtom = atom<TransformFormationDataResult>((get) => {
const wellborePicks = get(wellborePicksQueryAtom).data;
const wellboreStratUnits = get(wellboreStratigraphicUnitsQueryAtom).data;

if (!wellborePicks || !wellboreStratUnits) return { nonUnitPicks: [], unitPicks: [] };

const transformedPickData = transformFormationData(wellborePicks, wellboreStratUnits as any);

return {
nonUnitPicks: _.uniqBy(transformedPickData.nonUnitPicks, "identifier"),
unitPicks: _.uniqBy(transformedPickData.unitPicks, "name"),
};
});

export const selectedWellborePicksAtom = atom<WellPicksLayerData>((get) => {
const wellborePicks = get(wellborePicksAndStratigraphyQueryAtom)?.data;
const wellborePicks = get(availableWellPicksAtom);
const selectedUnitPicks = get(userSelectedUnitWellpicksAtom);
const selectedNonUnitPicks = get(userSelectedNonUnitWellpicksAtom);

Expand Down
39 changes: 19 additions & 20 deletions frontend/src/modules/WellLogViewer/settings/atoms/queryAtoms.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import { WellborePicksAndStratigraphicUnits_api } from "@api";
import { transformFormationData } from "@equinor/esv-intersection";
import { apiService } from "@framework/ApiService";
import { WellPicksLayerData } from "@modules/Intersection/utils/layers/WellpicksLayer";

import { atomWithQuery } from "jotai-tanstack-query";
import _ from "lodash";

import {
firstEnsembleInSelectedFieldAtom,
Expand Down Expand Up @@ -46,25 +42,28 @@ export const wellLogCurveHeadersQueryAtom = atomWithQuery((get) => {
};
});

export const wellborePicksAndStratigraphyQueryAtom = atomWithQuery((get) => {
const selectedEnsemble = get(firstEnsembleInSelectedFieldAtom);

const wellboreId = get(selectedWellboreHeaderAtom)?.wellboreUuid ?? "";
const caseId = selectedEnsemble?.getIdent()?.getCaseUuid() ?? "";
export const wellborePicksQueryAtom = atomWithQuery((get) => {
const selectedFieldIdent = get(selectedFieldIdentifierAtom) ?? "";
const selectedWellboreUuid = get(selectedWellboreHeaderAtom)?.wellboreUuid ?? "";

return {
queryKey: ["getWellborePicksAndStratigraphicUnits", wellboreId, caseId],
enabled: Boolean(caseId && wellboreId),
queryFn: () => apiService.well.getWellborePicksAndStratigraphicUnits(caseId, wellboreId),
select(data: WellborePicksAndStratigraphicUnits_api): WellPicksLayerData {
const transformedData = transformFormationData(data.wellbore_picks, data.stratigraphic_units as any);
queryKey: ["getWellborePicksForWellbore", selectedFieldIdent, selectedWellboreUuid],
enabled: Boolean(selectedFieldIdent && selectedWellboreUuid),
queryFn: () => apiService.well.getWellborePicksForWellbore(selectedFieldIdent, selectedWellboreUuid),
...SHARED_QUERY_OPTS,
};
});

export const wellboreStratigraphicUnitsQueryAtom = atomWithQuery((get) => {
// Stratigraphic column will be computed based on the case uuid
// TODO: Should make it a user-selected ensemble instead, at some point
const selectedEnsemble = get(firstEnsembleInSelectedFieldAtom);
const caseUuid = selectedEnsemble?.getCaseUuid() ?? "";

// ! Sometimes the transformation data returns duplicate entries, filtering them out
return {
nonUnitPicks: _.uniqBy(transformedData.nonUnitPicks, "identifier"),
unitPicks: _.uniqBy(transformedData.unitPicks, "name"),
};
},
return {
queryKey: ["getWellborePicksForWellbore", caseUuid],
enabled: Boolean(caseUuid),
queryFn: () => apiService.surface.getStratigraphicUnits(caseUuid),
...SHARED_QUERY_OPTS,
};
});
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ import { useAtom, useAtomValue } from "jotai";
import { WellpickSelect } from "./WellpickSelect";

import { userSelectedNonUnitWellpicksAtom, userSelectedUnitWellpicksAtom } from "../atoms/baseAtoms";
import { availableWellPicksAtom } from "../atoms/derivedAtoms";
import { padDataWithEmptyRowsAtom, viewerHorizontalAtom } from "../atoms/persistedAtoms";
import { wellborePicksAndStratigraphyQueryAtom } from "../atoms/queryAtoms";
import { wellborePicksQueryAtom, wellboreStratigraphicUnitsQueryAtom } from "../atoms/queryAtoms";

export type ViewerSettingsProps = {
statusWriter: SettingsStatusWriter;
Expand All @@ -24,9 +25,8 @@ export function ViewerSettings(props: ViewerSettingsProps): React.ReactNode {
const [padWithEmptyRows, setPadWithEmptyRows] = useAtom(padDataWithEmptyRowsAtom);

// Wellpick selection
const borePicksAndStratQuery = useAtomValue(wellborePicksAndStratigraphyQueryAtom);
const availableWellPicks = borePicksAndStratQuery.data ?? { nonUnitPicks: [], unitPicks: [] };
const wellpickErrorMsg = usePropagateApiErrorToStatusWriter(borePicksAndStratQuery, props.statusWriter) ?? "";
const availableWellPicks = useAtomValue(availableWellPicksAtom);
const wellPickQueryState = useGetWellpickQueryState(props.statusWriter);

const [selectedNonUnitPicks, setSelectedNonUnitPicks] = useAtom(userSelectedNonUnitWellpicksAtom);
const [selectedUnitPicks, setSelectedUnitPicks] = useAtom(userSelectedUnitWellpicksAtom);
Expand All @@ -43,7 +43,7 @@ export function ViewerSettings(props: ViewerSettingsProps): React.ReactNode {
</Label>

<Label text="Well picks">
<PendingWrapper isPending={borePicksAndStratQuery.isPending} errorMessage={wellpickErrorMsg}>
<PendingWrapper isPending={wellPickQueryState.anyLoading} errorMessage={wellPickQueryState.errorMsg}>
<WellpickSelect
availableWellpicks={availableWellPicks}
selectedNonUnitPicks={selectedNonUnitPicks}
Expand All @@ -56,3 +56,17 @@ export function ViewerSettings(props: ViewerSettingsProps): React.ReactNode {
</div>
);
}

// As `availableWellpicks` is computed based on two separate queries, we need to check loading states and error messages of both.
function useGetWellpickQueryState(statusWriter: SettingsStatusWriter): { anyLoading: boolean; errorMsg: string } {
const wellpicksQuery = useAtomValue(wellborePicksQueryAtom);
const stratUnitQuery = useAtomValue(wellboreStratigraphicUnitsQueryAtom);

const pickQueryError = usePropagateApiErrorToStatusWriter(wellpicksQuery, statusWriter);
const unitQueryError = usePropagateApiErrorToStatusWriter(stratUnitQuery, statusWriter);

return {
anyLoading: wellpicksQuery.isLoading || stratUnitQuery.isLoading,
errorMsg: pickQueryError ?? unitQueryError ?? "",
};
}
1 change: 1 addition & 0 deletions frontend/src/modules/WellLogViewer/view/atoms/baseAtoms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ import { WellboreHeader_api } from "@api";
import { atom } from "jotai";

export const wellboreHeaderAtom = atom<WellboreHeader_api | null>(null);
export const selectedFieldIdentAtom = atom<string | null>(null);
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import { InterfaceEffects } from "@framework/Module";
import { SettingsToViewInterface } from "@modules/WellLogViewer/interfaces";

import { wellboreHeaderAtom } from "./baseAtoms";
import { selectedFieldIdentAtom, wellboreHeaderAtom } from "./baseAtoms";

export const settingsToViewInterfaceEffects: InterfaceEffects<SettingsToViewInterface> = [
(getInterfaceValue, setAtomValue) => {
const wellboreUuid = getInterfaceValue("wellboreHeader");
setAtomValue(wellboreHeaderAtom, wellboreUuid);
},
(getInterfaceValue, setAtomValue) => {
const selectedField = getInterfaceValue("selectedField");
setAtomValue(selectedFieldIdentAtom, selectedField);
},
];
5 changes: 3 additions & 2 deletions frontend/src/modules/WellLogViewer/view/atoms/queryAtoms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,18 @@ import { apiService } from "@framework/ApiService";

import { atomWithQuery } from "jotai-tanstack-query";

import { wellboreHeaderAtom } from "./baseAtoms";
import { selectedFieldIdentAtom, wellboreHeaderAtom } from "./baseAtoms";

import { DEFAULT_OPTIONS } from "../queries/shared";

export const wellboreTrajectoryQueryAtom = atomWithQuery((get) => {
// Getting the settings atom via the interface for clearer seperation
const wellboreUuid = get(wellboreHeaderAtom)?.wellboreUuid ?? "";
const fieldIdent = get(selectedFieldIdentAtom) ?? "";

return {
queryKey: ["getWellTrajectories", wellboreUuid],
queryFn: () => apiService.well.getWellTrajectories([wellboreUuid]),
queryFn: () => apiService.well.getWellTrajectories(fieldIdent, [wellboreUuid]),
select: (data: WellboreTrajectory_api[]) => data[0],
enabled: Boolean(wellboreUuid),
...DEFAULT_OPTIONS,
Expand Down

0 comments on commit d5a0412

Please sign in to comment.