Skip to content

Commit

Permalink
fix(layermanager): Reset layer editor state on layer type change
Browse files Browse the repository at this point in the history
  • Loading branch information
FilipLeitner authored and jmacura committed Oct 17, 2024
1 parent d622eb8 commit 501e772
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 9 deletions.
12 changes: 5 additions & 7 deletions cypress/tests/layer-editor.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {Component, Signal, inject, signal} from '@angular/core';
import {OSM} from 'ol/source';
import {Observable, map} from 'rxjs';

import {
Expand All @@ -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';

Expand All @@ -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<boolean>;
currentType: Signal<string>;
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 501e772

Please sign in to comment.