diff --git a/frontend/src/modules/TopographicMap/SurfaceAddress.ts b/frontend/src/modules/TopographicMap/SurfaceAddress.ts deleted file mode 100644 index 74685eb8f..000000000 --- a/frontend/src/modules/TopographicMap/SurfaceAddress.ts +++ /dev/null @@ -1,57 +0,0 @@ -import { SurfaceStatisticFunction_api } from "@api"; - -export interface StaticSurfAddr { - addressType: "static"; - caseUuid: string; - ensemble: string; - name: string; - attribute: string; - realizationNum: number; -} - -export interface StatisticalStaticSurfAddr { - addressType: "statistical-static"; - caseUuid: string; - ensemble: string; - name: string; - attribute: string; - statisticFunction: SurfaceStatisticFunction_api; -} - -export type SurfAddr = StaticSurfAddr | StatisticalStaticSurfAddr; - -export class SurfAddrFactory { - private _caseUuid: string; - private _ensemble: string; - private _name: string; - private _attribute: string; - - constructor(caseUuid: string, ensemble: string, name: string, attribute: string) { - this._caseUuid = caseUuid; - this._ensemble = ensemble; - this._name = name; - this._attribute = attribute; - } - - createStaticAddr(realizationNum: number): StaticSurfAddr { - return { - addressType: "static", - caseUuid: this._caseUuid, - ensemble: this._ensemble, - name: this._name, - attribute: this._attribute, - realizationNum: realizationNum, - }; - } - - createStatisticalStaticAddr(statFunction: SurfaceStatisticFunction_api): StatisticalStaticSurfAddr { - return { - addressType: "statistical-static", - caseUuid: this._caseUuid, - ensemble: this._ensemble, - name: this._name, - attribute: this._attribute, - statisticFunction: statFunction, - }; - } -} diff --git a/frontend/src/modules/TopographicMap/queryHooks.tsx b/frontend/src/modules/TopographicMap/queryHooks.tsx index fd58b5050..6767395de 100644 --- a/frontend/src/modules/TopographicMap/queryHooks.tsx +++ b/frontend/src/modules/TopographicMap/queryHooks.tsx @@ -1,35 +1,19 @@ import { PolygonData_api, - StaticSurfaceDirectory_api, - SumoContent_api, SurfaceData_api, SurfacePolygonDirectory_api, WellBoreHeader_api, WellBoreTrajectory_api, } from "@api"; import { apiService } from "@framework/ApiService"; +import { SurfaceAddress } from "@modules/_shared/SurfaceDirectory"; import { QueryFunction, QueryKey, UseQueryResult, useQuery } from "@tanstack/react-query"; -import { SurfAddr } from "./SurfaceAddress"; import { SurfacePolygonsAddress } from "./SurfacePolygonsAddress"; const STALE_TIME = 60 * 1000; const CACHE_TIME = 60 * 1000; -export function useSurfaceDirectoryQuery( - caseUuid: string | undefined, - ensembleName: string | undefined, - contentFilter?: SumoContent_api[] -): UseQueryResult { - return useQuery({ - queryKey: ["getStaticSurfaceDirectory", caseUuid, ensembleName, contentFilter], - queryFn: () => apiService.surface.getStaticSurfaceDirectory(caseUuid ?? "", ensembleName ?? "", contentFilter), - staleTime: STALE_TIME, - cacheTime: STALE_TIME, - enabled: caseUuid && ensembleName ? true : false, - }); -} - export function usePolygonDirectoryQuery( caseUuid: string | undefined, ensembleName: string | undefined @@ -72,80 +56,9 @@ export function useGetFieldWellsTrajectories(caseUuid: string | undefined): UseQ }); } -export function useSurfaceDataQueryByAddress( - surfAddr: SurfAddr | null, - enabled: boolean -): UseQueryResult { - function dummyApiCall(): Promise { - return new Promise((_resolve, reject) => { - reject(null); - }); - } - - if (!surfAddr) { - return useQuery({ - queryKey: ["getSurfaceData_DUMMY_ALWAYS_DISABLED"], - queryFn: () => dummyApiCall, - enabled: false, - }); - } - - let queryFn: QueryFunction | null = null; - let queryKey: QueryKey | null = null; - - // Static, per realization surface - if (surfAddr.addressType === "static") { - queryKey = [ - "getStaticSurfaceData", - surfAddr.caseUuid, - surfAddr.ensemble, - surfAddr.realizationNum, - surfAddr.name, - surfAddr.attribute, - ]; - queryFn = () => - apiService.surface.getStaticSurfaceData( - surfAddr.caseUuid, - surfAddr.ensemble, - surfAddr.realizationNum, - surfAddr.name, - surfAddr.attribute - ); - } - - // Static, statistical surface - else if (surfAddr.addressType === "statistical-static") { - queryKey = [ - "getStatisticalStaticSurfaceData", - surfAddr.caseUuid, - surfAddr.ensemble, - surfAddr.statisticFunction, - surfAddr.name, - surfAddr.attribute, - ]; - queryFn = () => - apiService.surface.getStatisticalStaticSurfaceData( - surfAddr.caseUuid, - surfAddr.ensemble, - surfAddr.statisticFunction, - surfAddr.name, - surfAddr.attribute - ); - } else { - throw new Error("Invalid surface address type"); - } - - return useQuery({ - queryKey: queryKey, - queryFn: queryFn, - staleTime: STALE_TIME, - cacheTime: CACHE_TIME, - enabled: enabled, - }); -} export function usePropertySurfaceDataByQueryAddress( - meshSurfAddr: SurfAddr | null, - propertySurfAddr: SurfAddr | null, + meshSurfAddr: SurfaceAddress | null, + propertySurfAddr: SurfaceAddress | null, enabled: boolean ): UseQueryResult { function dummyApiCall(): Promise { @@ -166,7 +79,7 @@ export function usePropertySurfaceDataByQueryAddress( let queryKey: QueryKey | null = null; // Static, per realization surface - if (meshSurfAddr.addressType === "static" && propertySurfAddr.addressType === "static") { + if (meshSurfAddr.addressType === "realization" && propertySurfAddr.addressType === "realization") { queryKey = [ "getPropertySurfaceResampledToStaticSurface", meshSurfAddr.caseUuid, @@ -189,10 +102,7 @@ export function usePropertySurfaceDataByQueryAddress( propertySurfAddr.name, propertySurfAddr.attribute ); - } else if ( - meshSurfAddr.addressType === "statistical-static" && - propertySurfAddr.addressType === "statistical-static" - ) { + } else if (meshSurfAddr.addressType === "statistical" && propertySurfAddr.addressType === "statistical") { queryKey = [ "getPropertySurfaceResampledToStaticSurface", meshSurfAddr.caseUuid, diff --git a/frontend/src/modules/TopographicMap/settings.tsx b/frontend/src/modules/TopographicMap/settings.tsx index 274d8a7f7..ea98a9b9c 100644 --- a/frontend/src/modules/TopographicMap/settings.tsx +++ b/frontend/src/modules/TopographicMap/settings.tsx @@ -1,7 +1,6 @@ import React from "react"; -import { SurfaceStatisticFunction_api } from "@api"; -import { SumoContent_api } from "@api"; +import { SurfaceAttributeType_api, SurfaceStatisticFunction_api } from "@api"; import { EnsembleIdent } from "@framework/EnsembleIdent"; import { ModuleFCProps } from "@framework/Module"; import { SyncSettingKey, SyncSettingsHelper } from "@framework/SyncSettings"; @@ -16,14 +15,19 @@ import { CollapsibleGroup } from "@lib/components/CollapsibleGroup"; import { Input } from "@lib/components/Input"; import { Label } from "@lib/components/Label"; import { Select, SelectOption } from "@lib/components/Select"; +import { + SurfaceAddress, + SurfaceAddressFactory, + SurfaceDirectory, + TimeType, + useSurfaceDirectoryQuery, +} from "@modules/_shared/SurfaceDirectory"; -import { SurfAddr, SurfAddrFactory } from "./SurfaceAddress"; import { SurfacePolygonsAddress } from "./SurfacePolygonsAddress"; import { AggregationSelector } from "./components/AggregationSelector"; import { PolygonDirectoryProvider } from "./polygonsDirectoryProvider"; -import { useGetWellHeaders, usePolygonDirectoryQuery, useSurfaceDirectoryQuery } from "./queryHooks"; +import { useGetWellHeaders, usePolygonDirectoryQuery } from "./queryHooks"; import { state } from "./state"; -import { SurfaceDirectoryProvider } from "./surfaceDirectoryProvider"; //----------------------------------------------------------------------------------------------------------- type LabelledCheckboxProps = { @@ -74,7 +78,7 @@ export function settings({ moduleContext, workbenchSession, workbenchServices }: const syncedSettingKeys = moduleContext.useSyncedSettingKeys(); const syncHelper = new SyncSettingsHelper(syncedSettingKeys, workbenchServices); const syncedValueEnsembles = syncHelper.useValue(SyncSettingKey.ENSEMBLE, "global.syncValue.ensembles"); - + const syncedValueSurface = syncHelper.useValue(SyncSettingKey.SURFACE, "global.syncValue.surface"); const candidateEnsembleIdent = maybeAssignFirstSyncedEnsemble(selectedEnsembleIdent, syncedValueEnsembles); const computedEnsembleIdent = fixupEnsembleIdent(candidateEnsembleIdent, ensembleSet); if (computedEnsembleIdent && !computedEnsembleIdent.equals(selectedEnsembleIdent)) { @@ -83,15 +87,27 @@ export function settings({ moduleContext, workbenchSession, workbenchServices }: // Mesh surface const meshSurfDirQuery = useSurfaceDirectoryQuery( computedEnsembleIdent?.getCaseUuid(), - computedEnsembleIdent?.getEnsembleName(), - [SumoContent_api.DEPTH] - ); - const meshSurfDirProvider = new SurfaceDirectoryProvider(meshSurfDirQuery, "tops"); - const computedMeshSurfaceName = meshSurfDirProvider.validateOrResetSurfaceName(selectedMeshSurfaceName); - const computedMeshSurfaceAttribute = meshSurfDirProvider.validateOrResetSurfaceAttribute( - computedMeshSurfaceName, - selectedMeshSurfaceAttribute + computedEnsembleIdent?.getEnsembleName() ); + const meshSurfaceDirectory = new SurfaceDirectory({ + surfaceDirectoryQueryData: meshSurfDirQuery.data, + includeAttributeTypes: [SurfaceAttributeType_api.DEPTH], + }); + + let computedMeshSurfaceName: string | null = null; + let computedMeshSurfaceAttribute: string | null = null; + if (meshSurfaceDirectory) { + const computedStaticSurface = fixupStaticSurface( + meshSurfaceDirectory, + { surfaceName: selectedMeshSurfaceName, surfaceAttribute: selectedMeshSurfaceAttribute }, + { + surfaceName: syncedValueSurface?.name || null, + surfaceAttribute: syncedValueSurface?.attribute || null, + } + ); + computedMeshSurfaceName = computedStaticSurface.surfaceName; + computedMeshSurfaceAttribute = computedStaticSurface.surfaceAttribute; + } if (computedMeshSurfaceName && computedMeshSurfaceName !== selectedMeshSurfaceName) { setSelectedMeshSurfaceName(computedMeshSurfaceName); @@ -102,22 +118,39 @@ export function settings({ moduleContext, workbenchSession, workbenchServices }: let meshSurfNameOptions: SelectOption[] = []; let meshSurfAttributeOptions: SelectOption[] = []; - meshSurfNameOptions = meshSurfDirProvider.surfaceNames().map((name) => ({ value: name, label: name })); - meshSurfAttributeOptions = meshSurfDirProvider - .attributesForSurfaceName(computedMeshSurfaceName) + meshSurfNameOptions = meshSurfaceDirectory + .getStratigraphicNames(TimeType.None, null) + .map((name) => ({ value: name, label: name })); + meshSurfAttributeOptions = meshSurfaceDirectory + .getAttributeNames(TimeType.None, computedMeshSurfaceName) .map((attr) => ({ value: attr, label: attr })); // Property surface + // TODO add timestamp and time interval surfaces const propertySurfDirQuery = useSurfaceDirectoryQuery( computedEnsembleIdent?.getCaseUuid(), - computedEnsembleIdent?.getEnsembleName() // Should be SumoContent_api.PROPERTY - ); - const propertySurfDirProvider = new SurfaceDirectoryProvider(propertySurfDirQuery, "formations"); - const computedPropertySurfaceName = propertySurfDirProvider.validateOrResetSurfaceName(selectedPropertySurfaceName); - const computedPropertySurfaceAttribute = propertySurfDirProvider.validateOrResetSurfaceAttribute( - computedPropertySurfaceName, - selectedPropertySurfaceAttribute + computedEnsembleIdent?.getEnsembleName() ); + const propertySurfaceDirectory = new SurfaceDirectory({ + surfaceDirectoryQueryData: propertySurfDirQuery.data, + excludeAttributeTypes: [SurfaceAttributeType_api.DEPTH], + }); + let computedPropertySurfaceName: string | null = null; + let computedPropertySurfaceAttribute: string | null = null; + + if (propertySurfaceDirectory) { + const computedStaticSurface = fixupStaticSurface( + propertySurfaceDirectory, + { surfaceName: selectedPropertySurfaceName, surfaceAttribute: selectedPropertySurfaceAttribute }, + { + surfaceName: null, + surfaceAttribute: null, + } + ); + computedPropertySurfaceName = computedStaticSurface.surfaceName; + computedPropertySurfaceAttribute = computedStaticSurface.surfaceAttribute; + } + if (computedPropertySurfaceName && computedPropertySurfaceName !== selectedPropertySurfaceName) { setSelectedPropertySurfaceName(computedPropertySurfaceName); } @@ -126,9 +159,12 @@ export function settings({ moduleContext, workbenchSession, workbenchServices }: } let propertySurfNameOptions: SelectOption[] = []; let propertySurfAttributeOptions: SelectOption[] = []; - propertySurfNameOptions = propertySurfDirProvider.surfaceNames().map((name) => ({ value: name, label: name })); - propertySurfAttributeOptions = propertySurfDirProvider - .attributesForSurfaceName(computedPropertySurfaceName) + + propertySurfNameOptions = propertySurfaceDirectory + .getStratigraphicNames(TimeType.None, null) + .map((name) => ({ value: name, label: name })); + propertySurfAttributeOptions = propertySurfaceDirectory + .getAttributeNames(TimeType.None, computedPropertySurfaceName) .map((attr) => ({ value: attr, label: attr })); // Polygon @@ -161,20 +197,21 @@ export function settings({ moduleContext, workbenchSession, workbenchServices }: React.useEffect( function propagateMeshSurfaceSelectionToView() { - let surfAddr: SurfAddr | null = null; + let surfAddr: SurfaceAddress | null = null; if (computedEnsembleIdent && computedMeshSurfaceName && computedMeshSurfaceAttribute) { - const addrFactory = new SurfAddrFactory( + const addrFactory = new SurfaceAddressFactory( computedEnsembleIdent.getCaseUuid(), computedEnsembleIdent.getEnsembleName(), computedMeshSurfaceName, - computedMeshSurfaceAttribute + computedMeshSurfaceAttribute, + null ); if (aggregation === null) { - surfAddr = addrFactory.createStaticAddr(realizationNum); + surfAddr = addrFactory.createRealizationAddress(realizationNum); } else { - surfAddr = addrFactory.createStatisticalStaticAddr(aggregation); + surfAddr = addrFactory.createStatisticalAddress(aggregation); } } @@ -185,23 +222,24 @@ export function settings({ moduleContext, workbenchSession, workbenchServices }: ); React.useEffect( function propagatePropertySurfaceSelectionToView() { - let surfAddr: SurfAddr | null = null; + let surfAddr: SurfaceAddress | null = null; if (!usePropertySurface) { moduleContext.getStateStore().setValue("propertySurfaceAddress", surfAddr); return; } if (computedEnsembleIdent && computedPropertySurfaceName && computedPropertySurfaceAttribute) { - const addrFactory = new SurfAddrFactory( + const addrFactory = new SurfaceAddressFactory( computedEnsembleIdent.getCaseUuid(), computedEnsembleIdent.getEnsembleName(), computedPropertySurfaceName, - computedPropertySurfaceAttribute + computedPropertySurfaceAttribute, + null ); if (aggregation === null) { - surfAddr = addrFactory.createStaticAddr(realizationNum); + surfAddr = addrFactory.createRealizationAddress(realizationNum); } else { - surfAddr = addrFactory.createStatisticalStaticAddr(aggregation); + surfAddr = addrFactory.createStatisticalAddress(aggregation); } } @@ -607,3 +645,135 @@ export function settings({ moduleContext, workbenchSession, workbenchServices }: ); } + +function fixupStaticSurface( + surfaceDirectory: SurfaceDirectory, + selectedSurface: { surfaceName: string | null; surfaceAttribute: string | null }, + syncedSurface: { surfaceName: string | null; surfaceAttribute: string | null } +): { surfaceName: string | null; surfaceAttribute: string | null } { + const surfaceNames = surfaceDirectory.getStratigraphicNames(TimeType.None, null); + let finalSurfaceName: string | null = null; + let finalSurfaceAttribute: string | null = null; + finalSurfaceName = fixupSyncedOrSelectedOrFirstValue( + syncedSurface.surfaceName, + selectedSurface.surfaceName, + surfaceNames + ); + + if (finalSurfaceName) { + const surfaceAttributes = surfaceDirectory.getAttributeNames(TimeType.None, finalSurfaceName); + finalSurfaceAttribute = fixupSyncedOrSelectedOrFirstValue( + syncedSurface.surfaceAttribute, + selectedSurface.surfaceAttribute, + surfaceAttributes + ); + } + return { surfaceName: finalSurfaceName, surfaceAttribute: finalSurfaceAttribute }; +} +function fixupTimeStampSurface( + surfaceDirectory: SurfaceDirectory, + selectedSurface: { surfaceName: string | null; surfaceAttribute: string | null; timeStamp: string | null }, + syncedSurface: { surfaceName: string | null; surfaceAttribute: string | null; timeStamp: string | null } +): { surfaceName: string | null; surfaceAttribute: string | null; timeStamp: string | null } { + const surfaceNames = surfaceDirectory.getStratigraphicNames(TimeType.Timestamp, null); + console.log(surfaceNames, "timestamp"); + let finalSurfaceName = fixupSyncedOrSelectedOrFirstValue( + syncedSurface.surfaceName, + selectedSurface.surfaceName, + surfaceNames + ); + let finalSurfaceAttribute: string | null = null; + let finalTimeOrInterval: string | null = null; + if (finalSurfaceName) { + const surfaceAttributes = surfaceDirectory.getAttributeNames(TimeType.Timestamp, finalSurfaceName); + finalSurfaceAttribute = fixupSyncedOrSelectedOrFirstValue( + syncedSurface.surfaceAttribute, + selectedSurface.surfaceAttribute, + surfaceAttributes + ); + } + if (finalSurfaceName && finalSurfaceAttribute) { + const timeStamps = surfaceDirectory.getTimeStamps(finalSurfaceName, finalSurfaceAttribute); + finalTimeOrInterval = fixupSyncedOrSelectedOrFirstValue( + syncedSurface.timeStamp, + selectedSurface.timeStamp, + timeStamps + ); + } + return { surfaceName: finalSurfaceName, surfaceAttribute: finalSurfaceAttribute, timeStamp: finalTimeOrInterval }; +} + +function fixupTimeIntervalSurface( + surfaceDirectory: SurfaceDirectory, + selectedSurface: { + surfaceName: string | null; + surfaceAttribute: string | null; + timeInterval: string | null; + }, + syncedSurface: { surfaceName: string | null; surfaceAttribute: string | null; timeInterval: string | null } +): { surfaceName: string | null; surfaceAttribute: string | null; timeInterval: string | null } { + const surfaceNames = surfaceDirectory.getStratigraphicNames(TimeType.Interval, null); + console.log(surfaceNames, "interval"); + let finalSurfaceName = fixupSyncedOrSelectedOrFirstValue( + syncedSurface.surfaceName, + selectedSurface.surfaceName, + surfaceNames + ); + let finalSurfaceAttribute: string | null = null; + let finalTimeOrInterval: string | null = null; + if (finalSurfaceName) { + const surfaceAttributes = surfaceDirectory.getAttributeNames(TimeType.Interval, finalSurfaceName); + finalSurfaceAttribute = fixupSyncedOrSelectedOrFirstValue( + syncedSurface.surfaceAttribute, + selectedSurface.surfaceAttribute, + surfaceAttributes + ); + } + if (finalSurfaceName && finalSurfaceAttribute) { + const timeIntervals = surfaceDirectory.getTimeIntervals(finalSurfaceName, finalSurfaceAttribute); + finalTimeOrInterval = fixupSyncedOrSelectedOrFirstValue( + syncedSurface.timeInterval, + selectedSurface.timeInterval, + timeIntervals + ); + } + console.log({ + surfaceName: finalSurfaceName, + surfaceAttribute: finalSurfaceAttribute, + timeInterval: finalTimeOrInterval, + }); + return { + surfaceName: finalSurfaceName, + surfaceAttribute: finalSurfaceAttribute, + timeInterval: finalTimeOrInterval, + }; +} + +function fixupSyncedOrSelectedOrFirstValue( + syncedValue: string | null, + selectedValue: string | null, + values: string[] +): string | null { + if (syncedValue && values.includes(syncedValue)) { + return syncedValue; + } + if (selectedValue && values.includes(selectedValue)) { + return selectedValue; + } + if (values.length) { + return values[0]; + } + return null; +} +export function IsoStringToDateLabel(input: string): string { + const date = input.split("T")[0]; + return `${date}`; +} + +export function IsoIntervalStringToDateLabel(input: string): string { + console.log(input); + const [start, end] = input.split("/"); + const startDate = start.split("T")[0]; + const endDate = end.split("T")[0]; + return `${startDate}/${endDate}`; +} diff --git a/frontend/src/modules/TopographicMap/state.ts b/frontend/src/modules/TopographicMap/state.ts index 4ce339bc9..d4c638de7 100644 --- a/frontend/src/modules/TopographicMap/state.ts +++ b/frontend/src/modules/TopographicMap/state.ts @@ -1,10 +1,11 @@ -import { SurfAddr } from "./SurfaceAddress"; +import { SurfaceAddress } from "@modules/_shared/SurfaceDirectory"; + import { SurfacePolygonsAddress } from "./SurfacePolygonsAddress"; import { SurfaceMeshLayerSettings, ViewSettings } from "./_utils/"; export interface state { - meshSurfaceAddress: SurfAddr | null; - propertySurfaceAddress: SurfAddr | null; + meshSurfaceAddress: SurfaceAddress | null; + propertySurfaceAddress: SurfaceAddress | null; polygonsAddress: SurfacePolygonsAddress | null; selectedWellUuids: string[]; surfaceSettings: SurfaceMeshLayerSettings | null; diff --git a/frontend/src/modules/TopographicMap/surfaceDirectoryProvider.ts b/frontend/src/modules/TopographicMap/surfaceDirectoryProvider.ts deleted file mode 100644 index 082983818..000000000 --- a/frontend/src/modules/TopographicMap/surfaceDirectoryProvider.ts +++ /dev/null @@ -1,106 +0,0 @@ -import { StaticSurfaceDirectory_api } from "@api"; -import { UseQueryResult } from "@tanstack/react-query"; - -export class SurfaceDirectoryProvider { - private _availableNames: string[]; - private _availableAttributes: string[]; - private _valid_attributes_for_name: number[][]; - - constructor(surfaceDirectoryQuery: UseQueryResult, badDataHack: "tops" | "formations") { - if (surfaceDirectoryQuery.data) { - const filteredNames: string[] = []; - const filteredValidAttributesForName: number[][] = []; - - // TODO: This is a hack to filter only the tops and bases from the surface directory - if (badDataHack == "tops") { - surfaceDirectoryQuery.data.names.forEach((item, idx) => { - if ( - item.includes("Top") || - item.includes("top") || - item.includes("TOP") || - item.includes("Base") || - item.includes("base") || - item.includes("BASE") - ) { - filteredNames.push(item); - filteredValidAttributesForName.push(surfaceDirectoryQuery.data.valid_attributes_for_name[idx]); - } - }); - } - // TODO: This is a hack to filter only the formations from the surface directory - else { - surfaceDirectoryQuery.data.names.forEach((item, idx) => { - if ( - !item.includes("Top") && - !item.includes("top") && - !item.includes("TOP") && - !item.includes("Base") && - !item.includes("base") && - !item.includes("BASE") - ) { - filteredNames.push(item); - filteredValidAttributesForName.push(surfaceDirectoryQuery.data.valid_attributes_for_name[idx]); - } - }); - } - - this._availableAttributes = surfaceDirectoryQuery.data.attributes; - this._availableNames = filteredNames.length > 0 ? filteredNames : surfaceDirectoryQuery.data.names; - this._valid_attributes_for_name = - filteredValidAttributesForName.length > 0 - ? filteredValidAttributesForName - : surfaceDirectoryQuery.data.valid_attributes_for_name; - } else { - this._availableNames = []; - this._availableAttributes = []; - this._valid_attributes_for_name = []; - } - } - - surfaceNames(): string[] { - return this._availableNames; - } - attributesForSurfaceName(surfName: string | null): string[] { - if (!surfName) { - return []; - } - const idxOfSurfName = this._availableNames.indexOf(surfName); - if (idxOfSurfName == -1) { - return []; - } - - const attrIndices = this._valid_attributes_for_name[idxOfSurfName]; - const attrNames: string[] = []; - for (const idx of attrIndices) { - attrNames.push(this._availableAttributes[idx]); - } - - return attrNames; - } - validateOrResetSurfaceName(surfaceName: string | null): string | null { - if (!this._availableNames) { - return null; - } - - if (surfaceName && this._availableNames.includes(surfaceName)) { - return surfaceName; - } - return this._availableNames[0]; - } - validateOrResetSurfaceAttribute(surfaceName: string | null, surfaceAttribute: string | null): string | null { - if (!surfaceName) { - return null; - } - const validAttrNames = this.attributesForSurfaceName(surfaceName); - - if (validAttrNames.length == 0) { - return null; - } - - if (surfaceAttribute && validAttrNames.includes(surfaceAttribute)) { - return surfaceAttribute; - } - - return validAttrNames[0]; - } -} diff --git a/frontend/src/modules/TopographicMap/view.tsx b/frontend/src/modules/TopographicMap/view.tsx index 9cf185394..23c9c168c 100644 --- a/frontend/src/modules/TopographicMap/view.tsx +++ b/frontend/src/modules/TopographicMap/view.tsx @@ -7,13 +7,13 @@ import { SyncSettingKey, SyncSettingsHelper } from "@framework/SyncSettings"; import { Wellbore } from "@framework/Wellbore"; import { Button } from "@lib/components/Button"; import { CircularProgress } from "@lib/components/CircularProgress"; +import { useSurfaceDataQueryByAddress } from "@modules/_shared/SurfaceDirectory"; import { ViewAnnotation } from "@webviz/subsurface-viewer/dist/components/ViewAnnotation"; import { useGetFieldWellsTrajectories, usePolygonsDataQueryByAddress, usePropertySurfaceDataByQueryAddress, - useSurfaceDataQueryByAddress, } from "././queryHooks"; import { SurfaceMeta, @@ -84,7 +84,7 @@ export function view({ moduleContext, workbenchServices }: ModuleFCProps) const show3D: boolean = viewSettings?.show3d ?? true; - const meshSurfDataQuery = useSurfaceDataQueryByAddress(meshSurfAddr, true); + const meshSurfDataQuery = useSurfaceDataQueryByAddress(meshSurfAddr); const hasMeshSurfData = meshSurfDataQuery?.data ? true : false; const propertySurfDataQuery = usePropertySurfaceDataByQueryAddress(meshSurfAddr, propertySurfAddr, hasMeshSurfData); diff --git a/frontend/src/modules/_shared/SurfaceDirectory/queryHooks.ts b/frontend/src/modules/_shared/SurfaceDirectory/queryHooks.ts index 0fb4ae67b..5e4232d48 100644 --- a/frontend/src/modules/_shared/SurfaceDirectory/queryHooks.ts +++ b/frontend/src/modules/_shared/SurfaceDirectory/queryHooks.ts @@ -56,7 +56,7 @@ export function useSurfaceDataQueryByAddress(surfAddr: SurfaceAddress | null): U surfAddr.realizationNum, surfAddr.name, surfAddr.attribute, - surfAddr.isoDateOrInterval + surfAddr.isoDateOrInterval ?? undefined ); } @@ -78,7 +78,7 @@ export function useSurfaceDataQueryByAddress(surfAddr: SurfaceAddress | null): U surfAddr.statisticFunction, surfAddr.name, surfAddr.attribute, - surfAddr.isoDateOrInterval + surfAddr.isoDateOrInterval ?? undefined ); } else { throw new Error("Invalid surface address type");