Skip to content

Commit

Permalink
Additional bug fixes and removed debug code
Browse files Browse the repository at this point in the history
  • Loading branch information
rubenthoms committed Oct 12, 2023
1 parent 0d4ece5 commit 867a423
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 23 deletions.
2 changes: 1 addition & 1 deletion frontend/src/framework/InitialSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export function applyToStateOnMount(
settingName: string,
type: keyof InitialSettingsSupportedTypes,
stateSetter: (value: any) => void,
initialSettings?: InitialSettings
initialSettings: InitialSettings | undefined
): void {
React.useEffect(() => {
if (initialSettings) {
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
19 changes: 8 additions & 11 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 { applyToStateOnMount } 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,17 +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);
applyToStateOnMount("plotType", "string", setPlotType);
applyToStateOnMount("numBins", "number", setNumBins);
applyToStateOnMount("orientation", "string", setOrientation);
applyToStateOnMount("crossPlottingType", "string", setCrossPlottingType);
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, initialSettings);

const handleChannelXChanged = (channelName: string) => {
setChannelNameX(channelName);
Expand Down
8 changes: 0 additions & 8 deletions frontend/src/modules/SimulationTimeSeries/channelDefs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,4 @@ export const broadcastChannelsDef = {
key: BroadcastChannelKeyCategory.Realization,
value: BroadcastChannelValueType.Numeric,
},
[BroadcastChannelNames.Realization_Value_TEST]: {
key: BroadcastChannelKeyCategory.Realization,
value: BroadcastChannelValueType.Numeric,
},
[BroadcastChannelNames.Time_Value]: {
key: BroadcastChannelKeyCategory.TimestampMs,
value: BroadcastChannelValueType.Numeric,
},
};
10 changes: 8 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 { applyToStateOnMount } 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,18 @@ import { State } from "./state";
export function settings({ moduleContext, workbenchServices, initialSettings }: ModuleFCProps<State>) {
const [responseChannelName, setResponseChannelName] = moduleContext.useStoreState("responseChannelName");

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

function handleResponseChannelNameChange(channelName: string) {
console.debug("handleResponseChannelNameChange", responseChannelName, channelName);
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

0 comments on commit 867a423

Please sign in to comment.