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 May 15, 2024
1 parent ef607e2 commit 946d9f4
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 @@ -22,7 +22,7 @@ import {
} from '@igo2/common';
import { IgoLanguageModule } from '@igo2/core/language';
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 { Observable, Subscription } from 'rxjs';
Expand Down Expand Up @@ -100,6 +100,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 @@ -116,6 +123,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 @@ -141,6 +156,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 { LAYER_PLUS_ICON, 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 946d9f4

Please sign in to comment.