From 264524a937d4f34042c409d0b88e4fa3b5159304 Mon Sep 17 00:00:00 2001 From: Ruben Thoms Date: Mon, 11 Nov 2024 18:28:49 +0100 Subject: [PATCH] wip --- frontend/src/framework/WorkbenchSession.ts | 2 +- .../modules/2DViewer/layers/LayerManager.ts | 69 ++++++++++++++---- .../layers/delegates/GroupDelegate.ts | 36 +++++----- .../2DViewer/layers/delegates/ItemDelegate.ts | 13 ++++ .../layers/delegates/LayerDelegate.ts | 7 ++ .../delegates/PublishSubscribeDelegate.ts | 1 + .../layers/delegates/SettingDelegate.ts | 6 +- .../delegates/SettingsContextDelegate.ts | 22 +++--- .../DrilledWellTrajectoriesContext.ts | 6 +- .../DrilledWellTrajectoriesLayer.ts | 6 +- .../DrilledWellTrajectoriesLayer/types.ts | 2 +- .../DrilledWellborePicksContext.ts | 11 ++- .../DrilledWellborePicksLayer.ts | 5 +- .../layers/DrilledWellborePicksLayer/types.ts | 2 +- .../RealizationGridContext.ts | 13 ++-- .../RealizationPolygonsContext.ts | 13 ++-- .../RealizationSurfaceContext.ts | 13 ++-- .../StatisticalSurfaceContext.ts | 5 +- .../settings/DrilledWellbores.tsx | 71 +++++++++++++------ .../implementations/settings/GridLayer.tsx | 10 +-- .../implementations/settings/Sensitivity.tsx | 2 +- .../src/modules/2DViewer/layers/interfaces.ts | 11 +-- .../view/components/LayersWrapper.tsx | 3 - 23 files changed, 209 insertions(+), 120 deletions(-) diff --git a/frontend/src/framework/WorkbenchSession.ts b/frontend/src/framework/WorkbenchSession.ts index aa9d610c8..54fa1c5ad 100644 --- a/frontend/src/framework/WorkbenchSession.ts +++ b/frontend/src/framework/WorkbenchSession.ts @@ -77,7 +77,7 @@ export class WorkbenchSession { } } -function createEnsembleRealizationFilterFuncForWorkbenchSession(workbenchSession: WorkbenchSession) { +export function createEnsembleRealizationFilterFuncForWorkbenchSession(workbenchSession: WorkbenchSession) { return function ensembleRealizationFilterFunc(ensembleIdent: EnsembleIdent): readonly number[] { const realizationFilterSet = workbenchSession.getRealizationFilterSet(); const realizationFilter = realizationFilterSet.getRealizationFilterForEnsembleIdent(ensembleIdent); diff --git a/frontend/src/modules/2DViewer/layers/LayerManager.ts b/frontend/src/modules/2DViewer/layers/LayerManager.ts index 400691374..cb45aa6c0 100644 --- a/frontend/src/modules/2DViewer/layers/LayerManager.ts +++ b/frontend/src/modules/2DViewer/layers/LayerManager.ts @@ -1,4 +1,10 @@ -import { WorkbenchSession, WorkbenchSessionEvent } from "@framework/WorkbenchSession"; +import { Ensemble } from "@framework/Ensemble"; +import { + EnsembleRealizationFilterFunction, + WorkbenchSession, + WorkbenchSessionEvent, + createEnsembleRealizationFilterFuncForWorkbenchSession, +} from "@framework/WorkbenchSession"; import { WorkbenchSettings } from "@framework/WorkbenchSettings"; import { QueryClient } from "@tanstack/react-query"; @@ -11,11 +17,11 @@ import { UnsubscribeHandlerDelegate } from "./delegates/UnsubscribeHandlerDelega import { Group, Item, SerializedLayerManager } from "./interfaces"; export enum LayerManagerTopic { - ITEMS_CHANGED = "items-changed", - SETTINGS_CHANGED = "settings-changed", - AVAILABLE_SETTINGS_CHANGED = "available-settings-changed", - LAYER_DATA_REVISION = "layer-data-changed", - GLOBAL_SETTINGS_CHANGED = "global-settings-changed", + ITEMS_CHANGED = "ITEMS_CHANGED", + SETTINGS_CHANGED = "SETTINGS_CHANGED", + AVAILABLE_SETTINGS_CHANGED = "AVAILABLE_SETTINGS_CHANGED", + LAYER_DATA_REVISION = "LAYER_DATA_REVISION", + GLOBAL_SETTINGS_CHANGED = "GLOBAL_SETTINGS_CHANGED", } export type LayerManagerTopicPayload = { @@ -28,6 +34,8 @@ export type LayerManagerTopicPayload = { export type GlobalSettings = { fieldId: string | null; + ensembles: readonly Ensemble[]; + realizationFilterFunction: EnsembleRealizationFilterFunction; }; export class LayerManager implements Group, PublishSubscribe { @@ -38,10 +46,9 @@ export class LayerManager implements Group, PublishSubscribe(); private _itemDelegate: ItemDelegate; private _layerDataRevision: number = 0; - private _globalSettings: GlobalSettings = { - fieldId: null, - }; + private _globalSettings: GlobalSettings; private _subscriptionsHandler = new UnsubscribeHandlerDelegate(); + private _deserializing = false; constructor(workbenchSession: WorkbenchSession, workbenchSettings: WorkbenchSettings, queryClient: QueryClient) { this._workbenchSession = workbenchSession; @@ -49,6 +56,9 @@ export class LayerManager implements Group, PublishSubscribe(key: T, value: GlobalSettings[T]): void { - if (!isEqual(this._globalSettings[key], value)) { - this._globalSettings[key] = value; - this._publishSubscribeDelegate.notifySubscribers(LayerManagerTopic.GLOBAL_SETTINGS_CHANGED); + if (isEqual(this._globalSettings[key], value)) { + return; } + + this._globalSettings[key] = value; + this.publishTopic(LayerManagerTopic.GLOBAL_SETTINGS_CHANGED); } getGlobalSetting(key: T): GlobalSettings[T] { @@ -91,6 +130,10 @@ export class LayerManager implements Group, PublishSubscribe(); private _subscriptions: Map void>> = new Map(); private _treeRevisionNumber: number = 0; + private _deserializing = false; constructor(owner: Item | null) { this._owner = owner; @@ -40,7 +41,7 @@ export class GroupDelegate implements PublishSubscribe { - this._publishSubscribeDelegate.notifySubscribers(GroupDelegateTopic.CHILDREN_EXPANSION_STATES); + this.publishTopic(GroupDelegateTopic.CHILDREN_EXPANSION_STATES); }) ); } if (instanceofGroup(child)) { - /* - for (const grandchild of child.getGroupDelegate().getChildren()) { - child.getGroupDelegate().takeOwnershipOfChild(grandchild); - } - */ - - subscriptionSet.add( - child - .getGroupDelegate() - .getPublishSubscribeDelegate() - .makeSubscriberFunction(GroupDelegateTopic.CHILDREN)(() => { - this.incrementTreeRevisionNumber(); - }) - ); subscriptionSet.add( child .getGroupDelegate() @@ -86,10 +73,17 @@ export class GroupDelegate implements PublishSubscribe } setIsSubordinated(isSubordinated: boolean): void { + if (this._isSubordinated === isSubordinated) { + return; + } this._isSubordinated = isSubordinated; this._publishSubscribeDelegate.notifySubscribers(LayerDelegateTopic.SUBORDINATED); } @@ -197,6 +200,10 @@ export class LayerDelegate } private setStatus(status: LayerStatus): void { + if (this._status === status) { + return; + } + this._status = status; this._layerManager?.publishTopic(LayerManagerTopic.LAYER_DATA_REVISION); this._publishSubscribeDelegate.notifySubscribers(LayerDelegateTopic.STATUS); diff --git a/frontend/src/modules/2DViewer/layers/delegates/PublishSubscribeDelegate.ts b/frontend/src/modules/2DViewer/layers/delegates/PublishSubscribeDelegate.ts index 567fd3bfc..054010baf 100644 --- a/frontend/src/modules/2DViewer/layers/delegates/PublishSubscribeDelegate.ts +++ b/frontend/src/modules/2DViewer/layers/delegates/PublishSubscribeDelegate.ts @@ -12,6 +12,7 @@ export class PublishSubscribeDelegate { notifySubscribers(topic: TTopic): void { const subscribers = this._subscribers.get(topic); + console.debug(topic); if (subscribers) { subscribers.forEach((subscriber) => subscriber()); } diff --git a/frontend/src/modules/2DViewer/layers/delegates/SettingDelegate.ts b/frontend/src/modules/2DViewer/layers/delegates/SettingDelegate.ts index 9044891af..193a81a59 100644 --- a/frontend/src/modules/2DViewer/layers/delegates/SettingDelegate.ts +++ b/frontend/src/modules/2DViewer/layers/delegates/SettingDelegate.ts @@ -34,7 +34,7 @@ export class SettingDelegate implements PublishSubscribe(); - private _availableValues: AvailableValuesType = [] as AvailableValuesType; + private _availableValues: AvailableValuesType = [] as unknown as AvailableValuesType; private _overriddenValue: TValue | undefined = undefined; private _loading: boolean = false; private _initialized: boolean = false; @@ -176,6 +176,10 @@ export class SettingDelegate implements PublishSubscribe( - key: K, - availableValues: AvailableValuesType> - ): void { + setAvailableValues(key: K, availableValues: AvailableValuesType): void { const settingDelegate = this._settings[key].getDelegate(); settingDelegate.setAvailableValues(availableValues); @@ -294,18 +296,18 @@ export class SettingsContextDelegate( settingKey: K, - updateFunc: UpdateFunc>, TSettings, K> - ): Dependency>, TSettings, K> => { - const dependency = new Dependency>, TSettings, K>( + updateFunc: UpdateFunc, TSettings, K> + ): Dependency, TSettings, K> => { + const dependency = new Dependency, TSettings, K>( this as unknown as SettingsContextDelegate, updateFunc, makeSettingGetter, makeGlobalSettingGetter ); - dependency.subscribe((availableValues: AvailableValuesType> | null) => { + dependency.subscribe((availableValues: AvailableValuesType | null) => { if (availableValues === null) { - this.setAvailableValues(settingKey, [] as AvailableValuesType>); + this.setAvailableValues(settingKey, [] as unknown as AvailableValuesType); return; } this.setAvailableValues(settingKey, availableValues); diff --git a/frontend/src/modules/2DViewer/layers/implementations/layers/DrilledWellTrajectoriesLayer/DrilledWellTrajectoriesContext.ts b/frontend/src/modules/2DViewer/layers/implementations/layers/DrilledWellTrajectoriesLayer/DrilledWellTrajectoriesContext.ts index 1c9c6b82c..ccf7dabb4 100644 --- a/frontend/src/modules/2DViewer/layers/implementations/layers/DrilledWellTrajectoriesLayer/DrilledWellTrajectoriesContext.ts +++ b/frontend/src/modules/2DViewer/layers/implementations/layers/DrilledWellTrajectoriesLayer/DrilledWellTrajectoriesContext.ts @@ -1,4 +1,3 @@ -import { WellboreHeader_api } from "@api"; import { apiService } from "@framework/ApiService"; import { LayerManager } from "@modules/2DViewer/layers/LayerManager"; import { SettingsContextDelegate } from "@modules/2DViewer/layers/delegates/SettingsContextDelegate"; @@ -41,10 +40,9 @@ export class DrilledWellTrajectoriesContext implements SettingsContext) { availableSettingsUpdater(SettingType.ENSEMBLE, ({ getGlobalSetting }) => { const fieldIdentifier = getGlobalSetting("fieldId"); - const ensembleSet = workbenchSession.getEnsembleSet(); + const ensembles = getGlobalSetting("ensembles"); - const ensembleIdents = ensembleSet - .getEnsembleArr() + const ensembleIdents = ensembles .filter((ensemble) => ensemble.getFieldIdentifier() === fieldIdentifier) .map((ensemble) => ensemble.getIdent()); diff --git a/frontend/src/modules/2DViewer/layers/implementations/layers/DrilledWellTrajectoriesLayer/DrilledWellTrajectoriesLayer.ts b/frontend/src/modules/2DViewer/layers/implementations/layers/DrilledWellTrajectoriesLayer/DrilledWellTrajectoriesLayer.ts index 041bb31f7..2abc09855 100644 --- a/frontend/src/modules/2DViewer/layers/implementations/layers/DrilledWellTrajectoriesLayer/DrilledWellTrajectoriesLayer.ts +++ b/frontend/src/modules/2DViewer/layers/implementations/layers/DrilledWellTrajectoriesLayer/DrilledWellTrajectoriesLayer.ts @@ -83,7 +83,11 @@ export class DrilledWellTrajectoriesLayer implements Layer header.wellboreUuid); + let selectedWellboreUuids: string[] = []; + if (selectedWellboreHeaders) { + selectedWellboreHeaders.map((header) => header.wellboreUuid); + } + let fieldIdentifier: string | null = null; if (ensembleIdent) { const ensemble = ensembleSet.findEnsemble(ensembleIdent); diff --git a/frontend/src/modules/2DViewer/layers/implementations/layers/DrilledWellTrajectoriesLayer/types.ts b/frontend/src/modules/2DViewer/layers/implementations/layers/DrilledWellTrajectoriesLayer/types.ts index c684eacfb..7e4f232c1 100644 --- a/frontend/src/modules/2DViewer/layers/implementations/layers/DrilledWellTrajectoriesLayer/types.ts +++ b/frontend/src/modules/2DViewer/layers/implementations/layers/DrilledWellTrajectoriesLayer/types.ts @@ -4,5 +4,5 @@ import { SettingType } from "@modules/2DViewer/layers/settingsTypes"; export type DrilledWellTrajectoriesSettings = { [SettingType.ENSEMBLE]: EnsembleIdent | null; - [SettingType.SMDA_WELLBORE_HEADERS]: WellboreHeader_api[]; + [SettingType.SMDA_WELLBORE_HEADERS]: WellboreHeader_api[] | null; }; diff --git a/frontend/src/modules/2DViewer/layers/implementations/layers/DrilledWellborePicksLayer/DrilledWellborePicksContext.ts b/frontend/src/modules/2DViewer/layers/implementations/layers/DrilledWellborePicksLayer/DrilledWellborePicksContext.ts index a66ed7142..275f20202 100644 --- a/frontend/src/modules/2DViewer/layers/implementations/layers/DrilledWellborePicksLayer/DrilledWellborePicksContext.ts +++ b/frontend/src/modules/2DViewer/layers/implementations/layers/DrilledWellborePicksLayer/DrilledWellborePicksContext.ts @@ -1,4 +1,3 @@ -import { WellboreHeader_api } from "@api"; import { apiService } from "@framework/ApiService"; import { LayerManager } from "@modules/2DViewer/layers/LayerManager"; import { SettingsContextDelegate } from "@modules/2DViewer/layers/delegates/SettingsContextDelegate"; @@ -15,8 +14,6 @@ import { SurfaceName } from "../../settings/SurfaceName"; export class DrilledWellborePicksContext implements SettingsContext { private _contextDelegate: SettingsContextDelegate; - private _wellboreHeadersCache: WellboreHeader_api[] | null = null; - private _pickIdentifierCache: string[] | null = null; constructor(layerManager: LayerManager) { this._contextDelegate = new SettingsContextDelegate< @@ -40,7 +37,8 @@ export class DrilledWellborePicksContext implements SettingsContext 0 && + settings[SettingType.SMDA_WELLBORE_HEADERS] !== null && + settings[SettingType.SMDA_WELLBORE_HEADERS].length > 0 && settings[SettingType.SURFACE_NAME] !== null ); } @@ -53,10 +51,9 @@ export class DrilledWellborePicksContext implements SettingsContext) { availableSettingsUpdater(SettingType.ENSEMBLE, ({ getGlobalSetting }) => { const fieldIdentifier = getGlobalSetting("fieldId"); - const ensembleSet = workbenchSession.getEnsembleSet(); + const ensembles = getGlobalSetting("ensembles"); - const ensembleIdents = ensembleSet - .getEnsembleArr() + const ensembleIdents = ensembles .filter((ensemble) => ensemble.getFieldIdentifier() === fieldIdentifier) .map((ensemble) => ensemble.getIdent()); diff --git a/frontend/src/modules/2DViewer/layers/implementations/layers/DrilledWellborePicksLayer/DrilledWellborePicksLayer.ts b/frontend/src/modules/2DViewer/layers/implementations/layers/DrilledWellborePicksLayer/DrilledWellborePicksLayer.ts index 0faa399bd..e5f5c6b32 100644 --- a/frontend/src/modules/2DViewer/layers/implementations/layers/DrilledWellborePicksLayer/DrilledWellborePicksLayer.ts +++ b/frontend/src/modules/2DViewer/layers/implementations/layers/DrilledWellborePicksLayer/DrilledWellborePicksLayer.ts @@ -80,7 +80,10 @@ export class DrilledWellborePicksLayer implements Layer header.wellboreUuid); + let selectedWellboreUuids: string[] = []; + if (selectedWellboreHeaders) { + selectedWellboreUuids = selectedWellboreHeaders.map((header) => header.wellboreUuid); + } const selectedPickIdentifier = settings[SettingType.SURFACE_NAME].getDelegate().getValue(); let fieldIdentifier: string | null = null; if (ensembleIdent) { diff --git a/frontend/src/modules/2DViewer/layers/implementations/layers/DrilledWellborePicksLayer/types.ts b/frontend/src/modules/2DViewer/layers/implementations/layers/DrilledWellborePicksLayer/types.ts index 9dc2321c5..444fd66ce 100644 --- a/frontend/src/modules/2DViewer/layers/implementations/layers/DrilledWellborePicksLayer/types.ts +++ b/frontend/src/modules/2DViewer/layers/implementations/layers/DrilledWellborePicksLayer/types.ts @@ -4,6 +4,6 @@ import { SettingType } from "@modules/2DViewer/layers/settingsTypes"; export type DrilledWellborePicksSettings = { [SettingType.ENSEMBLE]: EnsembleIdent | null; - [SettingType.SMDA_WELLBORE_HEADERS]: WellboreHeader_api[]; + [SettingType.SMDA_WELLBORE_HEADERS]: WellboreHeader_api[] | null; [SettingType.SURFACE_NAME]: string | null; }; diff --git a/frontend/src/modules/2DViewer/layers/implementations/layers/RealizationGridLayer/RealizationGridContext.ts b/frontend/src/modules/2DViewer/layers/implementations/layers/RealizationGridLayer/RealizationGridContext.ts index 3ef942d79..1dad50b29 100644 --- a/frontend/src/modules/2DViewer/layers/implementations/layers/RealizationGridLayer/RealizationGridContext.ts +++ b/frontend/src/modules/2DViewer/layers/implementations/layers/RealizationGridLayer/RealizationGridContext.ts @@ -61,27 +61,24 @@ export class RealizationGridContext implements SettingsContext) { availableSettingsUpdater(SettingType.ENSEMBLE, ({ getGlobalSetting }) => { const fieldIdentifier = getGlobalSetting("fieldId"); - const ensembleSet = workbenchSession.getEnsembleSet(); + const ensembles = getGlobalSetting("ensembles"); - const ensembleIdents = ensembleSet - .getEnsembleArr() + const ensembleIdents = ensembles .filter((ensemble) => ensemble.getFieldIdentifier() === fieldIdentifier) .map((ensemble) => ensemble.getIdent()); return ensembleIdents; }); - availableSettingsUpdater(SettingType.REALIZATION, ({ getLocalSetting }) => { + availableSettingsUpdater(SettingType.REALIZATION, ({ getLocalSetting, getGlobalSetting }) => { const ensembleIdent = getLocalSetting(SettingType.ENSEMBLE); + const realizationFilterFunc = getGlobalSetting("realizationFilterFunction"); if (!ensembleIdent) { return []; } - const realizations = workbenchSession - .getRealizationFilterSet() - .getRealizationFilterForEnsembleIdent(ensembleIdent) - .getFilteredRealizations(); + const realizations = realizationFilterFunc(ensembleIdent); return [...realizations]; }); diff --git a/frontend/src/modules/2DViewer/layers/implementations/layers/RealizationPolygonsLayer/RealizationPolygonsContext.ts b/frontend/src/modules/2DViewer/layers/implementations/layers/RealizationPolygonsLayer/RealizationPolygonsContext.ts index dd69aa71b..b26f06c17 100644 --- a/frontend/src/modules/2DViewer/layers/implementations/layers/RealizationPolygonsLayer/RealizationPolygonsContext.ts +++ b/frontend/src/modules/2DViewer/layers/implementations/layers/RealizationPolygonsLayer/RealizationPolygonsContext.ts @@ -46,27 +46,24 @@ export class RealizationPolygonsContext implements SettingsContext) { availableSettingsUpdater(SettingType.ENSEMBLE, ({ getGlobalSetting }) => { const fieldIdentifier = getGlobalSetting("fieldId"); - const ensembleSet = workbenchSession.getEnsembleSet(); + const ensembles = getGlobalSetting("ensembles"); - const ensembleIdents = ensembleSet - .getEnsembleArr() + const ensembleIdents = ensembles .filter((ensemble) => ensemble.getFieldIdentifier() === fieldIdentifier) .map((ensemble) => ensemble.getIdent()); return ensembleIdents; }); - availableSettingsUpdater(SettingType.REALIZATION, ({ getLocalSetting }) => { + availableSettingsUpdater(SettingType.REALIZATION, ({ getLocalSetting, getGlobalSetting }) => { const ensembleIdent = getLocalSetting(SettingType.ENSEMBLE); + const realizationFilterFunc = getGlobalSetting("realizationFilterFunction"); if (!ensembleIdent) { return []; } - const realizations = workbenchSession - .getRealizationFilterSet() - .getRealizationFilterForEnsembleIdent(ensembleIdent) - .getFilteredRealizations(); + const realizations = realizationFilterFunc(ensembleIdent); return [...realizations]; }); diff --git a/frontend/src/modules/2DViewer/layers/implementations/layers/RealizationSurfaceLayer/RealizationSurfaceContext.ts b/frontend/src/modules/2DViewer/layers/implementations/layers/RealizationSurfaceLayer/RealizationSurfaceContext.ts index 6356589d1..0117d3889 100644 --- a/frontend/src/modules/2DViewer/layers/implementations/layers/RealizationSurfaceLayer/RealizationSurfaceContext.ts +++ b/frontend/src/modules/2DViewer/layers/implementations/layers/RealizationSurfaceLayer/RealizationSurfaceContext.ts @@ -47,27 +47,24 @@ export class RealizationSurfaceContext implements SettingsContext) { availableSettingsUpdater(SettingType.ENSEMBLE, ({ getGlobalSetting }) => { const fieldIdentifier = getGlobalSetting("fieldId"); - const ensembleSet = workbenchSession.getEnsembleSet(); + const ensembles = getGlobalSetting("ensembles"); - const ensembleIdents = ensembleSet - .getEnsembleArr() + const ensembleIdents = ensembles .filter((ensemble) => ensemble.getFieldIdentifier() === fieldIdentifier) .map((ensemble) => ensemble.getIdent()); return ensembleIdents; }); - availableSettingsUpdater(SettingType.REALIZATION, ({ getLocalSetting }) => { + availableSettingsUpdater(SettingType.REALIZATION, ({ getLocalSetting, getGlobalSetting }) => { const ensembleIdent = getLocalSetting(SettingType.ENSEMBLE); + const realizationFilterFunc = getGlobalSetting("realizationFilterFunction"); if (!ensembleIdent) { return []; } - const realizations = workbenchSession - .getRealizationFilterSet() - .getRealizationFilterForEnsembleIdent(ensembleIdent) - .getFilteredRealizations(); + const realizations = realizationFilterFunc(ensembleIdent); return [...realizations]; }); diff --git a/frontend/src/modules/2DViewer/layers/implementations/layers/StatisticalSurfaceLayer/StatisticalSurfaceContext.ts b/frontend/src/modules/2DViewer/layers/implementations/layers/StatisticalSurfaceLayer/StatisticalSurfaceContext.ts index a5c453544..4eaa9c357 100644 --- a/frontend/src/modules/2DViewer/layers/implementations/layers/StatisticalSurfaceLayer/StatisticalSurfaceContext.ts +++ b/frontend/src/modules/2DViewer/layers/implementations/layers/StatisticalSurfaceLayer/StatisticalSurfaceContext.ts @@ -50,10 +50,9 @@ export class StatisticalSurfaceContext implements SettingsContext Object.values(SurfaceStatisticFunction_api)); availableSettingsUpdater(SettingType.ENSEMBLE, ({ getGlobalSetting }) => { const fieldIdentifier = getGlobalSetting("fieldId"); - const ensembleSet = workbenchSession.getEnsembleSet(); + const ensembles = getGlobalSetting("ensembles"); - const ensembleIdents = ensembleSet - .getEnsembleArr() + const ensembleIdents = ensembles .filter((ensemble) => ensemble.getFieldIdentifier() === fieldIdentifier) .map((ensemble) => ensemble.getIdent()); diff --git a/frontend/src/modules/2DViewer/layers/implementations/settings/DrilledWellbores.tsx b/frontend/src/modules/2DViewer/layers/implementations/settings/DrilledWellbores.tsx index abf65f87d..b287cb7e5 100644 --- a/frontend/src/modules/2DViewer/layers/implementations/settings/DrilledWellbores.tsx +++ b/frontend/src/modules/2DViewer/layers/implementations/settings/DrilledWellbores.tsx @@ -1,18 +1,22 @@ import React from "react"; import { WellboreHeader_api } from "@api"; +import { DenseIconButton } from "@lib/components/DenseIconButton"; import { Select, SelectOption } from "@lib/components/Select"; +import { Deselect, SelectAll } from "@mui/icons-material"; import { SettingRegistry } from "../../SettingRegistry"; import { SettingDelegate } from "../../delegates/SettingDelegate"; -import { Setting, SettingComponentProps } from "../../interfaces"; +import { AvailableValuesType, Setting, SettingComponentProps } from "../../interfaces"; import { SettingType } from "../../settingsTypes"; -export class DrilledWellbores implements Setting { - private _delegate: SettingDelegate; +type ValueType = WellboreHeader_api[] | null; + +export class DrilledWellbores implements Setting { + private _delegate: SettingDelegate; constructor() { - this._delegate = new SettingDelegate([], this); + this._delegate = new SettingDelegate(null, this); } getType(): SettingType { @@ -23,11 +27,15 @@ export class DrilledWellbores implements Setting { return "Drilled wellbores"; } - getDelegate(): SettingDelegate { + getDelegate(): SettingDelegate { return this._delegate; } - fixupValue(availableValues: WellboreHeader_api[], currentValue: WellboreHeader_api[]): WellboreHeader_api[] { + fixupValue(availableValues: AvailableValuesType, currentValue: ValueType): ValueType { + if (!currentValue) { + return availableValues; + } + const matchingValues = currentValue.filter((value) => availableValues.some((availableValue) => availableValue.wellboreUuid === value.wellboreUuid) ); @@ -37,32 +45,53 @@ export class DrilledWellbores implements Setting { return matchingValues; } - makeComponent(): (props: SettingComponentProps) => React.ReactNode { - return function DrilledWellbores(props: SettingComponentProps) { + makeComponent(): (props: SettingComponentProps) => React.ReactNode { + return function DrilledWellbores(props: SettingComponentProps) { const options: SelectOption[] = props.availableValues.map((ident) => ({ value: ident.wellboreUuid, label: ident.uniqueWellboreIdentifier, })); - const handleChange = (selectedUuids: string[]) => { + function handleChange(selectedUuids: string[]) { const selectedWellbores = props.availableValues.filter((ident) => selectedUuids.includes(ident.wellboreUuid) ); props.onValueChange(selectedWellbores); - }; + } + + function selectAll() { + const allUuids = props.availableValues.map((ident) => ident.wellboreUuid); + handleChange(allUuids); + } + + function selectNone() { + handleChange([]); + } - const selectedValues = props.value.map((ident) => ident.wellboreUuid); + const selectedValues = props.value?.map((ident) => ident.wellboreUuid) ?? []; return ( - + ); }; } @@ -95,4 +124,4 @@ export function WellboreHeaderSelector(props: WellboreHeaderSelectorProps): Reac ); } -SettingRegistry.registerSetting(DrilledWellbores); +SettingRegistry.registerSetting(DrilledWellbores as unknown as new () => Setting); diff --git a/frontend/src/modules/2DViewer/layers/implementations/settings/GridLayer.tsx b/frontend/src/modules/2DViewer/layers/implementations/settings/GridLayer.tsx index ff2a16d01..0cd3e3dfe 100644 --- a/frontend/src/modules/2DViewer/layers/implementations/settings/GridLayer.tsx +++ b/frontend/src/modules/2DViewer/layers/implementations/settings/GridLayer.tsx @@ -4,7 +4,7 @@ import { Dropdown, DropdownOption } from "@lib/components/Dropdown"; import { SettingRegistry } from "../../SettingRegistry"; import { SettingDelegate } from "../../delegates/SettingDelegate"; -import { Setting, SettingComponentProps } from "../../interfaces"; +import { AvailableValuesType, Setting, SettingComponentProps } from "../../interfaces"; import { SettingType } from "../../settingsTypes"; type ValueType = number | null; @@ -13,7 +13,7 @@ export class GridLayer implements Setting { private _delegate: SettingDelegate; constructor() { - this._delegate = new SettingDelegate(null, this); + this._delegate = new SettingDelegate(null, this); } getType(): SettingType { @@ -28,7 +28,7 @@ export class GridLayer implements Setting { return this._delegate; } - isValueValid(availableValues: null[] | number[], value: ValueType): boolean { + isValueValid(availableValues: AvailableValuesType, value: ValueType): boolean { if (value === null) { return false; } @@ -47,7 +47,7 @@ export class GridLayer implements Setting { return value >= min && value <= max; } - fixupValue(availableValues: null[] | number[], currentValue: ValueType): ValueType { + fixupValue(availableValues: AvailableValuesType, currentValue: ValueType): ValueType { if (availableValues.length < 3) { return null; } @@ -98,4 +98,4 @@ export class GridLayer implements Setting { } } -SettingRegistry.registerSetting(GridLayer); +SettingRegistry.registerSetting(GridLayer as unknown as new () => Setting); diff --git a/frontend/src/modules/2DViewer/layers/implementations/settings/Sensitivity.tsx b/frontend/src/modules/2DViewer/layers/implementations/settings/Sensitivity.tsx index 499ac1245..8cd2ee4f7 100644 --- a/frontend/src/modules/2DViewer/layers/implementations/settings/Sensitivity.tsx +++ b/frontend/src/modules/2DViewer/layers/implementations/settings/Sensitivity.tsx @@ -135,4 +135,4 @@ function fixupSensitivityCase(currentSensitivityCase: string | null, availableSe return currentSensitivityCase; } -SettingRegistry.registerSetting(Sensitivity); +SettingRegistry.registerSetting(Sensitivity as unknown as new () => Setting); diff --git a/frontend/src/modules/2DViewer/layers/interfaces.ts b/frontend/src/modules/2DViewer/layers/interfaces.ts index 3a3eb9210..dc2e392ad 100644 --- a/frontend/src/modules/2DViewer/layers/interfaces.ts +++ b/frontend/src/modules/2DViewer/layers/interfaces.ts @@ -137,8 +137,8 @@ export interface UpdateFunc { availableSettingsUpdater: ( settingName: TKey, - update: UpdateFunc>, TSettings, TKey> - ) => Dependency>, TSettings, TKey>; + update: UpdateFunc, TSettings, TKey> + ) => Dependency, TSettings, TKey>; helperDependency: ( update: (args: { getLocalSetting: (settingName: T) => TSettings[T]; @@ -158,8 +158,11 @@ export interface SettingsContext): void; } -export type AvailableValuesType = TValue extends Array ? TValue : Array; +export type AvailableValuesType = Exclude extends Array + ? Array + : Array>; export type PossiblyUndefined = { [K in keyof TSettings]?: TSettings[K] }; +export type EachAvailableValuesType = T extends any ? AvailableValuesType : never; export type SettingComponentProps = { onValueChange: (newValue: TValue) => void; @@ -167,7 +170,7 @@ export type SettingComponentProps = { isValueValid: boolean; overriddenValue: TValue | null; isOverridden: boolean; - availableValues: AvailableValuesType>; + availableValues: AvailableValuesType; workbenchSession: WorkbenchSession; workbenchSettings: WorkbenchSettings; globalSettings: GlobalSettings; diff --git a/frontend/src/modules/2DViewer/view/components/LayersWrapper.tsx b/frontend/src/modules/2DViewer/view/components/LayersWrapper.tsx index c44784042..ea7a6bb58 100644 --- a/frontend/src/modules/2DViewer/view/components/LayersWrapper.tsx +++ b/frontend/src/modules/2DViewer/view/components/LayersWrapper.tsx @@ -8,7 +8,6 @@ import { useElementSize } from "@lib/hooks/useElementSize"; import { Rect2D, rectContainsPoint } from "@lib/utils/geometry"; import { Interfaces } from "@modules/2DViewer/interfaces"; import { LayerManager, LayerManagerTopic } from "@modules/2DViewer/layers/LayerManager"; -import { GroupDelegateTopic } from "@modules/2DViewer/layers/delegates/GroupDelegate"; import { usePublishSubscribeTopicValue } from "@modules/2DViewer/layers/delegates/PublishSubscribeDelegate"; import { BoundingBox } from "@modules/2DViewer/layers/interfaces"; import { PreferredViewLayout } from "@modules/2DViewer/types"; @@ -38,8 +37,6 @@ export function LayersWrapper(props: LayersWrapperProps): React.ReactNode { usePublishSubscribeTopicValue(props.layerManager, LayerManagerTopic.LAYER_DATA_REVISION); - usePublishSubscribeTopicValue(groupDelegate, GroupDelegateTopic.TREE_REVISION_NUMBER); - const viewports: ViewportType[] = []; const viewerLayers: DeckGlLayerWithPosition[] = []; const viewportAnnotations: React.ReactNode[] = [];