Skip to content

Commit

Permalink
Fixes/adjustments after merge
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgenherje committed Dec 13, 2024
1 parent bbbb19f commit 8169e93
Show file tree
Hide file tree
Showing 19 changed files with 69 additions and 56 deletions.
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
import React from "react";

import { DeltaEnsemble } from "@framework/DeltaEnsemble";
import { DeltaEnsembleIdent } from "@framework/DeltaEnsembleIdent";
import { EnsembleSet } from "@framework/EnsembleSet";
import { RegularEnsemble } from "@framework/RegularEnsemble";
import { RegularEnsembleIdent } from "@framework/RegularEnsembleIdent";
import { ColorTile } from "@lib/components/ColorTile";
import { Dropdown, DropdownOption, DropdownProps } from "@lib/components/Dropdown";

// Overload for EnsembleDropdown with DeltaEnsembleIdent
export type EnsembleDropdownWithDeltaEnsemblesProps = {
ensembleSet: EnsembleSet;
ensembles: readonly (RegularEnsemble | DeltaEnsemble)[];
allowDeltaEnsembles: true;
value: RegularEnsembleIdent | DeltaEnsembleIdent | null;
onChange: (ensembleIdent: RegularEnsembleIdent | DeltaEnsembleIdent | null) => void;
} & Omit<DropdownProps<string>, "options" | "value" | "onChange">;

// Overload for EnsembleDropdown without DeltaEnsembleIdent
export type EnsembleDropdownWithoutDeltaEnsemblesProps = {
ensembleSet: EnsembleSet;
ensembles: readonly RegularEnsemble[];
allowDeltaEnsembles?: false | undefined;
value: RegularEnsembleIdent | null;
onChange: (ensembleIdent: RegularEnsembleIdent | null) => void;
Expand All @@ -26,24 +28,28 @@ export function EnsembleDropdown(props: EnsembleDropdownWithoutDeltaEnsemblesPro
export function EnsembleDropdown(
props: EnsembleDropdownWithDeltaEnsemblesProps | EnsembleDropdownWithoutDeltaEnsemblesProps
): JSX.Element {
const { ensembleSet, allowDeltaEnsembles, value, onChange, ...rest } = props;
const { onChange, ensembles, allowDeltaEnsembles, value, ...rest } = props;

function handleSelectionChanged(selectedEnsembleIdentStr: string) {
const foundEnsemble = ensembleSet.findEnsembleByIdentString(selectedEnsembleIdentStr);
if (foundEnsemble && allowDeltaEnsembles) {
const handleSelectionChange = React.useCallback(
function handleSelectionChange(selectedEnsembleIdentStr: string) {
const foundEnsemble = ensembles.find(
(ensemble) => ensemble.getIdent().toString() === selectedEnsembleIdentStr
);
if (foundEnsemble && allowDeltaEnsembles) {
onChange(foundEnsemble.getIdent());
return;
}
if (!foundEnsemble || foundEnsemble instanceof DeltaEnsemble) {
onChange(null);
return;
}
onChange(foundEnsemble.getIdent());
return;
}
if (!foundEnsemble || foundEnsemble instanceof DeltaEnsemble) {
onChange(null);
return;
}
onChange(foundEnsemble.getIdent());
}
},
[allowDeltaEnsembles, ensembles, onChange]
);

const optionsArray: DropdownOption[] = [];
const ensembleArray = allowDeltaEnsembles ? ensembleSet.getEnsembleArray() : ensembleSet.getRegularEnsembleArray();
for (const ens of ensembleArray) {
for (const ens of ensembles) {
optionsArray.push({
value: ens.getIdent().toString(),
label: ens.getDisplayName(),
Expand All @@ -55,5 +61,5 @@ export function EnsembleDropdown(
});
}

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

import { DeltaEnsemble } from "@framework/DeltaEnsemble";
import { DeltaEnsembleIdent } from "@framework/DeltaEnsembleIdent";
import { EnsembleSet } from "@framework/EnsembleSet";
import { RegularEnsemble } from "@framework/RegularEnsemble";
import { RegularEnsembleIdent } from "@framework/RegularEnsembleIdent";
import { isEnsembleIdentOfType } from "@framework/utils/ensembleIdentUtils";
Expand All @@ -8,7 +10,7 @@ import { Select, SelectOption, SelectProps } from "@lib/components/Select";

// Overload for EnsembleSelect with DeltaEnsembleIdent
export type EnsembleSelectWithDeltaEnsemblesProps = {
ensembleSet: EnsembleSet;
ensembles: readonly (RegularEnsemble | DeltaEnsemble)[];
multiple?: boolean;
allowDeltaEnsembles: true;
value: (RegularEnsembleIdent | DeltaEnsembleIdent)[];
Expand All @@ -17,7 +19,7 @@ export type EnsembleSelectWithDeltaEnsemblesProps = {

// Overload for EnsembleSelect without DeltaEnsembleIdent
export type EnsembleSelectWithoutDeltaEnsemblesProps = {
ensembleSet: EnsembleSet;
ensembles: readonly RegularEnsemble[];
multiple?: boolean;
allowDeltaEnsembles?: false | undefined;
value: RegularEnsembleIdent[];
Expand All @@ -29,28 +31,33 @@ export function EnsembleSelect(props: EnsembleSelectWithoutDeltaEnsemblesProps):
export function EnsembleSelect(
props: EnsembleSelectWithDeltaEnsemblesProps | EnsembleSelectWithoutDeltaEnsemblesProps
): JSX.Element {
const { ensembleSet, value, allowDeltaEnsembles, onChange, multiple, ...rest } = props;
const { onChange, ensembles, value, allowDeltaEnsembles, multiple, ...rest } = props;

function handleSelectionChanged(selectedEnsembleIdentStrArray: string[]) {
const identArray: (RegularEnsembleIdent | DeltaEnsembleIdent)[] = [];
for (const identStr of selectedEnsembleIdentStrArray) {
const foundEnsemble = ensembleSet.findEnsembleByIdentString(identStr);
if (foundEnsemble && (allowDeltaEnsembles || foundEnsemble instanceof RegularEnsemble)) {
identArray.push(foundEnsemble.getIdent());
const handleSelectionChange = React.useCallback(
function handleSelectionChanged(selectedEnsembleIdentStringArray: string[]) {
const identArray: (RegularEnsembleIdent | DeltaEnsembleIdent)[] = [];
for (const identStr of selectedEnsembleIdentStringArray) {
const foundEnsemble = ensembles.find((ens) => ens.getIdent().toString() === identStr);
if (foundEnsemble && (allowDeltaEnsembles || foundEnsemble instanceof RegularEnsemble)) {
identArray.push(foundEnsemble.getIdent());
}
}

// Filter to match the correct return type before calling onChange
if (!allowDeltaEnsembles) {
const validIdentArray = identArray.filter((ident) => isEnsembleIdentOfType(ident, RegularEnsembleIdent));
onChange(validIdentArray);
return;
}
onChange(identArray);
}
// Filter to match the correct return type before calling onChange
if (!allowDeltaEnsembles) {
const validIdentArray = identArray.filter((ident) =>
isEnsembleIdentOfType(ident, RegularEnsembleIdent)
) as RegularEnsembleIdent[];
onChange(validIdentArray);
return;
}
onChange(identArray);
},
[allowDeltaEnsembles, ensembles, onChange]
);

const optionsArray: SelectOption[] = [];
const ensembleArray = allowDeltaEnsembles ? ensembleSet.getEnsembleArray() : ensembleSet.getRegularEnsembleArray();
for (const ens of ensembleArray) {
for (const ens of ensembles) {
optionsArray.push({
value: ens.getIdent().toString(),
label: ens.getDisplayName(),
Expand All @@ -73,7 +80,7 @@ export function EnsembleSelect(
<Select
options={optionsArray}
value={selectedArray}
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
ensembles={ensembleSet.getEnsembleArr()}
ensembles={ensembleSet.getRegularEnsembleArray()}
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
ensembles={ensembleSet.getEnsembleArr()}
ensembles={ensembleSet.getRegularEnsembleArray()}
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}
ensembles={props.ensembleSet.getEnsembleArr()}
ensembles={props.ensembleSet.getRegularEnsembleArray()}
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}
ensembles={props.ensembleSet.getEnsembleArr()}
ensembles={props.ensembleSet.getRegularEnsembleArray()}
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}
ensembles={props.ensembleSet.getEnsembleArr()}
ensembles={props.ensembleSet.getRegularEnsembleArray()}
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}
ensembles={props.ensembleSet.getEnsembleArr()}
ensembles={props.ensembleSet.getRegularEnsembleArray()}
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}
ensembles={props.ensembleSet.getEnsembleArr()}
ensembles={props.ensembleSet.getRegularEnsembleArray()}
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
ensembles={ensembleSet.getEnsembleArr()}
ensembles={ensembleSet.getRegularEnsembleArray()}
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
ensembles={ensembleSet.getEnsembleArr()}
ensembles={ensembleSet.getRegularEnsembleArray()}
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
ensembles={ensembleSet.getEnsembleArr()}
ensembles={ensembleSet.getRegularEnsembleArray()}
onChange={handleEnsembleSelectionChange}
value={selectedEnsembleIdents}
size={5}
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/modules/Rft/settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export function Settings({ settingsContext, workbenchSession }: ModuleSettingsPr
<div>
<CollapsibleGroup expanded={true} title="Ensembles">
<EnsembleDropdown
ensembles={ensembleSet.getEnsembleArr()}
ensembles={ensembleSet.getRegularEnsembleArray()}
value={selectedEnsembleIdent}
onChange={handleEnsembleSelectionChange}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ export function Settings({ settingsContext, workbenchSession }: ModuleSettingsPr
</CollapsibleGroup>
<CollapsibleGroup expanded={true} title="Ensembles">
<EnsembleSelect
ensembles={ensembleSet.getEnsembleArr()}
ensembles={ensembleSet.getEnsembleArray()}
value={selectedEnsembleIdents}
allowDeltaEnsembles={true}
size={5}
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
ensembles={ensembleSet.getEnsembleArr()}
ensembles={ensembleSet.getRegularEnsembleArray()}
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
ensembles={ensembleSet.getEnsembleArr()}
ensembles={ensembleSet.getRegularEnsembleArray()}
value={computedEnsembleIdent ? computedEnsembleIdent : null}
onChange={handleEnsembleSelectionChange}
/>
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/modules/Vfp/settings/settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ export function Settings({ workbenchSession, settingsContext }: ModuleSettingsPr
<div className="flex flex-col gap-2">
<CollapsibleGroup expanded={true} title="Ensemble">
<EnsembleDropdown
ensembles={ensembleSet.getEnsembleArr()}
ensembles={ensembleSet.getRegularEnsembleArray()}
value={selectedEnsembleIdent}
onChange={handleEnsembleSelectionChange}
/>
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/modules/WellCompletions/settings/settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ export const Settings = ({
<div className="flex flex-col gap-2 overflow-y-auto">
<CollapsibleGroup expanded={true} title="Ensemble">
<EnsembleDropdown
ensembles={ensembleSet.getEnsembleArr()}
ensembles={ensembleSet.getRegularEnsembleArray()}
value={selectedEnsembleIdent}
onChange={handleEnsembleSelectionChange}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ export function InplaceVolumetricsFilterComponent(props: InplaceVolumetricsFilte
<>
<CollapsibleGroup title="Ensembles" expanded>
<EnsembleSelect
ensembles={props.ensembleSet.getEnsembleArr()}
ensembles={props.ensembleSet.getRegularEnsembleArray()}
value={ensembleIdents}
onChange={handleEnsembleIdentsChange}
size={5}
Expand Down

0 comments on commit 8169e93

Please sign in to comment.