Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions cypress/e2e/datasets/datasets-general.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -401,4 +401,52 @@ describe("Datasets general", () => {
});
});
});

describe("Scientific notation in condition panel test", () => {
beforeEach(() => {
cy.login(Cypress.env("username"), Cypress.env("password"));
cy.createDataset({
type: "raw",
dataFileSize: "small",
scientificMetadata: {
extra_entry_end_time: { type: "number", value: 310000, unit: "" },
},
isPublished: true,
});

cy.visit("/datasets");
});
it("should be able to add condition with scientific notation value", () => {

cy.get('[data-cy="scientific-condition-filter-list"]').within(() => {
cy.get('[data-cy="add-condition-button"]').click();
});

cy.get('input[name="lhs"]').type("extra_entry_end_time");

cy.get("mat-dialog-container").find('button[type="submit"]').click();

cy.get(".condition-panel").first().click();

cy.get(".condition-panel")
.first()
.within(() => {
cy.get("mat-select").click();
});

cy.get("mat-option").contains("=").click();

cy.get(".condition-panel")
.first()
.within(() => {
cy.get("input[matInput]").eq(0).clear().type("3.1e4");
});

cy.get('[data-cy="search-button"]').click();

cy.get(".dataset-table mat-table").should("exist");

cy.get('[data-cy="remove-condition-button"]').click();
});
})
});
57 changes: 38 additions & 19 deletions src/app/datasets/datasets-filter/datasets-filter.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ export class DatasetsFilterComponent implements OnInit, OnDestroy {

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

tempConditionValues: string[] = [];

constructor(
public appConfigService: AppConfigService,
public dialog: MatDialog,
Expand Down Expand Up @@ -229,15 +231,47 @@ export class DatasetsFilterComponent implements OnInit, OnDestroy {
});

this.conditionConfigs$.pipe(take(1)).subscribe((conditionConfigs) => {
(conditionConfigs || []).forEach((oldCondition) => {
const updatedConditions = (conditionConfigs || []).map((config, i) => {
if (this.tempConditionValues[i] !== undefined) {
const value = this.tempConditionValues[i];
const isNumeric = value !== "" && !isNaN(Number(value));
if (
config.condition.relation === "EQUAL_TO" ||
config.condition.relation === "EQUAL_TO_NUMERIC" ||
config.condition.relation === "EQUAL_TO_STRING"
) {
return {
...config,
condition: {
...config.condition,
rhs: isNumeric ? Number(value) : value,
relation: isNumeric
? ("EQUAL_TO_NUMERIC" as ScientificCondition["relation"])
: ("EQUAL_TO_STRING" as ScientificCondition["relation"]),
},
};
} else {
return {
...config,
condition: {
...config.condition,
rhs: isNumeric ? Number(value) : value,
},
};
}
}
return config;
});

updatedConditions.forEach((oldCondition) => {
this.store.dispatch(
removeScientificConditionAction({
condition: oldCondition.condition,
}),
);
});

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

this.store.dispatch(
updateUserSettingsAction({
property: { conditions: conditionConfigs },
property: { conditions: updatedConditions },
}),
);
this.store.dispatch(fetchDatasetsAction());
Expand Down Expand Up @@ -623,22 +657,7 @@ export class DatasetsFilterComponent implements OnInit, OnDestroy {

updateConditionValue(index: number, event: Event) {
const newValue = (event.target as HTMLInputElement).value;
const currentRelation = this.asyncPipe.transform(this.conditionConfigs$)?.[
index
]?.condition.relation;
if (
currentRelation === "EQUAL_TO" ||
currentRelation === "EQUAL_TO_NUMERIC" ||
currentRelation === "EQUAL_TO_STRING"
) {
const isNumeric = newValue !== "" && !isNaN(Number(newValue));
this.updateConditionField(index, {
rhs: isNumeric ? Number(newValue) : newValue,
relation: isNumeric ? "EQUAL_TO_NUMERIC" : "EQUAL_TO_STRING",
});
} else {
this.updateConditionField(index, { rhs: Number(newValue) });
}
this.tempConditionValues[index] = newValue;
}

updateConditionRangeValue(index: number, event: Event, rangeIndex: 0 | 1) {
Expand Down
Loading