Skip to content

Commit 30e3c7d

Browse files
AnastasiiaDeveloperbpedersen2
authored andcommitted
add CONTAINS_STRING option to condition search
Change-Id: Ieca1c78c5fa7bcde1411089aeafb132a06b41874
1 parent ce4cfec commit 30e3c7d

File tree

6 files changed

+24
-8
lines changed

6 files changed

+24
-8
lines changed

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

+4-1
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,9 @@
193193
<ng-container *ngSwitchCase="'EQUAL_TO_STRING'">
194194
&nbsp;=&nbsp;
195195
</ng-container>
196+
<ng-container *ngSwitchCase="'CONTAINS_STRING'">
197+
&nbsp;contains&nbsp;
198+
</ng-container>
196199
<ng-container *ngSwitchCase="'LESS_THAN'">
197200
&nbsp;&lt;&nbsp;
198201
</ng-container>
@@ -201,7 +204,7 @@
201204
</ng-container>
202205
</ng-container>
203206
{{
204-
condition.relation === "EQUAL_TO_STRING"
207+
["EQUAL_TO_STRING", "CONTAINS_STRING"].includes(condition.relation)
205208
? '"' + condition.rhs + '"'
206209
: condition.rhs
207210
}}

src/app/samples/sample-dashboard/sample-dashboard.component.html

+4-1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@
4848
<ng-container *ngSwitchCase="'EQUAL_TO_STRING'">
4949
&nbsp;=&nbsp;
5050
</ng-container>
51+
<ng-container *ngSwitchCase="'CONTAINS_STRING'">
52+
&nbsp;=&nbsp;
53+
</ng-container>
5154
<ng-container *ngSwitchCase="'LESS_THAN'">
5255
&nbsp;&lt;&nbsp;
5356
</ng-container>
@@ -56,7 +59,7 @@
5659
</ng-container>
5760
</ng-container>
5861
{{
59-
characteristic.relation === "EQUAL_TO_STRING"
62+
[ "EQUAL_TO_STRING", "CONTAINS_STRING" ].includes(characteristic.relation)
6063
? '"' + characteristic.rhs + '"'
6164
: characteristic.rhs
6265
}}

src/app/shared/modules/search-parameters-dialog/search-parameters-dialog.component.html

+2-1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ <h2 mat-dialog-title>Add Characteristic</h2>
3838
<mat-option value="LESS_THAN">is less than</mat-option>
3939
<mat-option value="EQUAL_TO_NUMERIC">is equal to (numeric)</mat-option>
4040
<mat-option value="EQUAL_TO_STRING">is equal to (string)</mat-option>
41+
<mat-option value="CONTAINS_STRING">contains string</mat-option>
4142
</mat-select>
4243
</mat-form-field>
4344

@@ -90,4 +91,4 @@ <h2 mat-dialog-title>Add Characteristic</h2>
9091
Add
9192
</button>
9293
</mat-dialog-actions>
93-
</form>
94+
</form>

src/app/shared/modules/search-parameters-dialog/search-parameters-dialog.component.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ describe("SearchParametersDialogComponent", () => {
107107
});
108108

109109
describe("#toggleUnitField()", () => {
110-
it("should enable unitField if lhs is valid and relation is not EQUAL_TO_STRING", () => {
110+
it("should enable unitField if lhs is valid and relation is not CONTAINS_STRING or EQUAL_TO_STRING", () => {
111111
const formValues = {
112112
lhs: "mass",
113113
relation: "LESS_THAN",

src/app/shared/modules/search-parameters-dialog/search-parameters-dialog.component.ts

+12-4
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,9 @@ export class SearchParametersDialogComponent {
5757
add = (): void => {
5858
const { lhs, relation, unit } = this.parametersForm.value;
5959
const rawRhs = this.parametersForm.get("rhs")?.value;
60-
const rhs =
61-
relation === "EQUAL_TO_STRING" ? String(rawRhs) : Number(rawRhs);
60+
const rhs = ["CONTAINS_STRING", "EQUAL_TO_STRING"].includes(relation)
61+
? String(rawRhs)
62+
: Number(rawRhs);
6263
this.parametersForm.patchValue({ rhs });
6364
this.dialogRef.close({ data: { lhs, relation, rhs, unit } });
6465
};
@@ -73,7 +74,11 @@ export class SearchParametersDialogComponent {
7374
toggleUnitField = (): void => {
7475
const lhsInvalid = this.parametersForm.get("lhs")?.invalid;
7576
const { relation } = this.parametersForm.value;
76-
const isStringRelation = relation === "EQUAL_TO_STRING" ? true : false;
77+
const isStringRelation = ["CONTAINS_STRING", "EQUAL_TO_STRING"].includes(
78+
relation,
79+
)
80+
? true
81+
: false;
7782
const unitField = this.parametersForm.get("unit");
7883
unitField?.enable();
7984
if (lhsInvalid || isStringRelation) {
@@ -88,7 +93,10 @@ export class SearchParametersDialogComponent {
8893
if (invalid) {
8994
return invalid;
9095
}
91-
if (relation !== "EQUAL_TO_STRING" && isNaN(Number(rhs))) {
96+
if (
97+
!["CONTAINS_STRING", "EQUAL_TO_STRING"].includes(relation) &&
98+
isNaN(Number(rhs))
99+
) {
92100
return true;
93101
}
94102
return lhs.length * (rhs as string).length === 0;

src/app/state-management/models/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ export enum JobViewMode {
8181
type ScientificConditionRelation =
8282
| "EQUAL_TO_NUMERIC"
8383
| "EQUAL_TO_STRING"
84+
| "CONTAINS_STRING"
8485
| "GREATER_THAN"
8586
| "LESS_THAN";
8687

0 commit comments

Comments
 (0)