Fix invalid in / contains, fix some unintended closing

This commit is contained in:
shamoon
2024-09-23 13:03:56 -07:00
parent 55855bbe58
commit 9c09719dbd
5 changed files with 37 additions and 14 deletions

View File

@@ -46,6 +46,7 @@
[items]="getSelectOptionsForField(atom.field)"
[(ngModel)]="atom.value"
[disabled]="disabled"
(mousedown)="$event.stopImmediatePropagation()"
></ng-select>
} @else {
<input class="w-25 form-control rounded-end" type="text" [(ngModel)]="atom.value" [disabled]="disabled">
@@ -101,6 +102,7 @@
[(ngModel)]="atom.value"
[disabled]="disabled"
[multiple]="true"
(mousedown)="$event.stopImmediatePropagation()"
></ng-select>
}
@case (CustomFieldQueryOperator.Exact) {

View File

@@ -230,6 +230,16 @@ describe('CustomFieldsQueryDropdownComponent', () => {
expect(model.isValid()).toBeFalsy()
})
it('should validate an atom with in or contains operator', () => {
const atom = new CustomFieldQueryAtom([1, 'in', '[1,2,3]'])
expect(model['validateAtom'].apply(null, [atom])).toBeTruthy()
atom.operator = 'contains'
atom.value = [1, 2, 3]
expect(model['validateAtom'].apply(null, [atom])).toBeTruthy()
atom.value = null
expect(model['validateAtom'].apply(null, [atom])).toBeFalsy()
})
it('should check if model is empty', () => {
expect(model.isEmpty()).toBeTruthy()
model.addExpression()

View File

@@ -53,7 +53,17 @@ export class CustomFieldQueriesModel {
}
private validateAtom(atom: CustomFieldQueryAtom) {
return !!(atom.field && atom.operator && atom.value !== null)
let valid = !!(atom.field && atom.operator && atom.value !== null)
if (
[
CustomFieldQueryOperator.In.valueOf(),
CustomFieldQueryOperator.Contains.valueOf(),
].includes(atom.operator) &&
atom.value
) {
valid = valid && atom.value.length > 0
}
return valid
}
private validateExpression(expression: CustomFieldQueryExpression) {

View File

@@ -36,6 +36,7 @@
[minTermLength]="2"
[loading]="loading"
[typeahead]="documentsInput$"
(mousedown)="$event.stopImmediatePropagation()"
(change)="onChange(selectedDocuments)">
<ng-template ng-label-tmp let-document="item">
<div class="d-flex align-items-center">