Skip to content

Commit

Permalink
Add usage of status writer
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgenherje committed Oct 17, 2023
1 parent 5bb5155 commit 74ca76e
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 48 deletions.
17 changes: 8 additions & 9 deletions frontend/src/modules/Map/MapSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import React from "react";
import { SurfaceStatisticFunction_api } from "@api";
import { EnsembleIdent } from "@framework/EnsembleIdent";
import { ModuleFCProps } from "@framework/Module";
import { useSettingsStatusWriter } from "@framework/StatusWriter";
import { SyncSettingKey, SyncSettingsHelper } from "@framework/SyncSettings";
import { useEnsembleSet } from "@framework/WorkbenchSession";
import { SingleEnsembleSelect } from "@framework/components/SingleEnsembleSelect";
Expand Down Expand Up @@ -32,13 +33,12 @@ const TimeTypeEnumToStringMapping = {
};
//-----------------------------------------------------------------------------------------------------------
export function MapSettings(props: ModuleFCProps<MapState>) {
const myInstanceIdStr = props.moduleContext.getInstanceIdString();
console.debug(`${myInstanceIdStr} -- render MapSettings`);

const ensembleSet = useEnsembleSet(props.workbenchSession);
const [selectedEnsembleIdent, setSelectedEnsembleIdent] = React.useState<EnsembleIdent | null>(null);
const [timeType, setTimeType] = React.useState<TimeType>(TimeType.None);

const statusWriter = useSettingsStatusWriter(props.moduleContext);

const [selectedSurfaceName, setSelectedSurfaceName] = React.useState<string | null>(null);
const [selectedSurfaceAttribute, setSelectedSurfaceAttribute] = React.useState<string | null>(null);
const [realizationNum, setRealizationNum] = React.useState<number>(0);
Expand All @@ -51,18 +51,18 @@ export function MapSettings(props: ModuleFCProps<MapState>) {
const syncedValueSurface = syncHelper.useValue(SyncSettingKey.SURFACE, "global.syncValue.surface");
const syncedValueDate = syncHelper.useValue(SyncSettingKey.DATE, "global.syncValue.date");

const renderCount = React.useRef(0);
React.useEffect(function incrementRenderCount() {
renderCount.current = renderCount.current + 1;
});

const candidateEnsembleIdent = maybeAssignFirstSyncedEnsemble(selectedEnsembleIdent, syncedValueEnsembles);
const computedEnsembleIdent = fixupEnsembleIdent(candidateEnsembleIdent, ensembleSet);
const surfaceDirectoryQuery = useSurfaceDirectoryQuery(
computedEnsembleIdent?.getCaseUuid(),
computedEnsembleIdent?.getEnsembleName()
);

const isError = surfaceDirectoryQuery.isError;
if (isError) {
statusWriter.addError("Error loading surface directory");
}

const surfaceDirectory = new SurfaceDirectory(
surfaceDirectoryQuery.data
? { surfaceMetas: surfaceDirectoryQuery.data, timeType: timeType, useObservedSurfaces: useObserved }
Expand Down Expand Up @@ -286,7 +286,6 @@ export function MapSettings(props: ModuleFCProps<MapState>) {
onAggregationSelectionChange={handleAggregationChanged}
/>
{chooseRealizationElement}
<div>({renderCount.current})</div>
</>
);
}
Expand Down
79 changes: 40 additions & 39 deletions frontend/src/modules/Map/MapView.tsx
Original file line number Diff line number Diff line change
@@ -1,62 +1,63 @@
import React from "react";

import { ModuleFCProps } from "@framework/Module";
import { useViewStatusWriter } from "@framework/StatusWriter";
import { ContentError, ContentInfo } from "@modules/_shared/components/ContentMessage";
import { useSurfaceDataQueryByAddress } from "@modules_shared/Surface";
import SubsurfaceViewer from "@webviz/subsurface-viewer";

import { MapState } from "./MapState";
import { makeSurfaceAddressString } from "@modules_shared/Surface/surfaceAddress";

//-----------------------------------------------------------------------------------------------------------
export function MapView(props: ModuleFCProps<MapState>) {
const surfaceAddress = props.moduleContext.useStoreValue("surfaceAddress");

const renderCount = React.useRef(0);
React.useEffect(function incrementRenderCount() {
renderCount.current = renderCount.current + 1;
});

console.debug(`render MapView start [${surfaceAddress ? makeSurfaceAddressString(surfaceAddress) : "null"}]`);

const statusWriter = useViewStatusWriter(props.moduleContext);
const surfDataQuery = useSurfaceDataQueryByAddress(surfaceAddress);
console.debug(`surfDataQuery.status=${surfDataQuery.status}`);

if (!surfDataQuery.data) {
return <div>No data</div>;
}
const isLoading = surfDataQuery.isFetching;
statusWriter.setLoading(isLoading);

console.debug(`render MapView done [${surfaceAddress ? makeSurfaceAddressString(surfaceAddress) : "null"}]`);
const hasError = surfDataQuery.isError;
if (hasError) {
statusWriter.addError("Error fetching surface data");
}

const surfData = surfDataQuery.data;
return (
<div className="relative w-full h-full flex flex-col">
<SubsurfaceViewer
id="deckgl"
layers={[
{
"@@type": "MapLayer",
id: "mesh-layer",
// Drop conversion as soon as SubsurfaceViewer accepts typed arrays
meshData: Array.from(surfData.valuesFloat32Arr),
frame: {
origin: [surfData.x_ori, surfData.y_ori],
count: [surfData.x_count, surfData.y_count],
increment: [surfData.x_inc, surfData.y_inc],
rotDeg: surfData.rot_deg,
{hasError ? (
<ContentError>Error loading surface data</ContentError>
) : isLoading ? (
<ContentInfo>Is loading surface data</ContentInfo>
) : !surfData ? (
<ContentInfo>No surface data - make valid selection</ContentInfo>
) : (
<SubsurfaceViewer
id="deckgl"
layers={[
{
"@@type": "MapLayer",
id: "mesh-layer",
// Drop conversion as soon as SubsurfaceViewer accepts typed arrays
meshData: Array.from(surfData.valuesFloat32Arr),
frame: {
origin: [surfData.x_ori, surfData.y_ori],
count: [surfData.x_count, surfData.y_count],
increment: [surfData.x_inc, surfData.y_inc],
rotDeg: surfData.rot_deg,
},

contours: [0, 100],
isContoursDepth: true,
gridLines: false,
material: true,
smoothShading: true,
colorMapName: "Physics",
},

contours: [0, 100],
isContoursDepth: true,
gridLines: false,
material: true,
smoothShading: true,
colorMapName: "Physics",
},
]}
/>
<div className="absolute bottom-5 right-5 italic text-pink-400">
{props.moduleContext.getInstanceIdString()}
</div>
]}
/>
)}
</div>
);
}

0 comments on commit 74ca76e

Please sign in to comment.