Skip to content

Commit

Permalink
fix(context): trigger the changes on empty result (#1471)
Browse files Browse the repository at this point in the history
  • Loading branch information
alecarn authored Oct 30, 2023
1 parent a68db40 commit 18aebca
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
[checked]="getPermission(user).checked"
[indeterminate]="getPermission(user).indeterminate"
(click)="$event.stopPropagation()"
(change)="userSelection(user)"
(change)="handleToggleCategory(user)"
>
</mat-checkbox>
<span>{{ user.title }}</span>
Expand All @@ -101,7 +101,7 @@
[checked]="getPermission(user).checked"
[indeterminate]="getPermission(user).indeterminate"
(click)="$event.stopPropagation()"
(change)="userSelection(user)"
(change)="handleToggleCategory(user)"
>
</mat-checkbox>
<span>{{ user.title }}</span>
Expand All @@ -116,7 +116,7 @@
<mat-checkbox
[checked]="getPermission(child).checked"
(click)="$event.stopPropagation()"
(change)="userSelection(child, user)"
(change)="handleToggleCategory(child, user)"
>
{{ child.title }}
</mat-checkbox>
Expand Down Expand Up @@ -200,4 +200,8 @@
</igo-context-item>
</ng-template>
</ng-template>

<div *ngIf="isEmpty" class="no-result">
{{ 'igo.context.contextManager.noResult' | translate }}
</div>
</igo-list>
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,7 @@
.actions-container {
margin-left: 4px;
}

.no-result {
padding: 16px;
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,7 @@ import { ActionStore, ActionbarMode } from '@igo2/common';
import { ConfigService, LanguageService, StorageService } from '@igo2/core';
import type { IgoMap } from '@igo2/geo';

import {
BehaviorSubject,
EMPTY,
ReplaySubject,
Subscription,
timer
} from 'rxjs';
import { BehaviorSubject, ReplaySubject, Subscription, timer } from 'rxjs';
import { take } from 'rxjs/operators';
import { debounce } from 'rxjs/operators';

Expand Down Expand Up @@ -58,7 +52,6 @@ export class ContextListComponent implements OnInit, OnDestroy {
}
set contexts(value: ContextsList) {
this._contexts = value;
this.cdRef.detectChanges();
this.next();
}
private _contexts: ContextsList = { ours: [] };
Expand Down Expand Up @@ -155,6 +148,14 @@ export class ContextListComponent implements OnInit, OnDestroy {

public thresholdToFilter = 5;

get isEmpty(): boolean {
return (
!this.contexts.ours.length &&
!this.contexts.public?.length &&
!this.contexts.shared?.length
);
}

constructor(
private cdRef: ChangeDetectorRef,
public configService: ConfigService,
Expand All @@ -168,15 +169,7 @@ export class ContextListComponent implements OnInit, OnDestroy {

ngOnInit() {
this.change$$ = this.change$
.pipe(
debounce(() => {
return this.contexts.ours.length === 0 &&
this.contexts.public?.length === 0 &&
this.contexts.shared?.length === 0
? EMPTY
: timer(50);
})
)
.pipe(debounce(() => timer(50)))
.subscribe(() => {
this.contexts$.next(this.filterContextsList(this.contexts));
});
Expand Down Expand Up @@ -215,7 +208,7 @@ export class ContextListComponent implements OnInit, OnDestroy {
this.change$.next();
}

private filterContextsList(contexts: ContextsList) {
private filterContextsList(contexts: ContextsList): ContextsList {
if (this.term === '') {
if (this.sortedAlpha) {
contexts = this.sortContextsList(contexts);
Expand Down Expand Up @@ -372,7 +365,7 @@ export class ContextListComponent implements OnInit, OnDestroy {
}
}

userSelection(user, parent?) {
handleToggleCategory(user, parent?) {
const permission = this.getPermission(user);
if (permission) {
permission.checked = !permission.checked;
Expand Down
3 changes: 2 additions & 1 deletion packages/context/src/locale/en.context.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@
"contextMapTooltip": "Create a new context from map layers",
"hide": "Hide this context",
"show": "Show up this context",
"showHidden": "Show hidden contexts"
"showHidden": "Show hidden contexts",
"noResult": "No results for selected filters"
},
"contextImportExport": {
"export": {
Expand Down
3 changes: 2 additions & 1 deletion packages/context/src/locale/fr.context.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@
"contextMapTooltip": "Créer un nouveau contexte à partir des couches la carte",
"hide": "Masquer ce contexte",
"show": "Montrer ce contexte",
"showHidden": "Montrer les contextes masqués"
"showHidden": "Montrer les contextes masqués",
"noResult": "Aucun résultat pour les filtres sélectionnés"
},
"contextImportExport": {
"export": {
Expand Down

0 comments on commit 18aebca

Please sign in to comment.