From 380b79e563a833ec0aaad1730fbf28ba82eddae3 Mon Sep 17 00:00:00 2001 From: Hans Kallekleiv <16436291+HansKallekleiv@users.noreply.github.com> Date: Tue, 17 Oct 2023 12:12:27 +0100 Subject: [PATCH] Fixes to 3dGrid module (#430) --- frontend/src/modules/Grid3D/loadModule.tsx | 6 +- frontend/src/modules/Grid3D/queryHooks.ts | 75 +++++++- frontend/src/modules/Grid3D/settings.tsx | 180 +++++++++++++------ frontend/src/modules/Grid3D/state.ts | 8 +- frontend/src/modules/Grid3D/view.tsx | 190 ++++++++++++++------- 5 files changed, 328 insertions(+), 131 deletions(-) diff --git a/frontend/src/modules/Grid3D/loadModule.tsx b/frontend/src/modules/Grid3D/loadModule.tsx index 84bbc2165..24dc370c0 100644 --- a/frontend/src/modules/Grid3D/loadModule.tsx +++ b/frontend/src/modules/Grid3D/loadModule.tsx @@ -7,14 +7,12 @@ import { view } from "./view"; const defaultState: state = { gridName: "Simgrid", parameterName: "PORO", + selectedWellUuids: [], realizations: ["1"], useStatistics: false, - }; -const module = ModuleRegistry.initModule("Grid3D", defaultState, { - -}); +const module = ModuleRegistry.initModule("Grid3D", defaultState, {}); module.viewFC = view; module.settingsFC = settings; diff --git a/frontend/src/modules/Grid3D/queryHooks.ts b/frontend/src/modules/Grid3D/queryHooks.ts index f94777d1e..0fc0c29ca 100644 --- a/frontend/src/modules/Grid3D/queryHooks.ts +++ b/frontend/src/modules/Grid3D/queryHooks.ts @@ -1,3 +1,4 @@ +import { WellBoreHeader_api, WellBoreTrajectory_api } from "@api"; import { apiService } from "@framework/ApiService"; import { UseQueryResult, useQuery } from "@tanstack/react-query"; @@ -6,10 +7,16 @@ import { GridSurface_trans, transformGridSurface } from "./queryDataTransforms"; const STALE_TIME = 60 * 1000; const CACHE_TIME = 60 * 1000; -export function useGridSurface(caseUuid: string | null, ensembleName: string | null, gridName: string | null, realization: string | null): UseQueryResult { +export function useGridSurface( + caseUuid: string | null, + ensembleName: string | null, + gridName: string | null, + realization: string | null +): UseQueryResult { return useQuery({ queryKey: ["getGridSurface", caseUuid, ensembleName, gridName, realization], - queryFn: () => apiService.grid.gridSurface(caseUuid ?? "", ensembleName ?? "", gridName ?? "", realization ?? ""), + queryFn: () => + apiService.grid.gridSurface(caseUuid ?? "", ensembleName ?? "", gridName ?? "", realization ?? ""), select: transformGridSurface, staleTime: STALE_TIME, cacheTime: 0, @@ -17,28 +24,54 @@ export function useGridSurface(caseUuid: string | null, ensembleName: string | n }); } -export function useGridParameter(caseUuid: string | null, ensembleName: string | null, gridName: string | null, parameterName: string | null, realization: string | null, useStatistics: boolean): UseQueryResult { +export function useGridParameter( + caseUuid: string | null, + ensembleName: string | null, + gridName: string | null, + parameterName: string | null, + realization: string | null, + useStatistics: boolean +): UseQueryResult { return useQuery({ queryKey: ["getGridParameter", caseUuid, ensembleName, gridName, parameterName, realization], - queryFn: () => apiService.grid.gridParameter(caseUuid ?? "", ensembleName ?? "", gridName ?? "", parameterName ?? "", realization ?? ""), + queryFn: () => + apiService.grid.gridParameter( + caseUuid ?? "", + ensembleName ?? "", + gridName ?? "", + parameterName ?? "", + realization ?? "" + ), staleTime: STALE_TIME, cacheTime: 0, enabled: caseUuid && ensembleName && gridName && parameterName && realization && !useStatistics ? true : false, }); } - -export function useStatisticalGridParameter(caseUuid: string | null, ensembleName: string | null, gridName: string | null, parameterName: string | null, realizations: string[] | null, useStatistics: boolean): UseQueryResult { +export function useStatisticalGridParameter( + caseUuid: string | null, + ensembleName: string | null, + gridName: string | null, + parameterName: string | null, + realizations: string[] | null, + useStatistics: boolean +): UseQueryResult { return useQuery({ queryKey: ["getStatisticalGridParameter", caseUuid, ensembleName, gridName, parameterName, realizations], - queryFn: () => apiService.grid.statisticalGridParameter(caseUuid ?? "", ensembleName ?? "", gridName ?? "", parameterName ?? "", realizations ?? []), + queryFn: () => + apiService.grid.statisticalGridParameter( + caseUuid ?? "", + ensembleName ?? "", + gridName ?? "", + parameterName ?? "", + realizations ?? [] + ), staleTime: STALE_TIME, cacheTime: 0, enabled: caseUuid && ensembleName && gridName && parameterName && realizations && useStatistics ? true : false, }); } - export function useGridModelNames(caseUuid: string | null, ensembleName: string | null): UseQueryResult { return useQuery({ queryKey: ["getGridModelNames", caseUuid, ensembleName], @@ -49,7 +82,11 @@ export function useGridModelNames(caseUuid: string | null, ensembleName: string }); } -export function useGridParameterNames(caseUuid: string | null, ensembleName: string | null, gridName: string | null): UseQueryResult { +export function useGridParameterNames( + caseUuid: string | null, + ensembleName: string | null, + gridName: string | null +): UseQueryResult { return useQuery({ queryKey: ["getParameterNames", caseUuid, ensembleName, gridName], queryFn: () => apiService.grid.getParameterNames(caseUuid ?? "", ensembleName ?? "", gridName ?? ""), @@ -58,3 +95,23 @@ export function useGridParameterNames(caseUuid: string | null, ensembleName: str enabled: caseUuid && ensembleName && gridName ? true : false, }); } + +export function useGetWellHeaders(caseUuid: string | undefined): UseQueryResult { + return useQuery({ + queryKey: ["getWellHeaders", caseUuid], + queryFn: () => apiService.well.getWellHeaders(caseUuid ?? ""), + staleTime: STALE_TIME, + cacheTime: STALE_TIME, + enabled: caseUuid ? true : false, + }); +} + +export function useGetFieldWellsTrajectories(caseUuid: string | undefined): UseQueryResult { + return useQuery({ + queryKey: ["getFieldWellsTrajectories", caseUuid], + queryFn: () => apiService.well.getFieldWellTrajectories(caseUuid ?? ""), + staleTime: STALE_TIME, + cacheTime: CACHE_TIME, + enabled: caseUuid ? true : false, + }); +} diff --git a/frontend/src/modules/Grid3D/settings.tsx b/frontend/src/modules/Grid3D/settings.tsx index f54219f57..5e63512ff 100644 --- a/frontend/src/modules/Grid3D/settings.tsx +++ b/frontend/src/modules/Grid3D/settings.tsx @@ -1,103 +1,177 @@ import React, { useEffect } from "react"; +import { EnsembleIdent } from "@framework/EnsembleIdent"; import { ModuleFCProps } from "@framework/Module"; -import { useFirstEnsembleInEnsembleSet } from "@framework/WorkbenchSession"; +import { SyncSettingKey, SyncSettingsHelper } from "@framework/SyncSettings"; +import { useEnsembleSet } from "@framework/WorkbenchSession"; +import { fixupEnsembleIdent, maybeAssignFirstSyncedEnsemble } from "@framework/utils/ensembleUiHelpers"; import { ApiStateWrapper } from "@lib/components/ApiStateWrapper"; -import { useGridModelNames, useGridParameterNames } from "./queryHooks"; -import { CircularProgress } from "@lib/components/CircularProgress"; +import { Button } from "@lib/components/Button"; import { Checkbox } from "@lib/components/Checkbox"; +import { CircularProgress } from "@lib/components/CircularProgress"; +import { CollapsibleGroup } from "@lib/components/CollapsibleGroup"; import { Label } from "@lib/components/Label"; import { Select, SelectOption } from "@lib/components/Select"; +import { useGetWellHeaders, useGridModelNames, useGridParameterNames } from "./queryHooks"; import state from "./state"; + //----------------------------------------------------------------------------------------------------------- -export function settings({ moduleContext, workbenchSession }: ModuleFCProps) { +export function settings({ moduleContext, workbenchServices, workbenchSession }: ModuleFCProps) { // From Workbench - const firstEnsemble = useFirstEnsembleInEnsembleSet(workbenchSession); + const ensembleSet = useEnsembleSet(workbenchSession); + const [selectedEnsembleIdent, setSelectedEnsembleIdent] = React.useState(null); // State const [gridName, setGridName] = moduleContext.useStoreState("gridName"); const [parameterName, setParameterName] = moduleContext.useStoreState("parameterName"); const [realizations, setRealizations] = moduleContext.useStoreState("realizations"); const [useStatistics, setUseStatistics] = moduleContext.useStoreState("useStatistics"); + const [selectedWellUuids, setSelectedWellUuids] = moduleContext.useStoreState("selectedWellUuids"); + const syncedSettingKeys = moduleContext.useSyncedSettingKeys(); + const syncHelper = new SyncSettingsHelper(syncedSettingKeys, workbenchServices); + const syncedValueEnsembles = syncHelper.useValue(SyncSettingKey.ENSEMBLE, "global.syncValue.ensembles"); + const candidateEnsembleIdent = maybeAssignFirstSyncedEnsemble(selectedEnsembleIdent, syncedValueEnsembles); + const computedEnsembleIdent = fixupEnsembleIdent(candidateEnsembleIdent, ensembleSet); + if (computedEnsembleIdent && !computedEnsembleIdent.equals(selectedEnsembleIdent)) { + setSelectedEnsembleIdent(computedEnsembleIdent); + } // Queries - const firstCaseUuid = firstEnsemble?.getCaseUuid() ?? null; - const firstEnsembleName = firstEnsemble?.getEnsembleName() ?? null; + const firstCaseUuid = computedEnsembleIdent?.getCaseUuid() ?? null; + const firstEnsembleName = computedEnsembleIdent?.getEnsembleName() ?? null; const gridNamesQuery = useGridModelNames(firstCaseUuid, firstEnsembleName); const parameterNamesQuery = useGridParameterNames(firstCaseUuid, firstEnsembleName, gridName); - + const wellHeadersQuery = useGetWellHeaders(computedEnsembleIdent?.getCaseUuid()); // Handle Linked query useEffect(() => { if (parameterNamesQuery.data) { - if (gridName && parameterNamesQuery.data.find(name => name === parameterName)) { + if (gridName && parameterNamesQuery.data.find((name) => name === parameterName)) { // New grid has same parameter } else { // New grid has different parameter. Set to first - setParameterName(parameterNamesQuery.data[0]) + setParameterName(parameterNamesQuery.data[0]); } } - }, [parameterNamesQuery.data, parameterName]) - - // If no grid names, stop here - if (!gridNamesQuery.data) { return (
Select case: upscaled_grids_realistic_no_unc
) } + }, [parameterNamesQuery.data, parameterName]); - const parameterNames = parameterNamesQuery.data ? parameterNamesQuery.data : [] - const allRealizations: string[] = firstEnsemble ? firstEnsemble.getRealizations().map(real => JSON.stringify(real)) : [] + const parameterNames = parameterNamesQuery.data ? parameterNamesQuery.data : []; + const allRealizations = computedEnsembleIdent + ? ensembleSet + .findEnsemble(computedEnsembleIdent) + ?.getRealizations() + .map((real) => JSON.stringify(real)) ?? [] + : []; - return ( -
- } - > - + function handleWellsChange(selectedWellUuids: string[], allWellUuidsOptions: SelectOption[]) { + const newSelectedWellUuids = selectedWellUuids.filter((wellUuid) => + allWellUuidsOptions.some((wellHeader) => wellHeader.value === wellUuid) + ); + setSelectedWellUuids(newSelectedWellUuids); + } + function showAllWells(allWellUuidsOptions: SelectOption[]) { + const newSelectedWellUuids = allWellUuidsOptions.map((wellHeader) => wellHeader.value); -