@@ -22,6 +22,7 @@ import {
2222 ConditionConfig ,
2323 FilterConfig ,
2424} from "../../../shared/modules/filters/filters.module" ;
25+ import { isEqual } from "lodash-es" ;
2526
2627@Component ( {
2728 selector : "app-type-datasets-filter-settings" ,
@@ -55,6 +56,15 @@ export class DatasetsFilterSettingsComponent {
5556 . subscribe ( ( res ) => {
5657 if ( res ) {
5758 const { data } = res ;
59+
60+ // If the condition already exists, do nothing
61+ const existingConditionIndex = this . data . conditionConfigs . findIndex (
62+ ( config ) => isEqual ( config . condition , data ) ,
63+ ) ;
64+ if ( existingConditionIndex !== - 1 ) {
65+ console . log ( "Condition already exists" ) ;
66+ return ;
67+ }
5868 const condition = this . toggleCondition ( {
5969 condition : data ,
6070 enabled : false ,
@@ -77,30 +87,33 @@ export class DatasetsFilterSettingsComponent {
7787 if ( res ) {
7888 const { data } = res ;
7989
80- if ( data !== condition . condition ) {
81- this . store . dispatch (
82- removeScientificConditionAction ( {
83- condition : condition . condition ,
84- } ) ,
85- ) ;
86- this . store . dispatch (
87- deselectColumnAction ( {
88- name : condition . condition . lhs ,
89- columnType : "custom" ,
90- } ) ,
91- ) ;
92-
93- this . data . conditionConfigs [ i ] = {
94- ...condition ,
95- condition : data ,
96- } ;
97- this . store . dispatch (
98- addScientificConditionAction ( { condition : data } ) ,
99- ) ;
100- this . store . dispatch (
101- selectColumnAction ( { name : data . lhs , columnType : "custom" } ) ,
102- ) ;
90+ // If the condition is unchanged, do nothing
91+ if ( isEqual ( condition . condition , data ) ) {
92+ return ;
10393 }
94+
95+ this . store . dispatch (
96+ removeScientificConditionAction ( {
97+ condition : condition . condition ,
98+ } ) ,
99+ ) ;
100+ this . store . dispatch (
101+ deselectColumnAction ( {
102+ name : condition . condition . lhs ,
103+ columnType : "custom" ,
104+ } ) ,
105+ ) ;
106+
107+ this . data . conditionConfigs [ i ] = {
108+ ...condition ,
109+ condition : data ,
110+ } ;
111+ this . store . dispatch (
112+ addScientificConditionAction ( { condition : data } ) ,
113+ ) ;
114+ this . store . dispatch (
115+ selectColumnAction ( { name : data . lhs , columnType : "custom" } ) ,
116+ ) ;
104117 }
105118 } ) ;
106119 }
0 commit comments