Skip to content

Commit

Permalink
Merge branch 'main' into implement-module-state
Browse files Browse the repository at this point in the history
  • Loading branch information
rubenthoms authored Oct 13, 2023
2 parents b56e4b6 + 1fb813b commit 81dece1
Show file tree
Hide file tree
Showing 8 changed files with 70 additions and 29 deletions.
35 changes: 31 additions & 4 deletions frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"@mui/icons-material": "^5.14.9",
"@tanstack/react-query": "^4.24.10",
"@tanstack/react-query-devtools": "^4.24.12",
"@webviz/subsurface-viewer": "^0.0.2-alpha.9",
"@webviz/subsurface-viewer": "^0.3.1",
"@webviz/well-completions-plot": "^0.0.1-alpha.1",
"animate.css": "^4.1.1",
"axios": "^1.3.0",
Expand Down
21 changes: 12 additions & 9 deletions frontend/src/framework/InitialSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,17 +58,20 @@ export class InitialSettings {
isSet(settingName: string, type: keyof InitialSettingsSupportedTypes): boolean {
return this.get(settingName, type) !== undefined;
}
}

applyToStateOnMount(
settingName: string,
type: keyof InitialSettingsSupportedTypes,
stateSetter: (value: any) => void
): void {
React.useEffect(() => {
const setting = this.get(settingName, type);
export function applyInitialSettingsToState(
initialSettings: InitialSettings | undefined,
settingName: string,
type: keyof InitialSettingsSupportedTypes,
stateSetter: (value: any) => void
): void {
React.useEffect(() => {
if (initialSettings) {
const setting = initialSettings.get(settingName, type);
if (setting !== undefined) {
stateSetter(setting);
}
}, []);
}
}
}, [initialSettings]);
}
6 changes: 2 additions & 4 deletions frontend/src/framework/Workbench.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import { WorkbenchSessionPrivate } from "./internal/WorkbenchSessionPrivate";

export enum WorkbenchEvents {
ModuleInstancesChanged = "ModuleInstancesChanged",
FullModuleRerenderRequested = "FullModuleRerenderRequested",
}

export type LayoutElement = {
Expand Down Expand Up @@ -142,9 +141,9 @@ export class Workbench {
this._broadcaster.unregisterAllChannelsForModuleInstance(moduleInstance.getId());
}
this._moduleInstances = [];
this._perModuleRunningInstanceNumber = {};
this._layout = [];
this.notifySubscribers(WorkbenchEvents.FullModuleRerenderRequested);
this._perModuleRunningInstanceNumber = {};
this.notifySubscribers(WorkbenchEvents.ModuleInstancesChanged);
}

makeAndAddModuleInstance(moduleName: string, layout: LayoutElement): ModuleInstance<any> {
Expand Down Expand Up @@ -179,7 +178,6 @@ export class Workbench {

setLayout(layout: LayoutElement[]): void {
this._layout = layout;
this.notifySubscribers(WorkbenchEvents.FullModuleRerenderRequested);

const modifiedLayout = layout.map((el) => {
return { ...el, moduleInstanceId: undefined };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,14 @@ export type ChannelSelectProps = {
export const ChannelSelect: React.FC<ChannelSelectProps> = (props) => {
const { channelKeyCategory, onChange, broadcaster, ...rest } = props;
const [channel, setChannel] = React.useState<string>(props.initialChannel ?? "");
const [prevInitialChannel, setPrevInitialChannel] = React.useState<string | undefined>(props.initialChannel);
const [channels, setChannels] = React.useState<string[]>([]);

if (prevInitialChannel !== props.initialChannel) {
setPrevInitialChannel(props.initialChannel);
setChannel(props.initialChannel ?? "");
}

React.useEffect(() => {
const handleChannelsChanged = (channels: BroadcastChannel[]) => {
setChannels(
Expand All @@ -36,6 +42,7 @@ export const ChannelSelect: React.FC<ChannelSelectProps> = (props) => {

if (channels.length === 0 || !channels.find((el) => el.getName() === channel)) {
setChannel("");

if (onChange) {
onChange("");
}
Expand All @@ -45,7 +52,7 @@ export const ChannelSelect: React.FC<ChannelSelectProps> = (props) => {
const unsubscribeFunc = broadcaster.subscribeToChannelsChanges(handleChannelsChanged);

return unsubscribeFunc;
}, [channelKeyCategory, onChange, broadcaster]);
}, [channelKeyCategory, onChange, broadcaster, channel]);

const handleChannelsChanged = (channel: string) => {
setChannel(channel);
Expand Down
15 changes: 8 additions & 7 deletions frontend/src/modules/DistributionPlot/settings.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React, { ChangeEvent } from "react";

import { BroadcastChannelKeyCategory } from "@framework/Broadcaster";
import { applyInitialSettingsToState } from "@framework/InitialSettings";
import { ModuleFCProps } from "@framework/Module";
import { ChannelSelect } from "@framework/components/ChannelSelect";
import { Dropdown } from "@lib/components/Dropdown";
Expand Down Expand Up @@ -62,13 +63,13 @@ export function settings({ moduleContext, workbenchServices, initialSettings }:
const [orientation, setOrientation] = moduleContext.useStoreState("orientation");
const [crossPlottingType, setCrossPlottingType] = React.useState<BroadcastChannelKeyCategory | null>(null);

initialSettings?.applyToStateOnMount("channelNameX", "string", setChannelNameX);
initialSettings?.applyToStateOnMount("channelNameY", "string", setChannelNameY);
initialSettings?.applyToStateOnMount("channelNameZ", "string", setChannelNameZ);
initialSettings?.applyToStateOnMount("plotType", "string", setPlotType);
initialSettings?.applyToStateOnMount("numBins", "number", setNumBins);
initialSettings?.applyToStateOnMount("orientation", "string", setOrientation);
initialSettings?.applyToStateOnMount("crossPlottingType", "string", setCrossPlottingType);
applyInitialSettingsToState(initialSettings, "channelNameX", "string", setChannelNameX);
applyInitialSettingsToState(initialSettings, "channelNameY", "string", setChannelNameY);
applyInitialSettingsToState(initialSettings, "channelNameZ", "string", setChannelNameZ);
applyInitialSettingsToState(initialSettings, "plotType", "string", setPlotType);
applyInitialSettingsToState(initialSettings, "numBins", "number", setNumBins);
applyInitialSettingsToState(initialSettings, "orientation", "string", setOrientation);
applyInitialSettingsToState(initialSettings, "crossPlottingType", "string", setCrossPlottingType);

const handleChannelXChanged = (channelName: string) => {
setChannelNameX(channelName);
Expand Down
9 changes: 7 additions & 2 deletions frontend/src/modules/TornadoChart/settings.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { BroadcastChannelKeyCategory } from "@framework/Broadcaster";
import { applyInitialSettingsToState } from "@framework/InitialSettings";
import { ModuleFCProps } from "@framework/Module";
import { ChannelSelect } from "@framework/components/ChannelSelect";
import { Label } from "@lib/components/Label";
Expand All @@ -8,13 +9,17 @@ import { State } from "./state";
export function settings({ moduleContext, workbenchServices, initialSettings }: ModuleFCProps<State>) {
const [responseChannelName, setResponseChannelName] = moduleContext.useStoreState("responseChannelName");

initialSettings?.applyToStateOnMount("responseChannelName", "string", setResponseChannelName);
applyInitialSettingsToState(initialSettings, "responseChannelName", "string", setResponseChannelName);

function handleResponseChannelNameChange(channelName: string) {
setResponseChannelName(channelName);
}

return (
<>
<Label text="Data channel" key="data-channel-x-axis">
<ChannelSelect
onChange={setResponseChannelName}
onChange={handleResponseChannelNameChange}
channelKeyCategory={BroadcastChannelKeyCategory.Realization}
initialChannel={responseChannelName || undefined}
broadcaster={workbenchServices.getBroadcaster()}
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/templates/oatTimeSeries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const template: Template = {
syncedSettings: [SyncSettingKey.ENSEMBLE],
},
{
instanceRef: "TorandoChartInstance",
instanceRef: "TornadoChartInstance",
moduleName: "TornadoChart",
layout: {
relHeight: 0.5,
Expand Down

0 comments on commit 81dece1

Please sign in to comment.