From bddca47924d82bef67526ed464122ee886c40a9e Mon Sep 17 00:00:00 2001 From: shamoon <4887959+shamoon@users.noreply.github.com> Date: Mon, 9 Sep 2024 13:04:29 -0700 Subject: [PATCH] Fix some clearing stuff --- .../custom-fields-query-dropdown.component.ts | 14 ++++++++++++-- src-ui/src/app/data/custom-field-query.ts | 2 +- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src-ui/src/app/components/common/custom-fields-query-dropdown/custom-fields-query-dropdown.component.ts b/src-ui/src/app/components/common/custom-fields-query-dropdown/custom-fields-query-dropdown.component.ts index dbad02e4c..112eca35a 100644 --- a/src-ui/src/app/components/common/custom-fields-query-dropdown/custom-fields-query-dropdown.component.ts +++ b/src-ui/src/app/components/common/custom-fields-query-dropdown/custom-fields-query-dropdown.component.ts @@ -35,6 +35,13 @@ export class CustomFieldQueriesModel { ) } + public isEmpty(): boolean { + return ( + this.queries.length === 0 || + (this.queries.length === 1 && this.queries[0].value.length === 0) + ) + } + private validateAtom(atom: CustomFieldQueryAtom) { let valid: boolean = !!(atom.field && atom.operator && atom.value) return valid @@ -112,6 +119,9 @@ export class CustomFieldQueriesModel { return } foundComponent.changed.complete() + if (this.isEmpty()) { + this.clear() + } this.changed.next(this) } } @@ -161,7 +171,7 @@ export class CustomFieldsQueryDropdownComponent { if (this._selectionModel) { this._selectionModel.changed.complete() } - model.changed.subscribe((updatedModel) => { + model.changed.subscribe(() => { this.onModelChange() }) this._selectionModel = model @@ -172,7 +182,7 @@ export class CustomFieldsQueryDropdownComponent { } private onModelChange() { - if (this.selectionModel.isValid()) { + if (this.selectionModel.isEmpty() || this.selectionModel.isValid()) { this.selectionModelChange.next(this.selectionModel) } } diff --git a/src-ui/src/app/data/custom-field-query.ts b/src-ui/src/app/data/custom-field-query.ts index 06c6ac3e4..bd1d6d8fa 100644 --- a/src-ui/src/app/data/custom-field-query.ts +++ b/src-ui/src/app/data/custom-field-query.ts @@ -268,7 +268,7 @@ export class CustomFieldQueryExpression extends CustomFieldQueryElement { super(CustomFieldQueryElementType.Expression) let values ;[this._operator, values] = expressionArray - if (!values) { + if (!values || values.length === 0) { this._value = [] } else if (values?.length > 0 && values[0] instanceof Array) { this._value = values.map((value) => {