@@ -22,6 +22,7 @@ import { ContextService } from '../../../../services/context/context.service';
22
22
import { Router } from '@angular/router' ;
23
23
import { SummaryCardFormT } from '../../summary-card-settings/summary-card-settings.component' ;
24
24
import { DashboardAutomationService } from '../../../../services/dashboard-automation/dashboard-automation.service' ;
25
+ import { isEqual , set } from 'lodash' ;
25
26
26
27
/**
27
28
* Content component of Single Item of Summary Card.
@@ -68,6 +69,8 @@ export class SummaryCardItemContentComponent
68
69
onContentClick ( event : any ) {
69
70
let filterButtonIsClicked = ! ! event . target . dataset . filterField ;
70
71
let currentNode = event . target ;
72
+ const currentFilters = { ...this . contextService . filter . getValue ( ) } ;
73
+ const updatedFilters = { ...currentFilters } ;
71
74
// Check for filter fields
72
75
if ( ! filterButtonIsClicked ) {
73
76
// 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
84
87
// Cleanup filter value from the span set by default in the tinymce calculated field if exists
85
88
const cleanContent = filterValue . match ( / (?< = > ) ( .* ?) (? = < ) / gi) ;
86
89
const cleanFilterValue = cleanContent ? cleanContent [ 0 ] : filterValue ;
87
- const currentFilters = { ...this . contextService . filter . getValue ( ) } ;
88
90
// If current filters contains the field but there is no value set, delete it
89
91
if ( filterField in currentFilters && ! cleanFilterValue ) {
90
- delete currentFilters [ filterField ] ;
92
+ delete updatedFilters [ filterField ] ;
91
93
}
92
94
// 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
+ }
100
98
}
101
99
102
100
// Check for automation rules
@@ -140,16 +138,17 @@ export class SummaryCardItemContentComponent
140
138
const resetList = currentNode . dataset . filterReset
141
139
. split ( ';' )
142
140
. 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 ] ;
150
145
}
151
146
}
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 ) ;
153
152
}
154
153
155
154
const content = this . htmlContentComponent . el . nativeElement ;
0 commit comments