Skip to content

Commit

Permalink
* fixed issue with filter values selection if not applying filter (#345)
Browse files Browse the repository at this point in the history
  • Loading branch information
agnybida committed Nov 10, 2024
1 parent 005f7a3 commit 20a7cc8
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 5 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "deep-see-web",
"version": "4.0.15",
"version": "4.0.16",
"scripts": {
"ng": "ng",
"start": "ng serve --proxy-config=proxy.conf.samples-bi.js",
Expand Down
33 changes: 29 additions & 4 deletions src/app/components/ui/filter-popup/filter-popup.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
HostBinding,
Inject,
Input,
LOCALE_ID,
LOCALE_ID, OnDestroy,
OnInit,
Pipe,
PipeTransform,
Expand Down Expand Up @@ -52,7 +52,7 @@ export class SelectedFirstPipe implements PipeTransform {
imports: [FormsModule, AutoFocusDirective, DateFilterComponent, I18nPipe, SelectedFirstPipe],
changeDetection: ChangeDetectionStrategy.OnPush
})
export class FilterPopupComponent implements OnInit, AfterViewInit {
export class FilterPopupComponent implements OnInit, AfterViewInit, OnDestroy {
@ViewChild('dateFilter') dateFilter!: DateFilterComponent;
model: IFilterModel = {
search: '',
Expand All @@ -70,6 +70,8 @@ export class FilterPopupComponent implements OnInit, AfterViewInit {
isRelatedFilters = false;
widget!: IWidgetDesc;
private datePipe: DatePipe;
private restoreValuesOnClose = true;
private originalValues?: any[];

constructor(private ss: StorageService,
private el: ElementRef,
Expand Down Expand Up @@ -145,6 +147,9 @@ export class FilterPopupComponent implements OnInit, AfterViewInit {
this.model.isAll = !this.isAnyChecked();
this.model.isExclude = filter.isExclude;
this.model.isInterval = filter.isInterval;
if (this.model.filter.values?.length) {
this.originalValues = this.model.filter.values;
}
}

ngOnInit() {
Expand Down Expand Up @@ -383,6 +388,7 @@ export class FilterPopupComponent implements OnInit, AfterViewInit {
// Update model values
if (newFilters.length && this.model.filter) {
this.model.filter.values = [...newFilters];
this.originalValues = structuredClone(newFilters);
}
// this.model.filter.values.push(...toAdd); // filter.children;

Expand Down Expand Up @@ -412,11 +418,23 @@ export class FilterPopupComponent implements OnInit, AfterViewInit {
}
delete this.model.filter?.fromIdx;
delete this.model.filter?.toIdx;
this.clearSelectedItems();
this.fs.applyFilter(this.model.filter);
this.restoreValuesOnClose = false;
this.close();
}

private clearSelectedItems() {
for (let i = 0; i < this.model.filter?.values.length; i++) {
this.model.filter.values[i].checked = false;
}
this.fs.applyFilter(this.model.filter);
this.close();
}

private restoreSelectionState() {
if (!this.originalValues?.length) {
return;
}
this.model.filter.values = structuredClone(this.originalValues);
}

/**
Expand Down Expand Up @@ -458,6 +476,7 @@ export class FilterPopupComponent implements OnInit, AfterViewInit {

this.fs.applyFilter(this.model.filter);
this.fs.filtersChanged = true;
this.restoreValuesOnClose = false;
this.close();
}

Expand All @@ -483,4 +502,10 @@ export class FilterPopupComponent implements OnInit, AfterViewInit {
private createDate(v: string) {
return this.us.toDate(v.replace('&[', '').replace(']', ''));
}

ngOnDestroy() {
if (this.restoreValuesOnClose) {
this.restoreSelectionState();
}
}
}
3 changes: 3 additions & 0 deletions src/changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#### 4.0.16
* fixed issue with filter values selection if not applying filter (#345)

#### 4.0.15
* changed MDX generation for filters (#341)
* improved filter popup opening time by moving date picker code to deferred loading, only if filter is date(previously loaded always)
Expand Down

0 comments on commit 20a7cc8

Please sign in to comment.