From 501e772e9c7060f84727eedc86c83d0caa4dbe18 Mon Sep 17 00:00:00 2001 From: Filip Leitner Date: Thu, 10 Oct 2024 18:09:38 +0200 Subject: [PATCH] fix(layermanager): Reset layer editor state on layer type change --- cypress/tests/layer-editor.cy.ts | 12 +++++------- .../layer-manager/editor/layer-editor.service.ts | 2 +- .../gallery/gallery-editor-dialog.component.ts | 16 ++++++++++++++++ .../layer-type-switcher-widget.component.ts | 6 +++++- 4 files changed, 27 insertions(+), 9 deletions(-) diff --git a/cypress/tests/layer-editor.cy.ts b/cypress/tests/layer-editor.cy.ts index 4565a7e47b..378fd50275 100644 --- a/cypress/tests/layer-editor.cy.ts +++ b/cypress/tests/layer-editor.cy.ts @@ -47,14 +47,12 @@ describe('Hslayers application', () => { .parent() .within(() => { cy.get('div').click(); - cy.get('label').contains('More').click(); - cy.get('hs-layer-editor form hs-layer-type-switcher-widget div') - .find('button') - .contains('Thematic map') - .should('exist') - .click(); }); - + cy.get('hs-layer-type-switcher-widget div') + .find('button') + .contains('Thematic map') + .should('exist') + .click(); cy.get('.modal-footer').find('button').contains('Yes').click(); cy.get('.hs-lm-mapcontentlist .hs-lm-item-title').should('contain', 'EVI'); }); diff --git a/projects/hslayers/components/layer-manager/editor/layer-editor.service.ts b/projects/hslayers/components/layer-manager/editor/layer-editor.service.ts index f7b56fec0c..ef24da4f03 100644 --- a/projects/hslayers/components/layer-manager/editor/layer-editor.service.ts +++ b/projects/hslayers/components/layer-manager/editor/layer-editor.service.ts @@ -140,7 +140,7 @@ export class HsLayerEditorService { * @param toToggle - Part of layer editor to be toggled ('sublayers' or 'settings') * @returns Boolean indicating whether the editor should be created */ - private toggleLayerEditor( + toggleLayerEditor( layer: HsLayerDescriptor, toToggle: 'sublayers' | 'settings', ): boolean { diff --git a/projects/hslayers/components/layer-manager/gallery/gallery-editor-dialog.component.ts b/projects/hslayers/components/layer-manager/gallery/gallery-editor-dialog.component.ts index 1106d94473..4031ab8658 100644 --- a/projects/hslayers/components/layer-manager/gallery/gallery-editor-dialog.component.ts +++ b/projects/hslayers/components/layer-manager/gallery/gallery-editor-dialog.component.ts @@ -14,7 +14,11 @@ import {HsDialogComponent} from 'hslayers-ng/common/dialogs'; import {HsDialogContainerService} from 'hslayers-ng/common/dialogs'; import {HsLayerDescriptor} from 'hslayers-ng/types'; import {HsLayerEditorService} from '../editor/layer-editor.service'; +import {HsLayerManagerService} from 'hslayers-ng/services/layer-manager'; import {TranslateCustomPipe} from 'hslayers-ng/services/language'; +import {filter, map} from 'rxjs'; +import {getBase} from 'hslayers-ng/common/extensions'; +import {takeUntilDestroyed, toObservable} from '@angular/core/rxjs-interop'; @Component({ selector: 'hs-gallery-editor-dialog', @@ -61,6 +65,18 @@ export class HsGalleryEditorDialogComponent private hsDialogContainerService = inject(HsDialogContainerService); private hsLayerEditorService = inject(HsLayerEditorService); + private hsLayerManagerService = inject(HsLayerManagerService); + + constructor() { + toObservable(this.hsLayerManagerService.data.folders) + .pipe( + filter((_) => !getBase(this.data.layer.layer)), + takeUntilDestroyed(), + ) + .subscribe((folders) => { + this.close(); + }); + } close() { this.hsLayerEditorService.createLayerEditor(this.editor(), this.data.layer); diff --git a/projects/hslayers/components/layer-manager/widgets/layer-type-switcher-widget/layer-type-switcher-widget.component.ts b/projects/hslayers/components/layer-manager/widgets/layer-type-switcher-widget/layer-type-switcher-widget.component.ts index 98c222b779..725ba0eb84 100644 --- a/projects/hslayers/components/layer-manager/widgets/layer-type-switcher-widget/layer-type-switcher-widget.component.ts +++ b/projects/hslayers/components/layer-manager/widgets/layer-type-switcher-widget/layer-type-switcher-widget.component.ts @@ -1,4 +1,5 @@ import {Component, Signal, inject, signal} from '@angular/core'; +import {OSM} from 'ol/source'; import {Observable, map} from 'rxjs'; import { @@ -14,9 +15,9 @@ import {HsConfirmDialogComponent} from 'hslayers-ng/common/confirm'; import {HsDialogContainerService} from 'hslayers-ng/common/dialogs'; import {HsEventBusService} from 'hslayers-ng/services/event-bus'; import {HsLayerDescriptor} from 'hslayers-ng/types'; +import {HsLayerEditorService} from '../../editor/layer-editor.service'; import {HsLayerEditorWidgetBaseComponent} from '../layer-editor-widget-base.component'; import {HsLayerUtilsService, HsUtilsService} from 'hslayers-ng/services/utils'; -import {OSM} from 'ol/source'; import {TranslateCustomPipe} from 'hslayers-ng/services/language'; import {getBase, setBase} from 'hslayers-ng/common/extensions'; @@ -40,6 +41,7 @@ export class LayerTypeSwitcherWidgetComponent extends HsLayerEditorWidgetBaseCom private hsLayerUtilsService = inject(HsLayerUtilsService); private hsUtilsService = inject(HsUtilsService); private hsDialogContainerService = inject(HsDialogContainerService); + private layerEditorService = inject(HsLayerEditorService); isEnabled: Observable; currentType: Signal; @@ -133,6 +135,8 @@ export class LayerTypeSwitcherWidgetComponent extends HsLayerEditorWidgetBaseCom if (!toBase) { this.loadingProgressSerice.loadingEvents(currentLayer); + } else { + this.layerEditorService.toggleLayerEditor(currentLayer, 'settings'); } this.hsEventBusService.layerManagerUpdates.next(this.olLayer);