Skip to content

Commit

Permalink
feat(integration): catalog keep selection when changing tools (#1654)
Browse files Browse the repository at this point in the history
  • Loading branch information
aziz-access authored and alecarn committed Apr 4, 2024
1 parent e1661bb commit f310dd2
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 2 deletions.
10 changes: 10 additions & 0 deletions packages/common/src/lib/tool/shared/toolbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ export class Toolbox {
* Active tool history. Useful for activating the previous tool.
*/
private activeToolHistory: string[] = [];
private previousToolName: string;
private currentToolName: string;

/**
* Tool store
Expand Down Expand Up @@ -118,6 +120,10 @@ export class Toolbox {
this.activateTool(previous);
}

getCurrentPreviousToolName(): [string, string] {
return [this.previousToolName, this.currentToolName];
}

/**
* Activate the tool below, if any
*/
Expand Down Expand Up @@ -198,6 +204,10 @@ export class Toolbox {
this.activeToolHistory = this.activeToolHistory
.filter((name: string) => name !== tool.name)
.concat([tool.name]);

this.previousToolName = this.currentToolName;
this.currentToolName =
this.activeToolHistory[this.activeToolHistory.length - 1];
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { MatTooltipModule } from '@angular/material/tooltip';

import { EntityStore, ListComponent, ListItemDirective } from '@igo2/common';
import { MessageService } from '@igo2/core/message';
import { StorageService } from '@igo2/core/storage';
import { StorageScope, StorageService } from '@igo2/core/storage';
import { ObjectUtils } from '@igo2/utils';

import { TranslateModule } from '@ngx-translate/core';
Expand Down Expand Up @@ -91,6 +91,13 @@ export class CatalogLibaryComponent implements OnInit, OnDestroy {
this.storageService.set('addedCatalogs', catalogs);
}

get selectedCatalogId() {
return this.storageService.get('selectedCatalogId', StorageScope.SESSION);
}
set selectedCatalogId(id) {
this.storageService.set('selectedCatalogId', id, StorageScope.SESSION);
}

constructor(
private capabilitiesService: CapabilitiesService,
private messageService: MessageService,
Expand All @@ -104,6 +111,14 @@ export class CatalogLibaryComponent implements OnInit, OnDestroy {
ngOnInit() {
this.store.state.clear();

if (this.selectedCatalogId) {
const selectedCatalog = this.store
.all()
.find((item) => item.id === this.selectedCatalogId);
if (selectedCatalog) {
this.onCatalogSelect(selectedCatalog);
}
}
this.predefinedCatalogs = this.predefinedCatalogs.map((c) => {
c.id = Md5.hashStr((c.type || 'wms') + standardizeUrl(c.url)) as string;
c.title = c.title === '' || !c.title ? c.url : c.title;
Expand All @@ -129,6 +144,7 @@ export class CatalogLibaryComponent implements OnInit, OnDestroy {
},
true
);
this.selectedCatalogId = catalog.id;
this.catalogSelectChange.emit({ selected: true, catalog });
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {

import { ToolComponent } from '@igo2/common';
import { EntityStore } from '@igo2/common';
import { StorageService } from '@igo2/core/storage';
import { StorageScope, StorageService } from '@igo2/core/storage';
import { Catalog, CatalogLibaryComponent, CatalogService } from '@igo2/geo';

import { take } from 'rxjs/operators';
Expand Down Expand Up @@ -49,6 +49,18 @@ export class CatalogLibraryToolComponent implements OnInit {
*/
@Input() predefinedCatalogs: Catalog[] = [];

set selectedCatalogId(id) {
this.storageService.set('selectedCatalogId', id, StorageScope.SESSION);
}

get currentTool() {
return this.toolState.toolbox.getCurrentPreviousToolName()[1];
}

get lastTool() {
return this.toolState.toolbox.getCurrentPreviousToolName()[0];
}

constructor(
private catalogService: CatalogService,
private catalogState: CatalogState,
Expand All @@ -60,6 +72,10 @@ export class CatalogLibraryToolComponent implements OnInit {
* @internal
*/
ngOnInit() {
if (this.lastTool === 'catalogBrowser' && this.currentTool === 'catalog') {
this.selectedCatalogId = null;
}

if (this.store.count === 0) {
this.loadCatalogs();
}
Expand Down

0 comments on commit f310dd2

Please sign in to comment.