Skip to content

fix(filter-bar): added onClosePipe output (#DS-3769) #755

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion packages/components-dev/filter-bar/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
KbqFilter,
KbqFilterBar,
KbqFilterBarModule,
KbqPipe,
KbqPipeTemplate,
KbqPipeTypes
} from '@koobiq/components/filter-bar';
Expand Down Expand Up @@ -170,6 +171,7 @@ export class DevApp implements AfterViewInit {
pipes: [
{
name: 'required',
id: 'MultiSelect',
value: [
{ name: 'Не определен', id: '1' },
{ name: 'Легитимное действие', id: '2' }
Expand All @@ -182,6 +184,7 @@ export class DevApp implements AfterViewInit {
},
{
name: 'required',
id: 'MultiSelect',
value: [{ name: 'Не определен', id: '1' }],
type: KbqPipeTypes.MultiSelect,

Expand All @@ -191,6 +194,7 @@ export class DevApp implements AfterViewInit {
},
{
name: 'empty',
id: 'MultiSelect',
type: KbqPipeTypes.MultiSelect,
value: null,

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

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

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

Expand Down Expand Up @@ -583,7 +590,7 @@ export class DevApp implements AfterViewInit {
}
];
pipeTemplates: KbqPipeTemplate[];
defaultFilter: KbqFilter | null = this.filters[9];
defaultFilter: KbqFilter | null = this.filters[1];
activeFilter: KbqFilter | null = this.defaultFilter;

ngAfterViewInit(): void {
Expand Down Expand Up @@ -630,6 +637,7 @@ export class DevApp implements AfterViewInit {
},
{
name: 'MultiSelect',
id: 'MultiSelect',
type: KbqPipeTypes.MultiSelect,
values: [
{ name: 'Option 1', id: '1', type: 'error' },
Expand Down Expand Up @@ -820,4 +828,8 @@ export class DevApp implements AfterViewInit {
onSearch(value: string) {
console.log('onSearch: ', value);
}

onClosePipe($event: KbqPipe) {
console.log('onClosePipe: ', $event);
}
}
1 change: 1 addition & 0 deletions packages/components-dev/filter-bar/template.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
[pipeTemplates]="pipeTemplates"
[(filter)]="activeFilter"
(filterChange)="onFilterChange($event)"
(onClosePipe)="onClosePipe($event)"
>
<kbq-filters
[filters]="filters"
Expand Down
2 changes: 2 additions & 0 deletions packages/components/filter-bar/filter-bar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ export class KbqFilterBar {
@Output() readonly onChangePipe = new EventEmitter<KbqPipe>();
/** Event that emits whenever the pipe deleted. */
@Output() readonly onRemovePipe = new EventEmitter<KbqPipe>();
/** Event that emits whenever the select or multiselect pipe closed. */
@Output() readonly onClosePipe = new EventEmitter<KbqPipe>();

/** Whether the current filter is saved and changed */
get isSavedAndChanged(): boolean {
Expand Down
3 changes: 3 additions & 0 deletions packages/components/filter-bar/pipes/base-pipe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {
afterNextRender,
AfterViewInit,
ChangeDetectorRef,
DestroyRef,
Directive,
ElementRef,
inject,
Expand Down Expand Up @@ -45,6 +46,8 @@ export abstract class KbqBasePipe<V> implements AfterViewInit {
protected readonly filterBar = inject(KbqFilterBar, { optional: true });
/** @docs-private */
protected readonly changeDetectorRef = inject(ChangeDetectorRef);
/** @docs-private */
protected readonly destroyRef = inject(DestroyRef);

/** values to select from the pipe template */
protected values;
Expand Down
13 changes: 12 additions & 1 deletion packages/components/filter-bar/pipes/pipe-multi-select.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { AsyncPipe, NgClass, NgTemplateOutlet } from '@angular/common';
import {
AfterViewInit,
ChangeDetectionStrategy,
Component,
OnInit,
Expand All @@ -8,6 +9,7 @@ import {
ViewChildren,
ViewEncapsulation
} from '@angular/core';
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
import { FormsModule, ReactiveFormsModule, UntypedFormControl } from '@angular/forms';
import { KbqBadgeModule } from '@koobiq/components/badge';
import { KbqButtonModule } from '@koobiq/components/button';
Expand Down Expand Up @@ -59,7 +61,7 @@ import { KbqPipeTitleDirective } from './pipe-title';
KbqPseudoCheckboxModule
]
})
export class KbqPipeMultiSelectComponent extends KbqBasePipe<KbqSelectValue[]> implements OnInit {
export class KbqPipeMultiSelectComponent extends KbqBasePipe<KbqSelectValue[]> implements AfterViewInit, OnInit {
/** control for search options */
searchControl: UntypedFormControl = new UntypedFormControl();
/** filtered by search options */
Expand Down Expand Up @@ -110,6 +112,15 @@ export class KbqPipeMultiSelectComponent extends KbqBasePipe<KbqSelectValue[]> i
);
}

/** @docs-private */
override ngAfterViewInit() {
super.ngAfterViewInit();

this.select.closedStream
.pipe(takeUntilDestroyed(this.destroyRef))
.subscribe(() => this.filterBar?.onClosePipe.next(this.data));
}

/** @docs-private */
onSelect(item: KbqSelectValue[]) {
this.data.value = item;
Expand Down
15 changes: 13 additions & 2 deletions packages/components/filter-bar/pipes/pipe-select.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { AsyncPipe, NgClass, NgTemplateOutlet } from '@angular/common';
import { ChangeDetectionStrategy, Component, OnInit, ViewChild, ViewEncapsulation } from '@angular/core';
import { AfterViewInit, ChangeDetectionStrategy, Component, OnInit, ViewChild, ViewEncapsulation } from '@angular/core';
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
import { ReactiveFormsModule, UntypedFormControl } from '@angular/forms';
import { KbqButtonModule } from '@koobiq/components/button';
import { KbqDividerModule } from '@koobiq/components/divider';
Expand Down Expand Up @@ -47,7 +48,7 @@ import { KbqPipeTitleDirective } from './pipe-title';
AsyncPipe
]
})
export class KbqPipeSelectComponent extends KbqBasePipe<KbqSelectValue> implements OnInit {
export class KbqPipeSelectComponent extends KbqBasePipe<KbqSelectValue> implements AfterViewInit, OnInit {
/** control for search options */
searchControl: UntypedFormControl = new UntypedFormControl();
/** filtered by search options */
Expand All @@ -66,13 +67,23 @@ export class KbqPipeSelectComponent extends KbqBasePipe<KbqSelectValue> implemen
return !this.data.value;
}

/** @docs-private */
ngOnInit(): void {
this.filteredOptions = merge(
of(this.values),
this.searchControl.valueChanges.pipe(map((value) => this.getFilteredOptions(value)))
);
}

/** @docs-private */
override ngAfterViewInit() {
super.ngAfterViewInit();

this.select.closedStream
.pipe(takeUntilDestroyed(this.destroyRef))
.subscribe(() => this.filterBar?.onClosePipe.next(this.data));
}

onSelect(item: KbqSelectValue) {
this.data.value = item;
this.filterBar?.onChangePipe.emit(this.data);
Expand Down
12 changes: 8 additions & 4 deletions tools/public_api_guard/components/filter-bar.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { AfterContentInit } from '@angular/core';
import { AfterViewInit } from '@angular/core';
import { BehaviorSubject } from 'rxjs';
import { ChangeDetectorRef } from '@angular/core';
import { DestroyRef } from '@angular/core';
import { ElementRef } from '@angular/core';
import { EventEmitter } from '@angular/core';
import { FormControl } from '@angular/forms';
Expand Down Expand Up @@ -102,6 +103,7 @@ export abstract class KbqBasePipe<V> implements AfterViewInit {
constructor();
protected readonly changeDetectorRef: ChangeDetectorRef;
readonly data: KbqPipeData<V>;
protected readonly destroyRef: DestroyRef;
protected readonly filterBar: KbqFilterBar | null;
get isEmpty(): boolean;
isMac: boolean;
Expand Down Expand Up @@ -172,6 +174,7 @@ export class KbqFilterBar {
get isSavedAndChanged(): boolean;
protected readonly localeService: KbqLocaleService | null;
readonly onChangePipe: EventEmitter<KbqPipe>;
readonly onClosePipe: EventEmitter<KbqPipe>;
readonly onRemovePipe: EventEmitter<KbqPipe>;
readonly openPipe: BehaviorSubject<string | number | null>;
get pipeTemplates(): KbqPipeTemplate[];
Expand All @@ -181,7 +184,7 @@ export class KbqFilterBar {
restoreFilterState(filter?: KbqFilter): void;
saveFilterState(filter?: KbqFilter): void;
// (undocumented)
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>;
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>;
// (undocumented)
static ɵfac: i0.ɵɵFactoryDeclaration<KbqFilterBar, never>;
}
Expand Down Expand Up @@ -507,11 +510,12 @@ export class KbqPipeMinWidth {
}

// @public (undocumented)
export class KbqPipeMultiSelectComponent extends KbqBasePipe<KbqSelectValue[]> implements OnInit {
export class KbqPipeMultiSelectComponent extends KbqBasePipe<KbqSelectValue[]> implements AfterViewInit, OnInit {
get checkboxState(): KbqPseudoCheckboxState;
compareByValue: (o1: any, o2: any) => boolean;
filteredOptions: Observable<any[]>;
get isEmpty(): boolean;
ngAfterViewInit(): void;
ngOnInit(): void;
onClear(): void;
onSelect(item: KbqSelectValue[]): void;
Expand Down Expand Up @@ -539,11 +543,11 @@ export class KbqPipeReadonlyComponent extends KbqBasePipe<string | null> {
}

// @public (undocumented)
export class KbqPipeSelectComponent extends KbqBasePipe<KbqSelectValue> implements OnInit {
export class KbqPipeSelectComponent extends KbqBasePipe<KbqSelectValue> implements AfterViewInit, OnInit {
compareByValue: (o1: any, o2: any) => boolean;
filteredOptions: Observable<any[]>;
get isEmpty(): boolean;
// (undocumented)
ngAfterViewInit(): void;
ngOnInit(): void;
// (undocumented)
onSelect(item: KbqSelectValue): void;
Expand Down