Skip to content

Commit 8faff95

Browse files
authored
HTM-1763: Feature info: show edit icon only when edit component is enabled (#1055)
2 parents 6a87237 + 87568c3 commit 8faff95

File tree

3 files changed

+23
-37
lines changed

3 files changed

+23
-37
lines changed

projects/core/src/lib/components/feature-info/feature-info-dialog/feature-info-dialog.component.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
@if (layer.error) {
3333
<tm-error-message [friendlyError]="true" [message]="layer.error"></tm-error-message>
3434
}
35-
@if(currentFeature$ | async; as feature) {
35+
@if(currentFeature(); as feature) {
3636
<div class="feature-info" [class.attributes-collapsed]="attributesCollapsed() && !!layer.template">
3737
@if (layer.template) {
3838
<div class="row template-row">
@@ -51,7 +51,7 @@
5151
<div class="buttons">
5252
<button mat-flat-button i18n="@@core.common.back" (click)="back()" color="primary" [disabled]="isPrevButtonDisabled$ | async">Back</button>
5353
<button mat-flat-button i18n="@@core.common.next" (click)="next()" color="primary" [disabled]="isNextButtonDisabled$ | async">Next</button>
54-
@if (showEditButtonConfig && (isEditPossible$ | async)) {
54+
@if (isEditPossible()) {
5555
<div class="edit-feature-button">
5656
<button mat-icon-button
5757
tmTooltip="Edit feature"

projects/core/src/lib/components/feature-info/feature-info-dialog/feature-info-dialog.component.spec.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import { ViewerLayoutService } from '../../../services/viewer-layout/viewer-layo
1717
import { CoreSharedModule } from '../../../shared';
1818
import { FeatureInfoLayerListComponent } from '../feature-info-layer-list/feature-info-layer-list.component';
1919
import { of } from 'rxjs';
20+
import { selectComponentsConfig, selectViewerLoadingState } from '../../../state';
2021

2122
const getFeatureInfo = (updated?: boolean): FeatureInfoModel => {
2223
return {
@@ -51,6 +52,8 @@ const setup = async (withState = false) => {
5152
{ selector: selectFeatureInfoDialogVisible, value: true },
5253
{ selector: selectIsPrevButtonDisabled, value: false },
5354
{ selector: selectIsNextButtonDisabled, value: false },
55+
{ selector: selectViewerLoadingState, value: LoadingStateEnum.LOADED },
56+
{ selector: selectComponentsConfig, value: [] },
5457
] : [],
5558
}),
5659
{ provide: AuthenticatedUserService, useValue: { getUserDetails$: () => of({ isAuthenticated: true }) } },

projects/core/src/lib/components/feature-info/feature-info-dialog/feature-info-dialog.component.ts

Lines changed: 18 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,21 @@
1-
import { ChangeDetectionStrategy, Component, computed, DestroyRef, signal, inject } from '@angular/core';
1+
import { ChangeDetectionStrategy, Component, computed, DestroyRef, inject, signal } from '@angular/core';
22
import { Store } from '@ngrx/store';
33
import {
4-
selectCurrentFeatureForEdit,
5-
selectCurrentlySelectedFeature,
6-
selectFeatureInfoDialogCollapsed,
7-
selectFeatureInfoDialogVisible, selectFeatureInfoLayerListCollapsed, selectFeatureInfoLayers,
8-
selectIsNextButtonDisabled,
9-
selectIsPrevButtonDisabled, selectSelectedFeatureInfoLayer,
4+
selectCurrentFeatureForEdit, selectCurrentlySelectedFeature, selectFeatureInfoDialogCollapsed, selectFeatureInfoDialogVisible,
5+
selectFeatureInfoLayerListCollapsed, selectFeatureInfoLayers, selectIsNextButtonDisabled, selectIsPrevButtonDisabled,
6+
selectSelectedFeatureInfoLayer,
107
} from '../state/feature-info.selectors';
11-
import { map, Observable, combineLatest, take } from 'rxjs';
8+
import { combineLatest, map, Observable, take } from 'rxjs';
129
import {
1310
expandCollapseFeatureInfoDialog, expandCollapseFeatureInfoLayerList, hideFeatureInfoDialog, showNextFeatureInfoFeature,
1411
showPreviousFeatureInfoFeature,
1512
} from '../state/feature-info.actions';
16-
import { FeatureInfoModel } from '../models/feature-info.model';
1713
import { CssHelper } from '@tailormap-viewer/shared';
1814
import { FeatureInfoLayerModel } from '../models/feature-info-layer.model';
1915
import { FeatureInfoLayerListItemModel } from '../models/feature-info-layer-list-item.model';
2016
import { FeatureInfoHelper } from '../helpers/feature-info.helper';
2117
import { BreakpointObserver } from '@angular/cdk/layout';
22-
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
18+
import { takeUntilDestroyed, toSignal } from '@angular/core/rxjs-interop';
2319
import { setLoadedEditFeature } from '../../edit/state/edit.actions';
2420
import { AuthenticatedUserService, BaseComponentTypeEnum, FeatureInfoConfigModel } from '@tailormap-viewer/api';
2521
import { ComponentConfigHelper } from '../../../shared/helpers/component-config.helper';
@@ -40,32 +36,38 @@ export class FeatureInfoDialogComponent {
4036

4137
public dialogOpen$: Observable<boolean>;
4238
public dialogCollapsed$: Observable<boolean>;
43-
public currentFeature$: Observable<FeatureInfoModel | null>;
39+
public currentFeature = toSignal(this.store$.select(selectCurrentlySelectedFeature), { initialValue: null });
4440
public selectedLayer$: Observable<FeatureInfoLayerModel | null>;
4541
public selectedSingleLayer$: Observable<FeatureInfoLayerModel | null>;
4642
public isPrevButtonDisabled$: Observable<boolean>;
4743
public isNextButtonDisabled$: Observable<boolean>;
48-
public isEditPossible$: Observable<boolean>;
4944

5045
public panelWidth = 600;
5146
public panelWidthCollapsed = 300;
5247

5348
private bodyMargin = CssHelper.getCssVariableValueNumeric('--body-margin');
5449
public panelWidthMargin = CssHelper.getCssVariableValueNumeric('--menubar-width') + (this.bodyMargin * 2);
5550

56-
public showEditButtonConfig: boolean = true;
51+
public config = ComponentConfigHelper.componentConfigSignal<FeatureInfoConfigModel>(this.store$, BaseComponentTypeEnum.FEATURE_INFO);
52+
public editComponentEnabled= ComponentConfigHelper.componentEnabledConfigSignal(this.store$, BaseComponentTypeEnum.EDIT);
53+
private authenticatedUserDetails = toSignal(this.authenticatedUserService.getUserDetails$());
54+
55+
public isEditPossible = computed(() => {
56+
const showEditButton = !(this.config()?.showEditButton === false);
57+
return showEditButton
58+
&& this.currentFeature()?.layer?.editable
59+
&& this.authenticatedUserDetails()?.isAuthenticated // remove when HTM-1762 is implemented
60+
&& this.editComponentEnabled();
61+
});
5762

5863
public isWideScreen = signal<boolean>(false);
5964
public expandedList = signal<boolean>(false);
6065
public attributesCollapsed = signal<boolean>(false);
6166
public toggleIcon = computed(() => this.attributesCollapsed() ? 'chevron_top' : 'chevron_bottom');
6267

6368
constructor() {
64-
const store$ = this.store$;
65-
6669
this.dialogOpen$ = this.store$.select(selectFeatureInfoDialogVisible);
6770
this.dialogCollapsed$ = this.store$.select(selectFeatureInfoDialogCollapsed);
68-
this.currentFeature$ = this.store$.select(selectCurrentlySelectedFeature);
6971
this.selectedLayer$ = this.store$.select(selectSelectedFeatureInfoLayer);
7072
this.selectedSingleLayer$ = combineLatest([
7173
this.store$.select(selectSelectedFeatureInfoLayer),
@@ -77,27 +79,8 @@ export class FeatureInfoDialogComponent {
7779
return null;
7880
}));
7981

80-
ComponentConfigHelper.useInitialConfigForComponent<FeatureInfoConfigModel>(
81-
store$,
82-
BaseComponentTypeEnum.FEATURE_INFO,
83-
config => {
84-
this.showEditButtonConfig = config.showEditButton ?? true;
85-
},
86-
);
87-
8882
this.isPrevButtonDisabled$ = this.store$.select(selectIsPrevButtonDisabled);
8983
this.isNextButtonDisabled$ = this.store$.select(selectIsNextButtonDisabled);
90-
this.isEditPossible$ = combineLatest([
91-
this.authenticatedUserService.getUserDetails$(),
92-
this.currentFeature$,
93-
]).pipe(
94-
takeUntilDestroyed(this.destroyRef),
95-
map(([ userDetails, feature ]) => {
96-
const isAuthenticated = userDetails.isAuthenticated;
97-
const isLayerEditable = feature?.layer?.editable ?? false;
98-
return isAuthenticated && isLayerEditable;
99-
}),
100-
);
10184

10285
combineLatest([
10386
this.store$.select(selectFeatureInfoLayerListCollapsed),

0 commit comments

Comments
 (0)