Skip to content

Commit f732cfd

Browse files
abdimo101Junjiequan
authored andcommitted
fixed nan issue when typing incomplete scientific notation
1 parent e5707ec commit f732cfd

File tree

1 file changed

+38
-19
lines changed

1 file changed

+38
-19
lines changed

src/app/datasets/datasets-filter/datasets-filter.component.ts

Lines changed: 38 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ export class DatasetsFilterComponent implements OnInit, OnDestroy {
8888

8989
fieldTypeMap: { [key: string]: string } = {};
9090

91+
tempConditionValues: string[] = [];
92+
9193
constructor(
9294
public appConfigService: AppConfigService,
9395
public dialog: MatDialog,
@@ -229,15 +231,47 @@ export class DatasetsFilterComponent implements OnInit, OnDestroy {
229231
});
230232

231233
this.conditionConfigs$.pipe(take(1)).subscribe((conditionConfigs) => {
232-
(conditionConfigs || []).forEach((oldCondition) => {
234+
const updatedConditions = (conditionConfigs || []).map((config, i) => {
235+
if (this.tempConditionValues[i] !== undefined) {
236+
const value = this.tempConditionValues[i];
237+
const isNumeric = value !== "" && !isNaN(Number(value));
238+
if (
239+
config.condition.relation === "EQUAL_TO" ||
240+
config.condition.relation === "EQUAL_TO_NUMERIC" ||
241+
config.condition.relation === "EQUAL_TO_STRING"
242+
) {
243+
return {
244+
...config,
245+
condition: {
246+
...config.condition,
247+
rhs: isNumeric ? Number(value) : value,
248+
relation: isNumeric
249+
? ("EQUAL_TO_NUMERIC" as ScientificCondition["relation"])
250+
: ("EQUAL_TO_STRING" as ScientificCondition["relation"]),
251+
},
252+
};
253+
} else {
254+
return {
255+
...config,
256+
condition: {
257+
...config.condition,
258+
rhs: isNumeric ? Number(value) : value,
259+
},
260+
};
261+
}
262+
}
263+
return config;
264+
});
265+
266+
updatedConditions.forEach((oldCondition) => {
233267
this.store.dispatch(
234268
removeScientificConditionAction({
235269
condition: oldCondition.condition,
236270
}),
237271
);
238272
});
239273

240-
(conditionConfigs || []).forEach((config) => {
274+
updatedConditions.forEach((config) => {
241275
if (config.enabled && config.condition.lhs && config.condition.rhs) {
242276
this.store.dispatch(
243277
addScientificConditionAction({ condition: config.condition }),
@@ -247,7 +281,7 @@ export class DatasetsFilterComponent implements OnInit, OnDestroy {
247281

248282
this.store.dispatch(
249283
updateUserSettingsAction({
250-
property: { conditions: conditionConfigs },
284+
property: { conditions: updatedConditions },
251285
}),
252286
);
253287
this.store.dispatch(fetchDatasetsAction());
@@ -623,22 +657,7 @@ export class DatasetsFilterComponent implements OnInit, OnDestroy {
623657

624658
updateConditionValue(index: number, event: Event) {
625659
const newValue = (event.target as HTMLInputElement).value;
626-
const currentRelation = this.asyncPipe.transform(this.conditionConfigs$)?.[
627-
index
628-
]?.condition.relation;
629-
if (
630-
currentRelation === "EQUAL_TO" ||
631-
currentRelation === "EQUAL_TO_NUMERIC" ||
632-
currentRelation === "EQUAL_TO_STRING"
633-
) {
634-
const isNumeric = newValue !== "" && !isNaN(Number(newValue));
635-
this.updateConditionField(index, {
636-
rhs: isNumeric ? Number(newValue) : newValue,
637-
relation: isNumeric ? "EQUAL_TO_NUMERIC" : "EQUAL_TO_STRING",
638-
});
639-
} else {
640-
this.updateConditionField(index, { rhs: Number(newValue) });
641-
}
660+
this.tempConditionValues[index] = newValue;
642661
}
643662

644663
updateConditionRangeValue(index: number, event: Event, rangeIndex: 0 | 1) {

0 commit comments

Comments
 (0)