Skip to content

Commit

Permalink
add CONTAINS_STRING option to condition search
Browse files Browse the repository at this point in the history
Change-Id: Ieca1c78c5fa7bcde1411089aeafb132a06b41874
  • Loading branch information
AnastasiiaDeveloper authored and bpedersen2 committed Dec 18, 2023
1 parent ce4cfec commit 30e3c7d
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,9 @@
<ng-container *ngSwitchCase="'EQUAL_TO_STRING'">
&nbsp;=&nbsp;
</ng-container>
<ng-container *ngSwitchCase="'CONTAINS_STRING'">
&nbsp;contains&nbsp;
</ng-container>
<ng-container *ngSwitchCase="'LESS_THAN'">
&nbsp;&lt;&nbsp;
</ng-container>
Expand All @@ -201,7 +204,7 @@
</ng-container>
</ng-container>
{{
condition.relation === "EQUAL_TO_STRING"
["EQUAL_TO_STRING", "CONTAINS_STRING"].includes(condition.relation)
? '"' + condition.rhs + '"'
: condition.rhs
}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@
<ng-container *ngSwitchCase="'EQUAL_TO_STRING'">
&nbsp;=&nbsp;
</ng-container>
<ng-container *ngSwitchCase="'CONTAINS_STRING'">
&nbsp;=&nbsp;
</ng-container>
<ng-container *ngSwitchCase="'LESS_THAN'">
&nbsp;&lt;&nbsp;
</ng-container>
Expand All @@ -56,7 +59,7 @@
</ng-container>
</ng-container>
{{
characteristic.relation === "EQUAL_TO_STRING"
[ "EQUAL_TO_STRING", "CONTAINS_STRING" ].includes(characteristic.relation)
? '"' + characteristic.rhs + '"'
: characteristic.rhs
}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ <h2 mat-dialog-title>Add Characteristic</h2>
<mat-option value="LESS_THAN">is less than</mat-option>
<mat-option value="EQUAL_TO_NUMERIC">is equal to (numeric)</mat-option>
<mat-option value="EQUAL_TO_STRING">is equal to (string)</mat-option>
<mat-option value="CONTAINS_STRING">contains string</mat-option>
</mat-select>
</mat-form-field>

Expand Down Expand Up @@ -90,4 +91,4 @@ <h2 mat-dialog-title>Add Characteristic</h2>
Add
</button>
</mat-dialog-actions>
</form>
</form>
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ describe("SearchParametersDialogComponent", () => {
});

describe("#toggleUnitField()", () => {
it("should enable unitField if lhs is valid and relation is not EQUAL_TO_STRING", () => {
it("should enable unitField if lhs is valid and relation is not CONTAINS_STRING or EQUAL_TO_STRING", () => {
const formValues = {
lhs: "mass",
relation: "LESS_THAN",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,9 @@ export class SearchParametersDialogComponent {
add = (): void => {
const { lhs, relation, unit } = this.parametersForm.value;
const rawRhs = this.parametersForm.get("rhs")?.value;
const rhs =
relation === "EQUAL_TO_STRING" ? String(rawRhs) : Number(rawRhs);
const rhs = ["CONTAINS_STRING", "EQUAL_TO_STRING"].includes(relation)
? String(rawRhs)
: Number(rawRhs);
this.parametersForm.patchValue({ rhs });
this.dialogRef.close({ data: { lhs, relation, rhs, unit } });
};
Expand All @@ -73,7 +74,11 @@ export class SearchParametersDialogComponent {
toggleUnitField = (): void => {
const lhsInvalid = this.parametersForm.get("lhs")?.invalid;
const { relation } = this.parametersForm.value;
const isStringRelation = relation === "EQUAL_TO_STRING" ? true : false;
const isStringRelation = ["CONTAINS_STRING", "EQUAL_TO_STRING"].includes(
relation,
)
? true
: false;
const unitField = this.parametersForm.get("unit");
unitField?.enable();
if (lhsInvalid || isStringRelation) {
Expand All @@ -88,7 +93,10 @@ export class SearchParametersDialogComponent {
if (invalid) {
return invalid;
}
if (relation !== "EQUAL_TO_STRING" && isNaN(Number(rhs))) {
if (
!["CONTAINS_STRING", "EQUAL_TO_STRING"].includes(relation) &&
isNaN(Number(rhs))
) {
return true;
}
return lhs.length * (rhs as string).length === 0;
Expand Down
1 change: 1 addition & 0 deletions src/app/state-management/models/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ export enum JobViewMode {
type ScientificConditionRelation =
| "EQUAL_TO_NUMERIC"
| "EQUAL_TO_STRING"
| "CONTAINS_STRING"
| "GREATER_THAN"
| "LESS_THAN";

Expand Down

0 comments on commit 30e3c7d

Please sign in to comment.