Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add CONTAINS_STRING option to condition search #1342

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
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
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,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 @@ -181,7 +184,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
@@ -1,93 +1,94 @@
<h2 mat-dialog-title>Add Characteristic</h2>
<form [formGroup]="parametersForm">
<mat-dialog-content>
<mat-form-field>
<mat-label>Field</mat-label>
<input
matInput
autocomplete="off"
autocorrect="off"
autocapitalize="off"
spellcheck="false"
name="lhs"
formControlName="lhs"
[matAutocomplete]="parameterKeys"
(blur)="getUnits(lhs)"
(focus)="toggleUnitField()"
/>
<mat-autocomplete #parameterKeys="matAutocomplete">
<mat-option
*ngFor="let key of filteredKeys$ | async"
[value]="key"
[matTooltip]="key"
>
{{ key }}
</mat-option>
</mat-autocomplete>
</mat-form-field>

<mat-form-field>
<mat-label>Operator</mat-label>
<mat-select
name="operator"
formControlName="relation"
(focus)="toggleUnitField()"
(selectionChange)="toggleUnitField()"
>
<mat-option value="GREATER_THAN">is greater than</mat-option>
<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-select>
</mat-form-field>

<mat-form-field>
<mat-label>Value</mat-label>
<input
matInput
autocomplete="off"
autocorrect="off"
autocapitalize="off"
spellcheck="false"
name="rhs"
formControlName="rhs"
/>
</mat-form-field>

<ng-template [ngIf]="unitsEnabled">
<mat-form-field>
<mat-label>Unit</mat-label>
<input
matInput
autocomplete="off"
autocorrect="off"
autocapitalize="off"
spellcheck="false"
name="rhsUnit"
formControlName="unit"
[matAutocomplete]="rhsUnits"
/>
<mat-autocomplete #rhsUnits="matAutocomplete">
<mat-option
*ngFor="let unit of filteredUnits$ | async"
[value]="unit"
>
{{ unit }}
</mat-option>
</mat-autocomplete>
</mat-form-field>
</ng-template>
</mat-dialog-content>
<mat-dialog-actions [attr.align]="'end'">
<button mat-button (click)="cancel()">Cancel</button>
<button
mat-button
type="submit"
(click)="add()"
color="primary"
[disabled]="isInvalid()"
>
Add
</button>
</mat-dialog-actions>
</form>
<h2 mat-dialog-title>Add Characteristic</h2>
<form [formGroup]="parametersForm">
<mat-dialog-content>
<mat-form-field>
<mat-label>Field</mat-label>
<input
matInput
autocomplete="off"
autocorrect="off"
autocapitalize="off"
spellcheck="false"
name="lhs"
formControlName="lhs"
[matAutocomplete]="parameterKeys"
(blur)="getUnits(lhs)"
(focus)="toggleUnitField()"
/>
<mat-autocomplete #parameterKeys="matAutocomplete">
<mat-option
*ngFor="let key of filteredKeys$ | async"
[value]="key"
[matTooltip]="key"
>
{{ key }}
</mat-option>
</mat-autocomplete>
</mat-form-field>

<mat-form-field>
<mat-label>Operator</mat-label>
<mat-select
name="operator"
formControlName="relation"
(focus)="toggleUnitField()"
(selectionChange)="toggleUnitField()"
>
<mat-option value="GREATER_THAN">is greater than</mat-option>
<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>

<mat-form-field>
<mat-label>Value</mat-label>
<input
matInput
autocomplete="off"
autocorrect="off"
autocapitalize="off"
spellcheck="false"
name="rhs"
formControlName="rhs"
/>
</mat-form-field>

<ng-template [ngIf]="unitsEnabled">
<mat-form-field>
<mat-label>Unit</mat-label>
<input
matInput
autocomplete="off"
autocorrect="off"
autocapitalize="off"
spellcheck="false"
name="rhsUnit"
formControlName="unit"
[matAutocomplete]="rhsUnits"
/>
<mat-autocomplete #rhsUnits="matAutocomplete">
<mat-option
*ngFor="let unit of filteredUnits$ | async"
[value]="unit"
>
{{ unit }}
</mat-option>
</mat-autocomplete>
</mat-form-field>
</ng-template>
</mat-dialog-content>
<mat-dialog-actions [attr.align]="'end'">
<button mat-button (click)="cancel()">Cancel</button>
<button
mat-button
type="submit"
(click)="add()"
color="primary"
[disabled]="isInvalid()"
>
Add
</button>
</mat-dialog-actions>
</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
Loading