Pull request #9: UpdateFilterService

Merge in SL/common-ui from updateFilterService to master

* commit '6c79b02a50f268a6b663e8e46d88f3c0d333a608':
  some instead of find && children checked = true
  'unknown' type for result in dialog service
  checkChildren in toggleFilter method
  refactor filtersEnabled method
  added filtersEnabled by group slug method
This commit is contained in:
Eduard Cziszter 2022-01-28 07:10:19 +01:00 committed by Dan Percic
commit 31b60ff117
2 changed files with 16 additions and 2 deletions

View File

@ -37,7 +37,7 @@ export class FilterService {
this._refresh$.next(true);
}
toggleFilter(filterGroupSlug: string, key: string): void {
toggleFilter(filterGroupSlug: string, key: string, checkChildren = false): void {
const filters = this.filterGroups.find(group => group.slug === filterGroupSlug)?.filters;
if (!filters) {
return console.error(`Cannot find filter group "${filterGroupSlug}"`);
@ -53,6 +53,10 @@ export class FilterService {
if (found) {
found.checked = !found.checked;
if (checkChildren && found.checked && found instanceof NestedFilter) {
found.children.forEach(c => (c.checked = true));
}
}
this.refresh();
@ -99,6 +103,16 @@ export class FilterService {
);
}
filtersEnabled(filterGroupSlug: string): boolean {
const group = this.getGroup(filterGroupSlug);
if (!group) {
return false;
}
return group.filters.some(filter => filter.checked || filter.children.some(c => c.checked));
}
reset(): void {
this.filterGroups.forEach(group => {
group.filters.forEach(filter => {

View File

@ -49,7 +49,7 @@ export abstract class DialogService<T extends string> {
data,
});
const fn = async result => {
const fn = async (result: unknown) => {
if (result && cb) {
await cb(result);
}