Skip to content

Commit af6346e

Browse files
authored
fix(filter-bar): added onClosePipe output (#DS-3769) (#755)
1 parent a11ba4d commit af6346e

File tree

7 files changed

+52
-8
lines changed

7 files changed

+52
-8
lines changed

packages/components-dev/filter-bar/module.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import {
1818
KbqFilter,
1919
KbqFilterBar,
2020
KbqFilterBarModule,
21+
KbqPipe,
2122
KbqPipeTemplate,
2223
KbqPipeTypes
2324
} from '@koobiq/components/filter-bar';
@@ -170,6 +171,7 @@ export class DevApp implements AfterViewInit {
170171
pipes: [
171172
{
172173
name: 'required',
174+
id: 'MultiSelect',
173175
value: [
174176
{ name: 'Не определен', id: '1' },
175177
{ name: 'Легитимное действие', id: '2' }
@@ -182,6 +184,7 @@ export class DevApp implements AfterViewInit {
182184
},
183185
{
184186
name: 'required',
187+
id: 'MultiSelect',
185188
value: [{ name: 'Не определен', id: '1' }],
186189
type: KbqPipeTypes.MultiSelect,
187190

@@ -191,6 +194,7 @@ export class DevApp implements AfterViewInit {
191194
},
192195
{
193196
name: 'empty',
197+
id: 'MultiSelect',
194198
type: KbqPipeTypes.MultiSelect,
195199
value: null,
196200

@@ -200,6 +204,7 @@ export class DevApp implements AfterViewInit {
200204
},
201205
{
202206
name: 'cleanable',
207+
id: 'MultiSelect',
203208
value: [{ name: 'Не определен', id: '1' }],
204209
type: KbqPipeTypes.MultiSelect,
205210

@@ -209,6 +214,7 @@ export class DevApp implements AfterViewInit {
209214
},
210215
{
211216
name: 'removable',
217+
id: 'MultiSelect',
212218
value: [{ name: 'Не определен', id: '1' }],
213219
type: KbqPipeTypes.MultiSelect,
214220

@@ -218,6 +224,7 @@ export class DevApp implements AfterViewInit {
218224
},
219225
{
220226
name: 'disabled',
227+
id: 'MultiSelect',
221228
value: [{ name: 'Не определен', id: '1' }],
222229
type: KbqPipeTypes.MultiSelect,
223230

@@ -583,7 +590,7 @@ export class DevApp implements AfterViewInit {
583590
}
584591
];
585592
pipeTemplates: KbqPipeTemplate[];
586-
defaultFilter: KbqFilter | null = this.filters[9];
593+
defaultFilter: KbqFilter | null = this.filters[1];
587594
activeFilter: KbqFilter | null = this.defaultFilter;
588595

589596
ngAfterViewInit(): void {
@@ -630,6 +637,7 @@ export class DevApp implements AfterViewInit {
630637
},
631638
{
632639
name: 'MultiSelect',
640+
id: 'MultiSelect',
633641
type: KbqPipeTypes.MultiSelect,
634642
values: [
635643
{ name: 'Option 1', id: '1', type: 'error' },
@@ -820,4 +828,8 @@ export class DevApp implements AfterViewInit {
820828
onSearch(value: string) {
821829
console.log('onSearch: ', value);
822830
}
831+
832+
onClosePipe($event: KbqPipe) {
833+
console.log('onClosePipe: ', $event);
834+
}
823835
}

packages/components-dev/filter-bar/template.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
[pipeTemplates]="pipeTemplates"
1111
[(filter)]="activeFilter"
1212
(filterChange)="onFilterChange($event)"
13+
(onClosePipe)="onClosePipe($event)"
1314
>
1415
<kbq-filters
1516
[filters]="filters"

packages/components/filter-bar/filter-bar.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,8 @@ export class KbqFilterBar {
105105
@Output() readonly onChangePipe = new EventEmitter<KbqPipe>();
106106
/** Event that emits whenever the pipe deleted. */
107107
@Output() readonly onRemovePipe = new EventEmitter<KbqPipe>();
108+
/** Event that emits whenever the select or multiselect pipe closed. */
109+
@Output() readonly onClosePipe = new EventEmitter<KbqPipe>();
108110

109111
/** Whether the current filter is saved and changed */
110112
get isSavedAndChanged(): boolean {

packages/components/filter-bar/pipes/base-pipe.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import {
22
afterNextRender,
33
AfterViewInit,
44
ChangeDetectorRef,
5+
DestroyRef,
56
Directive,
67
ElementRef,
78
inject,
@@ -45,6 +46,8 @@ export abstract class KbqBasePipe<V> implements AfterViewInit {
4546
protected readonly filterBar = inject(KbqFilterBar, { optional: true });
4647
/** @docs-private */
4748
protected readonly changeDetectorRef = inject(ChangeDetectorRef);
49+
/** @docs-private */
50+
protected readonly destroyRef = inject(DestroyRef);
4851

4952
/** values to select from the pipe template */
5053
protected values;

packages/components/filter-bar/pipes/pipe-multi-select.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { AsyncPipe, NgClass, NgTemplateOutlet } from '@angular/common';
22
import {
3+
AfterViewInit,
34
ChangeDetectionStrategy,
45
Component,
56
OnInit,
@@ -8,6 +9,7 @@ import {
89
ViewChildren,
910
ViewEncapsulation
1011
} from '@angular/core';
12+
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
1113
import { FormsModule, ReactiveFormsModule, UntypedFormControl } from '@angular/forms';
1214
import { KbqBadgeModule } from '@koobiq/components/badge';
1315
import { KbqButtonModule } from '@koobiq/components/button';
@@ -59,7 +61,7 @@ import { KbqPipeTitleDirective } from './pipe-title';
5961
KbqPseudoCheckboxModule
6062
]
6163
})
62-
export class KbqPipeMultiSelectComponent extends KbqBasePipe<KbqSelectValue[]> implements OnInit {
64+
export class KbqPipeMultiSelectComponent extends KbqBasePipe<KbqSelectValue[]> implements AfterViewInit, OnInit {
6365
/** control for search options */
6466
searchControl: UntypedFormControl = new UntypedFormControl();
6567
/** filtered by search options */
@@ -110,6 +112,15 @@ export class KbqPipeMultiSelectComponent extends KbqBasePipe<KbqSelectValue[]> i
110112
);
111113
}
112114

115+
/** @docs-private */
116+
override ngAfterViewInit() {
117+
super.ngAfterViewInit();
118+
119+
this.select.closedStream
120+
.pipe(takeUntilDestroyed(this.destroyRef))
121+
.subscribe(() => this.filterBar?.onClosePipe.next(this.data));
122+
}
123+
113124
/** @docs-private */
114125
onSelect(item: KbqSelectValue[]) {
115126
this.data.value = item;

packages/components/filter-bar/pipes/pipe-select.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { AsyncPipe, NgClass, NgTemplateOutlet } from '@angular/common';
2-
import { ChangeDetectionStrategy, Component, OnInit, ViewChild, ViewEncapsulation } from '@angular/core';
2+
import { AfterViewInit, ChangeDetectionStrategy, Component, OnInit, ViewChild, ViewEncapsulation } from '@angular/core';
3+
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
34
import { ReactiveFormsModule, UntypedFormControl } from '@angular/forms';
45
import { KbqButtonModule } from '@koobiq/components/button';
56
import { KbqDividerModule } from '@koobiq/components/divider';
@@ -47,7 +48,7 @@ import { KbqPipeTitleDirective } from './pipe-title';
4748
AsyncPipe
4849
]
4950
})
50-
export class KbqPipeSelectComponent extends KbqBasePipe<KbqSelectValue> implements OnInit {
51+
export class KbqPipeSelectComponent extends KbqBasePipe<KbqSelectValue> implements AfterViewInit, OnInit {
5152
/** control for search options */
5253
searchControl: UntypedFormControl = new UntypedFormControl();
5354
/** filtered by search options */
@@ -66,13 +67,23 @@ export class KbqPipeSelectComponent extends KbqBasePipe<KbqSelectValue> implemen
6667
return !this.data.value;
6768
}
6869

70+
/** @docs-private */
6971
ngOnInit(): void {
7072
this.filteredOptions = merge(
7173
of(this.values),
7274
this.searchControl.valueChanges.pipe(map((value) => this.getFilteredOptions(value)))
7375
);
7476
}
7577

78+
/** @docs-private */
79+
override ngAfterViewInit() {
80+
super.ngAfterViewInit();
81+
82+
this.select.closedStream
83+
.pipe(takeUntilDestroyed(this.destroyRef))
84+
.subscribe(() => this.filterBar?.onClosePipe.next(this.data));
85+
}
86+
7687
onSelect(item: KbqSelectValue) {
7788
this.data.value = item;
7889
this.filterBar?.onChangePipe.emit(this.data);

tools/public_api_guard/components/filter-bar.api.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { AfterContentInit } from '@angular/core';
88
import { AfterViewInit } from '@angular/core';
99
import { BehaviorSubject } from 'rxjs';
1010
import { ChangeDetectorRef } from '@angular/core';
11+
import { DestroyRef } from '@angular/core';
1112
import { ElementRef } from '@angular/core';
1213
import { EventEmitter } from '@angular/core';
1314
import { FormControl } from '@angular/forms';
@@ -102,6 +103,7 @@ export abstract class KbqBasePipe<V> implements AfterViewInit {
102103
constructor();
103104
protected readonly changeDetectorRef: ChangeDetectorRef;
104105
readonly data: KbqPipeData<V>;
106+
protected readonly destroyRef: DestroyRef;
105107
protected readonly filterBar: KbqFilterBar | null;
106108
get isEmpty(): boolean;
107109
isMac: boolean;
@@ -172,6 +174,7 @@ export class KbqFilterBar {
172174
get isSavedAndChanged(): boolean;
173175
protected readonly localeService: KbqLocaleService | null;
174176
readonly onChangePipe: EventEmitter<KbqPipe>;
177+
readonly onClosePipe: EventEmitter<KbqPipe>;
175178
readonly onRemovePipe: EventEmitter<KbqPipe>;
176179
readonly openPipe: BehaviorSubject<string | number | null>;
177180
get pipeTemplates(): KbqPipeTemplate[];
@@ -181,7 +184,7 @@ export class KbqFilterBar {
181184
restoreFilterState(filter?: KbqFilter): void;
182185
saveFilterState(filter?: KbqFilter): void;
183186
// (undocumented)
184-
static ɵcmp: i0.ɵɵComponentDeclaration<KbqFilterBar, "kbq-filter-bar, [kbq-filter-bar]", never, { "filter": { "alias": "filter"; "required": false; }; "pipeTemplates": { "alias": "pipeTemplates"; "required": false; }; }, { "filterChange": "filterChange"; "onChangePipe": "onChangePipe"; "onRemovePipe": "onRemovePipe"; }, ["filters", "filterReset"], ["kbq-filters", "*", "kbq-pipe-add", "kbq-filter-reset", "kbq-filter-search, [kbq-filter-search]", "kbq-filter-refresher, [kbq-filter-refresher]"], true, never>;
187+
static ɵcmp: i0.ɵɵComponentDeclaration<KbqFilterBar, "kbq-filter-bar, [kbq-filter-bar]", never, { "filter": { "alias": "filter"; "required": false; }; "pipeTemplates": { "alias": "pipeTemplates"; "required": false; }; }, { "filterChange": "filterChange"; "onChangePipe": "onChangePipe"; "onRemovePipe": "onRemovePipe"; "onClosePipe": "onClosePipe"; }, ["filters", "filterReset"], ["kbq-filters", "*", "kbq-pipe-add", "kbq-filter-reset", "kbq-filter-search, [kbq-filter-search]", "kbq-filter-refresher, [kbq-filter-refresher]"], true, never>;
185188
// (undocumented)
186189
static ɵfac: i0.ɵɵFactoryDeclaration<KbqFilterBar, never>;
187190
}
@@ -507,11 +510,12 @@ export class KbqPipeMinWidth {
507510
}
508511

509512
// @public (undocumented)
510-
export class KbqPipeMultiSelectComponent extends KbqBasePipe<KbqSelectValue[]> implements OnInit {
513+
export class KbqPipeMultiSelectComponent extends KbqBasePipe<KbqSelectValue[]> implements AfterViewInit, OnInit {
511514
get checkboxState(): KbqPseudoCheckboxState;
512515
compareByValue: (o1: any, o2: any) => boolean;
513516
filteredOptions: Observable<any[]>;
514517
get isEmpty(): boolean;
518+
ngAfterViewInit(): void;
515519
ngOnInit(): void;
516520
onClear(): void;
517521
onSelect(item: KbqSelectValue[]): void;
@@ -539,11 +543,11 @@ export class KbqPipeReadonlyComponent extends KbqBasePipe<string | null> {
539543
}
540544

541545
// @public (undocumented)
542-
export class KbqPipeSelectComponent extends KbqBasePipe<KbqSelectValue> implements OnInit {
546+
export class KbqPipeSelectComponent extends KbqBasePipe<KbqSelectValue> implements AfterViewInit, OnInit {
543547
compareByValue: (o1: any, o2: any) => boolean;
544548
filteredOptions: Observable<any[]>;
545549
get isEmpty(): boolean;
546-
// (undocumented)
550+
ngAfterViewInit(): void;
547551
ngOnInit(): void;
548552
// (undocumented)
549553
onSelect(item: KbqSelectValue): void;

0 commit comments

Comments
 (0)