Skip to content

Commit

Permalink
Further adjustments/implementations
Browse files Browse the repository at this point in the history
  • Loading branch information
rubenthoms committed Dec 1, 2023
1 parent 3e8434f commit a24acfb
Show file tree
Hide file tree
Showing 30 changed files with 125 additions and 83 deletions.
26 changes: 20 additions & 6 deletions frontend/src/framework/ModuleContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
GenreType,
SubscriberDefinitions,
Type,
TypeToTSTypeMapping,
} from "./DataChannelTypes";
import { InitialSettings } from "./InitialSettings";
import { ModuleInstance } from "./ModuleInstance";
Expand Down Expand Up @@ -102,20 +103,33 @@ export class ModuleContext<
channelIdent: TIdent;
dependencies: any[];
contents: ContentDefinition[];
dataGenerator: (contentIdent: string) => TChannelDefs[TIdent]["metaData"] extends undefined
? Data<GenreType[TChannelDefs[TIdent]["genre"]], TChannelDefs[TIdent]["dataType"]>[]
: {
dataGenerator: (contentIdent: string) => TChannelDefs[TIdent] extends { metaData: Record<string, Type> }
? {
data: Data<GenreType[TChannelDefs[TIdent]["genre"]], TChannelDefs[TIdent]["dataType"]>[];
metaData: TChannelDefs[TIdent]["metaData"];
};
metaData: {
[K in keyof TChannelDefs[TIdent]["metaData"]]: TypeToTSTypeMapping[TChannelDefs[TIdent]["metaData"][K]];
};
}
: Data<GenreType[TChannelDefs[TIdent]["genre"]], TChannelDefs[TIdent]["dataType"]>[];
}) {
const { channelIdent, ...rest } = options;
const channel = this._moduleInstance.getPublishSubscribeBroker().getChannel(options.channelIdent);
if (!channel) {
throw new Error(`Channel '${options.channelIdent}' does not exist`);
}
return usePublish({
channel,
...options,
...rest,
});
}
}

const l = {} as const;

type n = typeof l;

type m = n extends { metaData: Record<string, Type> }
? {
[K in keyof n["metaData"]]: TypeToTSTypeMapping[n["metaData"][K]];
}
: never;
24 changes: 16 additions & 8 deletions frontend/src/framework/internal/DataChannels/Channel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,22 @@ import { PublishSubscribeBroker } from "./PublishSubscribeBroker";

import { Data, Genre, GenreType, Type } from "../../DataChannelTypes";

export interface ChannelDefinitions {
[ident: string]: {
name: string;
genre: Genre;
dataType: Type;
metaData?: Record<string, Type>;
};
}
export type ChannelDefinitions =
| {
[ident: string]: {
name: string;
genre: Genre;
dataType: Type;
};
}
| {
[ident: string]: {
name: string;
genre: Genre;
dataType: Type;
metaData: Record<string, Type>;
};
};

export enum ChannelTopic {
ContentsChange = "contents-change",
Expand Down
2 changes: 0 additions & 2 deletions frontend/src/framework/internal/DataChannels/Content.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { Data } from "../../DataChannelTypes";

export interface ContentDefinition {
ident: string;
name: string;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Channel, ChannelDefinitions } from "./Channel";
import { Subscriber, SubscriberDefinitions } from "./Subscriber";

import { Genre } from "../../DataChannelTypes";
import { Genre, Type } from "../../DataChannelTypes";

export enum BroadcastServiceTopic {
ChannelsChange = "channels-change",
Expand All @@ -26,7 +26,11 @@ export class PublishSubscribeBroker<

getChannel<T extends Extract<keyof TChannelDefs, string>>(
ident: T
): Channel<TChannelDefs[T]["genre"], TChannelDefs[T]["dataType"], TChannelDefs[T]["metaData"]> | null {
): Channel<
TChannelDefs[T]["genre"],
TChannelDefs[T]["dataType"],
TChannelDefs[T] extends { metaData: Record<string, Type> } ? TChannelDefs[T]["metaData"] : never
> | null {
return this._channels.find((c) => c.getIdent() === ident) ?? null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { ContentDefinition } from "../Content";
export function usePublish<
TGenre extends Genre,
TContentType extends Type,
TMetaData extends Record<string, Type> | undefined
TMetaData extends Record<string, Type>
>(options: {
channel: Channel<TGenre, TContentType, TMetaData>;
dependencies: any[];
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/modules/DistributionPlot/loadModule.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { ModuleRegistry } from "@framework/ModuleRegistry";

import { settings } from "./settings";
import { PlotType, State } from "./state";
import { subscriberDefs } from "./subscriberDefs";
import { SubscriberDefs } from "./subscriberDefs";
import { view } from "./view";

const defaultState: State = {
Expand All @@ -11,7 +11,7 @@ const defaultState: State = {
orientation: "h",
};

const module = ModuleRegistry.initModule<State, never, typeof subscriberDefs>("DistributionPlot", defaultState);
const module = ModuleRegistry.initModule<State, never, SubscriberDefs>("DistributionPlot", defaultState);

module.viewFC = view;
module.settingsFC = settings;
4 changes: 2 additions & 2 deletions frontend/src/modules/DistributionPlot/settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { RadioGroup } from "@lib/components/RadioGroup";
import { Slider } from "@lib/components/Slider";

import { PlotType, State } from "./state";
import { subscriberDefs } from "./subscriberDefs";
import { SubscriberDefs } from "./subscriberDefs";

const plotTypes = [
{
Expand All @@ -34,7 +34,7 @@ export function settings({
moduleContext,
workbenchServices,
initialSettings,
}: ModuleFCProps<State, never, typeof subscriberDefs>) {
}: ModuleFCProps<State, never, SubscriberDefs>) {
const [prevChannelXName, setPrevChannelXName] = React.useState<string | null>(null);
const [prevChannelYName, setPrevChannelYName] = React.useState<string | null>(null);
const [prevChannelColorName, setPrevChannelColorName] = React.useState<string | null>(null);
Expand Down
4 changes: 3 additions & 1 deletion frontend/src/modules/DistributionPlot/subscriberDefs.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Genre, SubscriberDefinitions } from "@framework/DataChannelTypes";
import { Genre } from "@framework/DataChannelTypes";

export const subscriberDefs = {
["channelX"]: {
Expand Down Expand Up @@ -26,3 +26,5 @@ export const subscriberDefs = {
supportedGenres: [Genre.Realization],
},
} as const;

export type SubscriberDefs = typeof subscriberDefs;
4 changes: 2 additions & 2 deletions frontend/src/modules/DistributionPlot/view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { Histogram } from "./components/histogram";
import { ScatterPlot } from "./components/scatterPlot";
import { ScatterPlotWithColorMapping } from "./components/scatterPlotWithColorMapping";
import { PlotType, State } from "./state";
import { subscriberDefs } from "./subscriberDefs";
import { SubscriberDefs } from "./subscriberDefs";

function nFormatter(num: number, digits: number): string {
const lookup = [
Expand Down Expand Up @@ -225,7 +225,7 @@ export const view = ({
workbenchServices,
initialSettings,
workbenchSettings,
}: ModuleFCProps<State, never, typeof subscriberDefs>) => {
}: ModuleFCProps<State, never, SubscriberDefs>) => {
const [plotType, setPlotType] = moduleContext.useStoreState("plotType");
const numBins = moduleContext.useStoreValue("numBins");
const orientation = moduleContext.useStoreValue("orientation");
Expand Down
4 changes: 3 additions & 1 deletion frontend/src/modules/InplaceVolumetrics/channelDefs.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ChannelDefinitions, Genre, Type } from "@framework/DataChannelTypes";
import { Genre, Type } from "@framework/DataChannelTypes";

export enum BroadcastChannelNames {
Response = "Response (per realization)",
Expand All @@ -12,3 +12,5 @@ export const channelDefs = {
metaData: undefined,
},
} as const;

export type ChannelDefs = typeof channelDefs;
4 changes: 2 additions & 2 deletions frontend/src/modules/InplaceVolumetrics/loadModule.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ModuleRegistry } from "@framework/ModuleRegistry";

import { channelDefs } from "./channelDefs";
import { ChannelDefs } from "./channelDefs";
import { settings } from "./settings";
import { State } from "./state";
import { view } from "./view";
Expand All @@ -14,7 +14,7 @@ const defaultState: State = {
realizationsToInclude: null,
};

const module = ModuleRegistry.initModule<State, typeof channelDefs>("InplaceVolumetrics", defaultState);
const module = ModuleRegistry.initModule<State, ChannelDefs>("InplaceVolumetrics", defaultState);

module.viewFC = view;
module.settingsFC = settings;
4 changes: 2 additions & 2 deletions frontend/src/modules/InplaceVolumetrics/settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { Label } from "@lib/components/Label";
import { Select } from "@lib/components/Select";
import { UseQueryResult } from "@tanstack/react-query";

import { channelDefs } from "./channelDefs";
import { ChannelDefs } from "./channelDefs";
import { useTableDescriptionsQuery } from "./queryHooks";
import { State } from "./state";

Expand Down Expand Up @@ -97,7 +97,7 @@ function getTableResponseOptions(
return responsesToSelectOptions(responses);
}

export function settings({ moduleContext, workbenchSession }: ModuleFCProps<State, typeof channelDefs>) {
export function settings({ moduleContext, workbenchSession }: ModuleFCProps<State, ChannelDefs>) {
const ensembleSet = useEnsembleSet(workbenchSession);
const [ensembleIdent, setEnsembleIdent] = moduleContext.useStoreState("ensembleIdent");
const [tableName, setTableName] = moduleContext.useStoreState("tableName");
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/modules/InplaceVolumetrics/view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ import { useElementSize } from "@lib/hooks/useElementSize";

import { Layout, PlotData, PlotHoverEvent } from "plotly.js";

import { BroadcastChannelNames, channelDefs } from "./channelDefs";
import { BroadcastChannelNames, ChannelDefs } from "./channelDefs";
import { useRealizationsResponseQuery } from "./queryHooks";
import { VolumetricResponseAbbreviations } from "./settings";
import { State } from "./state";

export const view = (props: ModuleFCProps<State, typeof channelDefs>) => {
export const view = (props: ModuleFCProps<State, ChannelDefs>) => {
const wrapperDivRef = React.useRef<HTMLDivElement>(null);
const wrapperDivSize = useElementSize(wrapperDivRef);
const ensembleIdent = props.moduleContext.useStoreValue("ensembleIdent");
Expand Down
7 changes: 5 additions & 2 deletions frontend/src/modules/InplaceVolumetricsNew/channelDefs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@ export enum Channels {
ResponseValuePerRealization = "Response value (per realization)",
}

export const channels: ChannelDefinitions = {
export const channelDefs = {
[Channels.ResponseValuePerRealization]: {
name: "Response value (per realization)",
genre: Genre.Realization,
dataType: Type.Number,
metaData: {},
},
};
} as const;

export type ChannelDefs = typeof channelDefs;
3 changes: 2 additions & 1 deletion frontend/src/modules/InplaceVolumetricsNew/loadModule.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { ModuleRegistry } from "@framework/ModuleRegistry";

import { ChannelDefs } from "./channelDefs";
import { settings } from "./settings";
import { State } from "./state";
import { view } from "./view";
Expand All @@ -11,7 +12,7 @@ const defaultState: State = {
selectedCategoricalMetadata: [],
};

const module = ModuleRegistry.initModule<State>("InplaceVolumetricsNew", defaultState);
const module = ModuleRegistry.initModule<State, ChannelDefs>("InplaceVolumetricsNew", defaultState);

module.viewFC = view;
module.settingsFC = settings;
4 changes: 2 additions & 2 deletions frontend/src/modules/InplaceVolumetricsNew/registerModule.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { ModuleRegistry } from "@framework/ModuleRegistry";

import { channels } from "./channelDefs";
import { channelDefs } from "./channelDefs";
import { State } from "./state";

ModuleRegistry.registerModule<State>({
moduleName: "InplaceVolumetricsNew",
defaultTitle: "Inplace Volumetrics (new)",
description: "A module for comparing and investigating responses.",
channels: channels,
channels: channelDefs,
});
3 changes: 2 additions & 1 deletion frontend/src/modules/InplaceVolumetricsNew/settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { Label } from "@lib/components/Label";
import { LoadingStateWrapper } from "@lib/components/StateWrapper/stateWrapper";
import { FilterAlt } from "@mui/icons-material";

import { ChannelDefs } from "./channelDefs";
import FilterSelect from "./components/filterSelect";
import { useTableNameAndMetadataFilterOptions } from "./hooks/useTableNameAndMetadataFilterOptions";
import { useTableNamesAndMetadata } from "./hooks/useTableNamesAndMetadata";
Expand All @@ -32,7 +33,7 @@ function findValidRealizations(ensembleIdents: EnsembleIdent[], ensembleSet: Ens
return validRealizations;
}

export const settings = ({ workbenchSession, moduleContext }: ModuleFCProps<State>) => {
export const settings = ({ workbenchSession, moduleContext }: ModuleFCProps<State, ChannelDefs>) => {
const [selectedEnsembleIdents, setSelectedEnsembleIdents] = moduleContext.useStoreState("selectedEnsembleIdents");
const [selectedResponseNames, setSelectedResponseNames] = moduleContext.useStoreState("selectedResponseNames");
const [selectedTableNames, setSelectedTableNames] = moduleContext.useStoreState("selectedTableNames");
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/modules/InplaceVolumetricsNew/view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ import { TableHeading } from "@lib/components/Table/table";
import { useElementSize } from "@lib/hooks/useElementSize";
import { ContentInfo } from "@modules/_shared/components/ContentMessage";

import { Channels } from "./channelDefs";
import { ChannelDefs, Channels } from "./channelDefs";
import { useRealizationsResponses } from "./hooks/useRealizationResponses";
import { State } from "./state";

export const view = (props: ModuleFCProps<State>) => {
export const view = (props: ModuleFCProps<State, ChannelDefs>) => {
const responseNames = props.moduleContext.useStoreValue("selectedResponseNames");
const tableNames = props.moduleContext.useStoreValue("selectedTableNames");
const ensembleIdents = props.moduleContext.useStoreValue("selectedEnsembleIdents");
Expand Down
13 changes: 7 additions & 6 deletions frontend/src/modules/Map/channelDefs.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import { ChannelDefinition, DataType, Genre } from "@framework/DataChannelTypes";
import { Genre, Type } from "@framework/DataChannelTypes";

export enum Channels {
GridIJK = "Grid IJK",
}

export const channels: ChannelDefinition[] = [
{
ident: Channels.GridIJK,
export const channelDefs = {
[Channels.GridIJK]: {
name: "Grid IJK",
genre: Genre.GridIJK,
dataType: DataType.Numeric,
dataType: Type.Number,
},
];
} as const;

export type ChannelDefs = typeof channelDefs;
4 changes: 2 additions & 2 deletions frontend/src/modules/Map/registerModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ import { ModuleRegistry } from "@framework/ModuleRegistry";
import { SyncSettingKey } from "@framework/SyncSettings";

import { MapState } from "./MapState";
import { channels } from "./channelDefs";
import { channelDefs } from "./channelDefs";
import { preview } from "./preview";

ModuleRegistry.registerModule<MapState>({
moduleName: "Map",
defaultTitle: "Map",
syncableSettingKeys: [SyncSettingKey.ENSEMBLE, SyncSettingKey.SURFACE, SyncSettingKey.DATE],
preview,
channels: channels,
channels: channelDefs,
});
14 changes: 8 additions & 6 deletions frontend/src/modules/SimulationTimeSeries/channelDefs.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import { ChannelDefinition, DataType, Genre } from "@framework/DataChannelTypes";
import { ChannelDefinitions, Genre, Type } from "@framework/DataChannelTypes";

export enum BroadcastChannelNames {
Realization_Value = "Value (per realization)",
}

export const channelDefs: ChannelDefinition[] = [
{
ident: BroadcastChannelNames.Realization_Value,
export const channelDefs = {
[BroadcastChannelNames.Realization_Value]: {
name: "Value (per realization)",
genre: Genre.Realization,
dataType: DataType.Numeric,
dataType: Type.Number,
metaData: undefined,
},
];
} as const;

export type ChannelDefs = typeof channelDefs;
3 changes: 2 additions & 1 deletion frontend/src/modules/SimulationTimeSeries/loadModule.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Frequency_api } from "@api";
import { ModuleRegistry } from "@framework/ModuleRegistry";

import { ChannelDefs } from "./channelDefs";
import { settings } from "./settings";
import { State } from "./state";
import { view } from "./view";
Expand All @@ -14,7 +15,7 @@ const defaultState: State = {
realizationsToInclude: null,
};

const module = ModuleRegistry.initModule<State>("SimulationTimeSeries", defaultState);
const module = ModuleRegistry.initModule<State, ChannelDefs>("SimulationTimeSeries", defaultState);

module.viewFC = view;
module.settingsFC = settings;
Loading

0 comments on commit a24acfb

Please sign in to comment.