From 8169e93c724c9bcb95dc57b9aabdbc5e1c86102a Mon Sep 17 00:00:00 2001 From: jorgenherje Date: Fri, 13 Dec 2024 15:17:13 +0100 Subject: [PATCH] Fixes/adjustments after merge --- .../EnsembleDropdown/ensembleDropdown.tsx | 42 +++++++++------- .../EnsembleSelect/ensembleSelect.tsx | 49 +++++++++++-------- .../modules/3DViewer/settings/settings.tsx | 2 +- .../modules/FlowNetwork/settings/settings.tsx | 2 +- .../components/layerSettings/gridLayer.tsx | 2 +- .../components/layerSettings/seismicLayer.tsx | 2 +- .../components/layerSettings/surfaceLayer.tsx | 2 +- .../surfacesUncertaintyLayer.tsx | 2 +- .../layerSettings/wellpicksLayer.tsx | 2 +- .../src/modules/Map/settings/settings.tsx | 2 +- .../settings/settings.tsx | 2 +- .../src/modules/Pvt/settings/settings.tsx | 2 +- frontend/src/modules/Rft/settings.tsx | 2 +- .../settings/settings.tsx | 2 +- .../settings/settings.tsx | 2 +- .../SubsurfaceMap/settings/settings.tsx | 2 +- .../src/modules/Vfp/settings/settings.tsx | 2 +- .../WellCompletions/settings/settings.tsx | 2 +- .../inplaceVolumetricsFilterComponent.tsx | 2 +- 19 files changed, 69 insertions(+), 56 deletions(-) diff --git a/frontend/src/framework/components/EnsembleDropdown/ensembleDropdown.tsx b/frontend/src/framework/components/EnsembleDropdown/ensembleDropdown.tsx index 40f4d3895..86ffd582e 100644 --- a/frontend/src/framework/components/EnsembleDropdown/ensembleDropdown.tsx +++ b/frontend/src/framework/components/EnsembleDropdown/ensembleDropdown.tsx @@ -1,13 +1,15 @@ +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; @@ -15,7 +17,7 @@ export type EnsembleDropdownWithDeltaEnsemblesProps = { // Overload for EnsembleDropdown without DeltaEnsembleIdent export type EnsembleDropdownWithoutDeltaEnsemblesProps = { - ensembleSet: EnsembleSet; + ensembles: readonly RegularEnsemble[]; allowDeltaEnsembles?: false | undefined; value: RegularEnsembleIdent | null; onChange: (ensembleIdent: RegularEnsembleIdent | null) => void; @@ -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(), @@ -55,5 +61,5 @@ export function EnsembleDropdown( }); } - return ; + return ; } diff --git a/frontend/src/framework/components/EnsembleSelect/ensembleSelect.tsx b/frontend/src/framework/components/EnsembleSelect/ensembleSelect.tsx index 59529e5bf..b40b64d68 100644 --- a/frontend/src/framework/components/EnsembleSelect/ensembleSelect.tsx +++ b/frontend/src/framework/components/EnsembleSelect/ensembleSelect.tsx @@ -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"; @@ -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)[]; @@ -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[]; @@ -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(), @@ -73,7 +80,7 @@ export function EnsembleSelect(