Skip to content

Commit

Permalink
Fix subsurface map module
Browse files Browse the repository at this point in the history
  • Loading branch information
HansKallekleiv committed Sep 23, 2023
1 parent e7b73bf commit 175d75e
Show file tree
Hide file tree
Showing 7 changed files with 220 additions and 302 deletions.
57 changes: 0 additions & 57 deletions frontend/src/modules/TopographicMap/SurfaceAddress.ts

This file was deleted.

100 changes: 5 additions & 95 deletions frontend/src/modules/TopographicMap/queryHooks.tsx
Original file line number Diff line number Diff line change
@@ -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<StaticSurfaceDirectory_api> {
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
Expand Down Expand Up @@ -72,80 +56,9 @@ export function useGetFieldWellsTrajectories(caseUuid: string | undefined): UseQ
});
}

export function useSurfaceDataQueryByAddress(
surfAddr: SurfAddr | null,
enabled: boolean
): UseQueryResult<SurfaceData_api> {
function dummyApiCall(): Promise<SurfaceData_api> {
return new Promise((_resolve, reject) => {
reject(null);
});
}

if (!surfAddr) {
return useQuery({
queryKey: ["getSurfaceData_DUMMY_ALWAYS_DISABLED"],
queryFn: () => dummyApiCall,
enabled: false,
});
}

let queryFn: QueryFunction<SurfaceData_api> | 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<SurfaceData_api> {
function dummyApiCall(): Promise<SurfaceData_api> {
Expand All @@ -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,
Expand All @@ -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,
Expand Down
Loading

0 comments on commit 175d75e

Please sign in to comment.