Skip to content

Commit

Permalink
fix(filter): show "select all" and "clear" buttons to facilitate comp…
Browse files Browse the repository at this point in the history
…lex filter settings (#2245)

closes #2222

---------

Co-authored-by: Sebastian Leidig <sebastian@aam-digital.com>
  • Loading branch information
sadaf895 and sleidig authored Mar 7, 2024
1 parent d3ccaba commit a2d833e
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/app/core/filter/list-filter/list-filter.component.html
Original file line number Diff line number Diff line change
@@ -1,11 +1,22 @@
<mat-form-field appearance="fill" class="full-width">
<mat-label>{{ filterConfig.label || filterConfig.name }}</mat-label>

<mat-select
[id]="filterConfig.name"
[(value)]="selectedOptions"
(valueChange)="selectedOptionChange.emit($event)"
multiple
>
<!-- SELECT ALL / CLEAR -->
<div class="flex-row">
<button mat-flat-button i18n class="util-button" (click)="selectAll()">
Select All
</button>
<button mat-flat-button i18n class="util-button" (click)="deselectAll()">
Clear
</button>
</div>

@for (option of filterConfig.options; track option.key) {
<mat-option
[value]="option.key"
Expand Down
5 changes: 5 additions & 0 deletions src/app/core/filter/list-filter/list-filter.component.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.util-button {
flex-basis: 50%;
border-radius: 0;
font-size: 0.8rem;
}
16 changes: 16 additions & 0 deletions src/app/core/filter/list-filter/list-filter.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,21 @@ import { BorderHighlightDirective } from "../../common-components/border-highlig
import { JsonPipe, NgForOf } from "@angular/common";
import { ReactiveFormsModule } from "@angular/forms";
import { SelectableFilter } from "../filters/filters";
import { MatButtonModule } from "@angular/material/button";

@Component({
selector: "app-list-filter",
templateUrl: "./list-filter.component.html",
styleUrls: ["./list-filter.component.scss"],
imports: [
MatFormFieldModule,
MatSelectModule,
ReactiveFormsModule,
BorderHighlightDirective,
NgForOf,
JsonPipe,
MatButtonModule,
ReactiveFormsModule,
],
standalone: true,
})
Expand All @@ -25,4 +29,16 @@ export class ListFilterComponent<E extends Entity> {
filterConfig: SelectableFilter<E>;
@Input() selectedOptions: string[];
@Output() selectedOptionChange: EventEmitter<string[]> = new EventEmitter();

selectAll() {
this.selectedOptions = this.filterConfig.options.map(
(option) => option.key,
);
this.selectedOptionChange.emit(this.selectedOptions);
}

deselectAll() {
this.selectedOptions = [];
this.selectedOptionChange.emit(this.selectedOptions);
}
}
37 changes: 37 additions & 0 deletions src/app/core/filter/list-filter/list-filter.stories.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { applicationConfig, Meta, StoryFn } from "@storybook/angular";
import { StorybookBaseModule } from "../../../utils/storybook-base.module";
import { importProvidersFrom } from "@angular/core";
import { ListFilterComponent } from "./list-filter.component";
import { Entity } from "../../entity/model/entity";
import { FilterConfig } from "../../entity-list/EntityListConfig";

export default {
title: "Core/> App Layout/Filter",
component: ListFilterComponent<Entity>,
decorators: [
applicationConfig({
providers: [importProvidersFrom(StorybookBaseModule)],
}),
],
} as Meta;

const Template: StoryFn<ListFilterComponent<Entity>> = (
args: ListFilterComponent<Entity>,
) => ({
component: ListFilterComponent<Entity>,
props: args,
});

const filterConfig: FilterConfig = {
id: "isActive",
label: "Active",
options: [
{ key: "true", label: "Yes", filter: { isActive: true } },
{ key: "false", label: "No", filter: { isActive: false } },
],
};

export const Default = Template.bind({});
Default.args = {
filterConfig,
};

0 comments on commit a2d833e

Please sign in to comment.