From 1ca3234689a3d45c528a0c3f0f1079048602b218 Mon Sep 17 00:00:00 2001 From: Ruben Thoms Date: Tue, 12 Nov 2024 17:30:42 +0100 Subject: [PATCH] Multiple bug fixes and features --- .../modules/2DViewer/layers/LayerManager.ts | 6 ++++ .../modules/2DViewer/layers/SharedSetting.ts | 21 +++++++++-- .../layers/components/LayerComponent.tsx | 9 ++++- .../layers/components/SettingComponent.tsx | 14 +++++++- .../components/SharedSettingComponent.tsx | 2 +- .../layers/delegates/LayerDelegate.ts | 36 +++++++++++++------ .../delegates/PublishSubscribeDelegate.ts | 1 - .../DrilledWellTrajectoriesLayer.ts | 6 ++-- .../DrilledWellborePicksLayer.ts | 6 ++-- .../view/components/LayersWrapper.tsx | 10 ++---- 10 files changed, 81 insertions(+), 30 deletions(-) diff --git a/frontend/src/modules/2DViewer/layers/LayerManager.ts b/frontend/src/modules/2DViewer/layers/LayerManager.ts index 59acd72b5..34ee0bb1f 100644 --- a/frontend/src/modules/2DViewer/layers/LayerManager.ts +++ b/frontend/src/modules/2DViewer/layers/LayerManager.ts @@ -22,6 +22,7 @@ export enum LayerManagerTopic { AVAILABLE_SETTINGS_CHANGED = "AVAILABLE_SETTINGS_CHANGED", LAYER_DATA_REVISION = "LAYER_DATA_REVISION", GLOBAL_SETTINGS_CHANGED = "GLOBAL_SETTINGS_CHANGED", + SHARED_SETTINGS_CHANGED = "SHARED_SETTINGS_CHANGED", } export type LayerManagerTopicPayload = { @@ -30,6 +31,7 @@ export type LayerManagerTopicPayload = { [LayerManagerTopic.AVAILABLE_SETTINGS_CHANGED]: void; [LayerManagerTopic.LAYER_DATA_REVISION]: number; [LayerManagerTopic.GLOBAL_SETTINGS_CHANGED]: void; + [LayerManagerTopic.SHARED_SETTINGS_CHANGED]: void; }; export type GlobalSettings = { @@ -137,6 +139,7 @@ export class LayerManager implements Group, PublishSubscribe instanceofLayer(item) || item instanceof SharedSetting ) as Layer[]; + let noSettingLoadingOrUninitialized = true; + let index = 0; const availableValues = layersAndSharedSettings.reduce((acc, item) => { if (instanceofLayer(item)) { const setting = item.getLayerDelegate().getSettingsContext().getDelegate().getSettings()[ this._wrappedSetting.getType() ]; if (setting) { - if (acc.length === 0) { + noSettingLoadingOrUninitialized = + noSettingLoadingOrUninitialized && + !setting.getDelegate().getIsLoading() && + setting.getDelegate().getIsInitialized(); + if (index === 0) { acc.push(...setting.getDelegate().getAvailableValues()); } else { acc = acc.filter((value) => setting.getDelegate().getAvailableValues().includes(value)); } + index++; } } if ( @@ -91,16 +98,24 @@ export class SharedSetting implements Item { ) { const setting = item.getWrappedSetting(); if (setting) { - if (acc.length === 0) { + if (index === 0) { acc.push(...setting.getDelegate().getAvailableValues()); } else { acc = acc.filter((value) => setting.getDelegate().getAvailableValues().includes(value)); } + index++; } } return acc; }, [] as any[]); + if (!noSettingLoadingOrUninitialized) { + this._wrappedSetting.getDelegate().setIsLoading(true); + return; + } + + this._wrappedSetting.getDelegate().setIsLoading(false); + this._wrappedSetting.getDelegate().setAvailableValues(availableValues); } diff --git a/frontend/src/modules/2DViewer/layers/components/LayerComponent.tsx b/frontend/src/modules/2DViewer/layers/components/LayerComponent.tsx index b0675eb50..6bf419e5e 100644 --- a/frontend/src/modules/2DViewer/layers/components/LayerComponent.tsx +++ b/frontend/src/modules/2DViewer/layers/components/LayerComponent.tsx @@ -30,7 +30,14 @@ export function LayerComponent(props: LayerComponentProps): React.ReactNode { if (!manager) { return null; } - return ; + return ( + + ); } function makeSettings(settings: Record>): React.ReactNode[] { diff --git a/frontend/src/modules/2DViewer/layers/components/SettingComponent.tsx b/frontend/src/modules/2DViewer/layers/components/SettingComponent.tsx index 965c84aa0..122fad595 100644 --- a/frontend/src/modules/2DViewer/layers/components/SettingComponent.tsx +++ b/frontend/src/modules/2DViewer/layers/components/SettingComponent.tsx @@ -12,6 +12,7 @@ import { Setting, SettingComponentProps as SettingComponentPropsInterface } from export type SettingComponentProps = { setting: Setting; manager: LayerManager; + sharedSetting: boolean; }; export function SettingComponent(props: SettingComponentProps): React.ReactNode { @@ -42,6 +43,15 @@ export function SettingComponent(props: SettingComponentProps): props.setting.getDelegate().setValue(newValue); } + if (props.sharedSetting && availableValues.length === 0 && isInitialized) { + return ( + +
{props.setting.getLabel()}
+
Empty intersection
+
+ ); + } + if (overriddenValue !== undefined) { const valueAsString = props.setting .getDelegate() @@ -54,7 +64,9 @@ export function SettingComponent(props: SettingComponentProps): -
{isValid ? valueAsString : "-"}
+
+ {isValid ? valueAsString : No valid shared setting value} +
); } diff --git a/frontend/src/modules/2DViewer/layers/components/SharedSettingComponent.tsx b/frontend/src/modules/2DViewer/layers/components/SharedSettingComponent.tsx index bda4044f5..1ad7fcc55 100644 --- a/frontend/src/modules/2DViewer/layers/components/SharedSettingComponent.tsx +++ b/frontend/src/modules/2DViewer/layers/components/SharedSettingComponent.tsx @@ -56,7 +56,7 @@ export function SharedSettingComponent(props: SharedSettingComponentProps): Reac hidden: !isExpanded, })} > - + ); diff --git a/frontend/src/modules/2DViewer/layers/delegates/LayerDelegate.ts b/frontend/src/modules/2DViewer/layers/delegates/LayerDelegate.ts index f2e8648f2..ec8dbbe2e 100644 --- a/frontend/src/modules/2DViewer/layers/delegates/LayerDelegate.ts +++ b/frontend/src/modules/2DViewer/layers/delegates/LayerDelegate.ts @@ -76,11 +76,18 @@ export class LayerDelegate this._unsubscribeHandler.registerUnsubscribeFunction( "layer-manager", - layerManager.getPublishSubscribeDelegate().makeSubscriberFunction(LayerManagerTopic.LAYER_DATA_REVISION)( - () => { - this.handleSharedSettingsChanged(); - } - ) + layerManager + .getPublishSubscribeDelegate() + .makeSubscriberFunction(LayerManagerTopic.SHARED_SETTINGS_CHANGED)(() => { + this.handleSharedSettingsChanged(); + }) + ); + + this._unsubscribeHandler.registerUnsubscribeFunction( + "layer-manager", + layerManager.getPublishSubscribeDelegate().makeSubscriberFunction(LayerManagerTopic.ITEMS_CHANGED)(() => { + this.handleSharedSettingsChanged(); + }) ); } @@ -148,10 +155,18 @@ export class LayerDelegate const overriddenSettings: { [K in keyof TSettings]: TSettings[K] } = {} as { [K in keyof TSettings]: TSettings[K]; }; - for (const setting of sharedSettings) { - const type = setting.getWrappedSetting().getType(); - if (this._settingsContext.getDelegate().getSettings()[type] && overriddenSettings[type] === undefined) { - overriddenSettings[type] = setting.getWrappedSetting().getDelegate().getValue(); + for (const sharedSetting of sharedSettings) { + const type = sharedSetting.getWrappedSetting().getType(); + const setting = this._settingsContext.getDelegate().getSettings()[type]; + if (setting && overriddenSettings[type] === undefined) { + if ( + sharedSetting.getWrappedSetting().getDelegate().getIsInitialized() && + sharedSetting.getWrappedSetting().getDelegate().isValueValid() + ) { + overriddenSettings[type] = sharedSetting.getWrappedSetting().getDelegate().getValue(); + } else { + overriddenSettings[type] = null; + } } } this._settingsContext.getDelegate().setOverriddenSettings(overriddenSettings); @@ -205,7 +220,7 @@ export class LayerDelegate } this._status = status; - this._layerManager?.publishTopic(LayerManagerTopic.LAYER_DATA_REVISION); + this._layerManager.publishTopic(LayerManagerTopic.LAYER_DATA_REVISION); this._publishSubscribeDelegate.notifySubscribers(LayerDelegateTopic.STATUS); } @@ -277,6 +292,7 @@ export class LayerDelegate } this._queryKeys = []; this._publishSubscribeDelegate.notifySubscribers(LayerDelegateTopic.DATA); + this._layerManager.publishTopic(LayerManagerTopic.LAYER_DATA_REVISION); this.setStatus(LayerStatus.SUCCESS); } catch (error: any) { if (isCancelledError(error)) { diff --git a/frontend/src/modules/2DViewer/layers/delegates/PublishSubscribeDelegate.ts b/frontend/src/modules/2DViewer/layers/delegates/PublishSubscribeDelegate.ts index 054010baf..567fd3bfc 100644 --- a/frontend/src/modules/2DViewer/layers/delegates/PublishSubscribeDelegate.ts +++ b/frontend/src/modules/2DViewer/layers/delegates/PublishSubscribeDelegate.ts @@ -12,7 +12,6 @@ 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/implementations/layers/DrilledWellTrajectoriesLayer/DrilledWellTrajectoriesLayer.ts b/frontend/src/modules/2DViewer/layers/implementations/layers/DrilledWellTrajectoriesLayer/DrilledWellTrajectoriesLayer.ts index 2c7fccaca..b000a77f1 100644 --- a/frontend/src/modules/2DViewer/layers/implementations/layers/DrilledWellTrajectoriesLayer/DrilledWellTrajectoriesLayer.ts +++ b/frontend/src/modules/2DViewer/layers/implementations/layers/DrilledWellTrajectoriesLayer/DrilledWellTrajectoriesLayer.ts @@ -54,9 +54,9 @@ export class DrilledWellTrajectoriesLayer implements Layer