Skip to content

Commit e7a48ba

Browse files
committed
fix: possible conflict between reset filter event and add filter event on widget content click
1 parent 062151e commit e7a48ba

File tree

3 files changed

+32
-35
lines changed

3 files changed

+32
-35
lines changed

apps/web-widgets/src/app/widgets/app-widget/app-widget.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ export class AppWidgetComponent
133133
private shadowDomService: ShadowDomService,
134134
private authService: AuthService
135135
) {
136-
console.log('DEBUG: build from 03/13/2023, v2');
136+
console.log('DEBUG: build from 03/13/2023, v3');
137137
super(el, injector);
138138
this.shadowDomService.shadowRoot = el.nativeElement.shadowRoot;
139139

libs/shared/src/lib/components/widgets/editor/editor.component.ts

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,8 @@ export class EditorComponent extends BaseWidgetComponent implements OnInit {
109109
onContentClick(event: any) {
110110
let filterButtonIsClicked = !!event.target.dataset.filterField;
111111
let currentNode = event.target;
112+
const currentFilters = { ...this.contextService.filter.getValue() };
113+
const updatedFilters = { ...currentFilters };
112114
// Check for filter fields
113115
if (!filterButtonIsClicked) {
114116
// Check parent node if contains the dataset for filtering until we hit the host node or find the node with the filter dataset
@@ -125,19 +127,14 @@ export class EditorComponent extends BaseWidgetComponent implements OnInit {
125127
// Cleanup filter value from the span set by default in the tinymce calculated field if exists
126128
const cleanContent = filterValue.match(/(?<=>)(.*?)(?=<)/gi);
127129
const cleanFilterValue = cleanContent ? cleanContent[0] : filterValue;
128-
const currentFilters = { ...this.contextService.filter.getValue() };
129130
// If current filters contains the field but there is no value set, delete it
130131
if (filterField in currentFilters && !cleanFilterValue) {
131-
delete currentFilters[filterField];
132+
delete updatedFilters[filterField];
132133
}
133134
// Update filter object with existing fields and values
134-
const updatedFilters = {
135-
...(currentFilters && { ...currentFilters }),
136-
...(cleanFilterValue && {
137-
[filterField]: cleanFilterValue,
138-
}),
139-
};
140-
this.contextService.filter.next(updatedFilters);
135+
if (cleanFilterValue) {
136+
set(updatedFilters, filterField, cleanFilterValue);
137+
}
141138
}
142139

143140
// Check for automation rules
@@ -181,16 +178,17 @@ export class EditorComponent extends BaseWidgetComponent implements OnInit {
181178
const resetList = currentNode.dataset.filterReset
182179
.split(';')
183180
.map((item: any) => item.trim());
184-
const updatedFilter: any = {};
185-
for (const [key, value] of Object.entries(
186-
this.contextService.filter.getValue()
187-
)) {
188-
// If key is not in list of fields that need to be cleared, add to updated Filter
189-
if (!resetList.includes(key)) {
190-
updatedFilter[key] = value;
181+
for (const key of Object.keys(updatedFilters)) {
182+
// If key is in list of fields that need to be cleared, remove it
183+
if (resetList.includes(key)) {
184+
delete updatedFilters[key];
191185
}
192186
}
193-
this.contextService.filter.next(updatedFilter);
187+
}
188+
189+
// If filter is affected, update it
190+
if (!isEqual(currentFilters, updatedFilters)) {
191+
this.contextService.filter.next(updatedFilters);
194192
}
195193

196194
const content = this.htmlContentComponent.el.nativeElement;

libs/shared/src/lib/components/widgets/summary-card/summary-card-item-content/summary-card-item-content.component.ts

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import { ContextService } from '../../../../services/context/context.service';
2222
import { Router } from '@angular/router';
2323
import { SummaryCardFormT } from '../../summary-card-settings/summary-card-settings.component';
2424
import { DashboardAutomationService } from '../../../../services/dashboard-automation/dashboard-automation.service';
25+
import { isEqual, set } from 'lodash';
2526

2627
/**
2728
* Content component of Single Item of Summary Card.
@@ -68,6 +69,8 @@ export class SummaryCardItemContentComponent
6869
onContentClick(event: any) {
6970
let filterButtonIsClicked = !!event.target.dataset.filterField;
7071
let currentNode = event.target;
72+
const currentFilters = { ...this.contextService.filter.getValue() };
73+
const updatedFilters = { ...currentFilters };
7174
// Check for filter fields
7275
if (!filterButtonIsClicked) {
7376
// Check parent node if contains the dataset for filtering until we hit the host node or find the node with the filter dataset
@@ -84,19 +87,14 @@ export class SummaryCardItemContentComponent
8487
// Cleanup filter value from the span set by default in the tinymce calculated field if exists
8588
const cleanContent = filterValue.match(/(?<=>)(.*?)(?=<)/gi);
8689
const cleanFilterValue = cleanContent ? cleanContent[0] : filterValue;
87-
const currentFilters = { ...this.contextService.filter.getValue() };
8890
// If current filters contains the field but there is no value set, delete it
8991
if (filterField in currentFilters && !cleanFilterValue) {
90-
delete currentFilters[filterField];
92+
delete updatedFilters[filterField];
9193
}
9294
// Update filter object with existing fields and values
93-
const updatedFilters = {
94-
...(currentFilters && { ...currentFilters }),
95-
...(cleanFilterValue && {
96-
[filterField]: cleanFilterValue,
97-
}),
98-
};
99-
this.contextService.filter.next(updatedFilters);
95+
if (cleanFilterValue) {
96+
set(updatedFilters, filterField, cleanFilterValue);
97+
}
10098
}
10199

102100
// Check for automation rules
@@ -140,16 +138,17 @@ export class SummaryCardItemContentComponent
140138
const resetList = currentNode.dataset.filterReset
141139
.split(';')
142140
.map((item: any) => item.trim());
143-
const updatedFilter: any = {};
144-
for (const [key, value] of Object.entries(
145-
this.contextService.filter.getValue()
146-
)) {
147-
// If key is not in list of fields that need to be cleared, add to updated Filter
148-
if (!resetList.includes(key)) {
149-
updatedFilter[key] = value;
141+
for (const key of Object.keys(updatedFilters)) {
142+
// If key is in list of fields that need to be cleared, remove it
143+
if (resetList.includes(key)) {
144+
delete updatedFilters[key];
150145
}
151146
}
152-
this.contextService.filter.next(updatedFilter);
147+
}
148+
149+
// If filter is affected, update it
150+
if (!isEqual(currentFilters, updatedFilters)) {
151+
this.contextService.filter.next(updatedFilters);
153152
}
154153

155154
const content = this.htmlContentComponent.el.nativeElement;

0 commit comments

Comments
 (0)