Skip to content

Commit

Permalink
Replaced ensembleSet with ensembles prop in ensemble selectors
Browse files Browse the repository at this point in the history
  • Loading branch information
rubenthoms committed Dec 6, 2024
1 parent 876065e commit ed5e35c
Show file tree
Hide file tree
Showing 19 changed files with 114 additions and 104 deletions.
Original file line number Diff line number Diff line change
@@ -1,29 +1,31 @@
import React from "react";

import { Ensemble } from "@framework/Ensemble";
import { EnsembleIdent } from "@framework/EnsembleIdent";
import { EnsembleSet } from "@framework/EnsembleSet";
import { ColorTile } from "@lib/components/ColorTile";
import { Dropdown, DropdownOption, DropdownProps } from "@lib/components/Dropdown";

type EnsembleDropdownProps = {
ensembleSet?: EnsembleSet;
ensembles?: Ensemble[];
ensembles: readonly Ensemble[];
value: EnsembleIdent | null;
onChange: (ensembleIdent: EnsembleIdent | null) => void;
} & Omit<DropdownProps<string>, "options" | "value" | "onChange">;

export function EnsembleDropdown(props: EnsembleDropdownProps): JSX.Element {
const { ensembleSet, value, onChange, ...rest } = props;
const ensembleArr = props.ensembles ?? ensembleSet?.getEnsembleArr() ?? [];
const { onChange, value, ...rest } = props;

function handleSelectionChanged(selectedEnsembleIdentStr: string) {
const foundEnsemble = ensembleArr.find(
(ensemble) => ensemble.getIdent().toString() === selectedEnsembleIdentStr
);
onChange(foundEnsemble ? foundEnsemble.getIdent() : null);
}
const handleSelectionChange = React.useCallback(
function handleSelectionChange(selectedEnsembleIdentStr: string) {
const foundEnsemble = props.ensembles.find(
(ensemble) => ensemble.getIdent().toString() === selectedEnsembleIdentStr
);
onChange(foundEnsemble ? foundEnsemble.getIdent() : null);
},
[props.ensembles, onChange]
);

const optionsArr: DropdownOption[] = [];
for (const ens of ensembleArr) {
for (const ens of props.ensembles) {
optionsArr.push({
value: ens.getIdent().toString(),
label: ens.getDisplayName(),
Expand All @@ -35,5 +37,5 @@ export function EnsembleDropdown(props: EnsembleDropdownProps): JSX.Element {
});
}

return <Dropdown options={optionsArr} value={value?.toString()} onChange={handleSelectionChanged} {...rest} />;
return <Dropdown options={optionsArr} value={value?.toString()} onChange={handleSelectionChange} {...rest} />;
}
37 changes: 21 additions & 16 deletions frontend/src/framework/components/EnsembleSelect/ensembleSelect.tsx
Original file line number Diff line number Diff line change
@@ -1,31 +1,36 @@
import React from "react";

import { Ensemble } from "@framework/Ensemble";
import { EnsembleIdent } from "@framework/EnsembleIdent";
import { EnsembleSet } from "@framework/EnsembleSet";
import { ColorTile } from "@lib/components/ColorTile";
import { Select, SelectOption, SelectProps } from "@lib/components/Select";

type EnsembleSelectProps = {
ensembleSet: EnsembleSet;
ensembles: readonly Ensemble[];
value: EnsembleIdent[];
onChange: (ensembleIdentArr: EnsembleIdent[]) => void;
} & Omit<SelectProps<string>, "options" | "value" | "onChange">;

export function EnsembleSelect(props: EnsembleSelectProps): JSX.Element {
const { ensembleSet, value, onChange, multiple, ...rest } = props;

function handleSelectionChanged(selectedEnsembleIdentStrArr: string[]) {
const identArr: EnsembleIdent[] = [];
for (const identStr of selectedEnsembleIdentStrArr) {
const foundEnsemble = ensembleSet.findEnsembleByIdentString(identStr);
if (foundEnsemble) {
identArr.push(foundEnsemble.getIdent());
export function EnsembleSelect(props: EnsembleSelectProps): React.ReactNode {
const { ensembles, value, onChange, multiple, ...rest } = props;

const handleSelectionChange = React.useCallback(
function handleSelectionChanged(selectedEnsembleIdentStrArr: string[]) {
const identArr: EnsembleIdent[] = [];
for (const identStr of selectedEnsembleIdentStrArr) {
const foundEnsemble = ensembles.find((ens) => ens.getIdent().toString() === identStr);
if (foundEnsemble) {
identArr.push(foundEnsemble.getIdent());
}
}
}

onChange(identArr);
}
onChange(identArr);
},
[ensembles, onChange]
);

const optionsArr: SelectOption[] = [];
for (const ens of ensembleSet.getEnsembleArr()) {
for (const ens of ensembles) {
optionsArr.push({
value: ens.getIdent().toString(),
label: ens.getDisplayName(),
Expand All @@ -48,7 +53,7 @@ export function EnsembleSelect(props: EnsembleSelectProps): JSX.Element {
<Select
options={optionsArr}
value={selectedArr}
onChange={handleSelectionChanged}
onChange={handleSelectionChange}
multiple={isMultiple}
{...rest}
/>
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/modules/3DViewer/settings/settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ export function Settings(props: ModuleSettingsProps<Interfaces>): JSX.Element {
<div className="flex flex-col gap-2">
<Label text="Ensemble">
<EnsembleDropdown
ensembleSet={ensembleSet}
ensembles={ensembleSet.getEnsembleArr()}
value={selectedEnsembleIdent}
onChange={handleEnsembleSelectionChange}
showArrows
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/modules/FlowNetwork/settings/settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ export function Settings({ workbenchSession, settingsContext }: ModuleSettingsPr
<div className="flex flex-col gap-2 overflow-y-auto">
<CollapsibleGroup expanded={true} title="Ensemble">
<EnsembleDropdown
ensembleSet={ensembleSet}
ensembles={ensembleSet.getEnsembleArr()}
value={selectedEnsembleIdent}
onChange={handleEnsembleSelectionChange}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ export function GridLayerSettingsComponent(props: GridLayerSettingsComponentProp
<div className="table-cell">
<EnsembleDropdown
value={props.layer.getSettings().ensembleIdent}
ensembleSet={props.ensembleSet}
ensembles={props.ensembleSet.getEnsembleArr()}
onChange={handleEnsembleChange}
debounceTimeMs={600}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ export function SeismicLayerSettingsComponent(props: SeismicLayerSettingsProps):
<div className="table-cell">
<EnsembleDropdown
value={props.layer.getSettings().ensembleIdent}
ensembleSet={props.ensembleSet}
ensembles={props.ensembleSet.getEnsembleArr()}
onChange={handleEnsembleChange}
debounceTimeMs={600}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ export function SurfaceLayerSettingsComponent(props: SurfaceLayerSettingsCompone
<div className="table-cell">
<EnsembleDropdown
value={props.layer.getSettings().ensembleIdent}
ensembleSet={props.ensembleSet}
ensembles={props.ensembleSet.getEnsembleArr()}
onChange={handleEnsembleChange}
debounceTimeMs={600}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ export function SurfacesUncertaintyLayerSettingsComponent(
<div className="table-cell">
<EnsembleDropdown
value={props.layer.getSettings().ensembleIdent}
ensembleSet={props.ensembleSet}
ensembles={props.ensembleSet.getEnsembleArr()}
onChange={handleEnsembleChange}
debounceTimeMs={600}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export function WellpicksLayerSettingsComponent(props: WellpicksLayerSettingsCom
<div className="table-cell">
<EnsembleDropdown
value={props.layer.getSettings().ensembleIdent}
ensembleSet={props.ensembleSet}
ensembles={props.ensembleSet.getEnsembleArr()}
onChange={handleEnsembleChange}
debounceTimeMs={600}
/>
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/modules/Map/settings/settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ export function MapSettings(props: ModuleSettingsProps<Interfaces>) {
labelClassName={syncHelper.isSynced(SyncSettingKey.ENSEMBLE) ? "bg-indigo-700 text-white" : ""}
>
<EnsembleDropdown
ensembleSet={ensembleSet}
ensembles={ensembleSet.getEnsembleArr()}
value={computedEnsembleIdent}
onChange={handleEnsembleSelectionChange}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export function Settings({ workbenchSession }: ModuleSettingsProps<Interfaces>)
</CollapsibleGroup>
<CollapsibleGroup title="Ensembles" expanded>
<EnsembleSelect
ensembleSet={ensembleSet}
ensembles={ensembleSet.getEnsembleArr()}
onChange={handleEnsembleSelectionChange}
value={selectedEnsembleIdents}
size={5}
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/modules/Pvt/settings/settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ export function Settings({ workbenchSession }: ModuleSettingsProps<Interfaces>)
</CollapsibleGroup>
<CollapsibleGroup title="Ensembles" expanded>
<EnsembleSelect
ensembleSet={ensembleSet}
ensembles={ensembleSet.getEnsembleArr()}
onChange={handleEnsembleSelectionChange}
value={selectedEnsembleIdents}
size={5}
Expand Down
4 changes: 1 addition & 3 deletions frontend/src/modules/Rft/settings.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import React from "react";

import { EnsembleIdent } from "@framework/EnsembleIdent";
import { ModuleSettingsProps } from "@framework/Module";
import { useSettingsStatusWriter } from "@framework/StatusWriter";
Expand Down Expand Up @@ -88,7 +86,7 @@ export function Settings({ settingsContext, workbenchSession }: ModuleSettingsPr
<div>
<CollapsibleGroup expanded={true} title="Ensembles">
<EnsembleDropdown
ensembleSet={ensembleSet}
ensembles={ensembleSet.getEnsembleArr()}
value={selectedEnsembleIdent}
onChange={handleEnsembleSelectionChange}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ export function Settings({ settingsContext, workbenchSession }: ModuleSettingsPr
</CollapsibleGroup>
<CollapsibleGroup expanded={true} title="Ensembles">
<EnsembleSelect
ensembleSet={ensembleSet}
ensembles={ensembleSet.getEnsembleArr()}
value={selectedEnsembleIdents}
size={5}
onChange={handleEnsembleSelectChange}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ export function Settings({ settingsContext, workbenchSession, workbenchServices
<>
<CollapsibleGroup expanded={true} title="Ensemble">
<EnsembleDropdown
ensembleSet={ensembleSet}
ensembles={ensembleSet.getEnsembleArr()}
value={computedEnsembleIdent}
onChange={handleEnsembleSelectionChange}
/>
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/modules/SubsurfaceMap/settings/settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,7 @@ export function Settings({ settingsContext, workbenchSession, workbenchServices
<CollapsibleGroup expanded={true} title="Ensemble and realization">
<Label text="Ensemble" synced={syncHelper.isSynced(SyncSettingKey.ENSEMBLE)}>
<EnsembleDropdown
ensembleSet={ensembleSet}
ensembles={ensembleSet.getEnsembleArr()}
value={computedEnsembleIdent ? computedEnsembleIdent : null}
onChange={handleEnsembleSelectionChange}
/>
Expand Down
Loading

0 comments on commit ed5e35c

Please sign in to comment.