diff --git a/src-ui/src/app/components/document-list/filter-editor/filter-editor.component.spec.ts b/src-ui/src/app/components/document-list/filter-editor/filter-editor.component.spec.ts index 4dfb87f25..a84146838 100644 --- a/src-ui/src/app/components/document-list/filter-editor/filter-editor.component.spec.ts +++ b/src-ui/src/app/components/document-list/filter-editor/filter-editor.component.spec.ts @@ -97,6 +97,11 @@ import { RouterModule } from '@angular/router' import { SearchService } from 'src/app/services/rest/search.service' import { provideHttpClient, withInterceptorsFromDi } from '@angular/common/http' import { CustomFieldsQueryDropdownComponent } from '../../common/custom-fields-query-dropdown/custom-fields-query-dropdown.component' +import { + CustomFieldQueryAtom, + CustomFieldQueryLogicalOperator, + CustomFieldQueryOperator, +} from 'src/app/data/custom-field-query' const tags: Tag[] = [ { @@ -842,70 +847,43 @@ describe('FilterEditorComponent', () => { })) it('should ingest filter rules for has all custom fields', fakeAsync(() => { - // expect(component.customFieldQueriesModel.getSelectedItems()).toHaveLength(0) - // component.filterRules = [ - // { - // rule_type: FILTER_HAS_CUSTOM_FIELDS_ALL, - // value: '42', - // }, - // { - // rule_type: FILTER_HAS_CUSTOM_FIELDS_ALL, - // value: '43', - // }, - // ] - // expect(component.customFieldQueriesModel.logicalOperator).toEqual( - // LogicalOperator.And - // ) - // expect(component.customFieldQueriesModel.getSelectedItems()).toEqual( - // custom_fields - // ) - // // coverage - // component.filterRules = [ - // { - // rule_type: FILTER_HAS_CUSTOM_FIELDS_ALL, - // value: null, - // }, - // ] - // component.toggleTag(2) // coverage + expect(component.customFieldQueriesModel.isEmpty()).toBeTruthy() + component.filterRules = [ + { + rule_type: FILTER_HAS_CUSTOM_FIELDS_ALL, + value: '42,43', + }, + ] + expect(component.customFieldQueriesModel.queries[0].operator).toEqual( + CustomFieldQueryLogicalOperator.And + ) + expect(component.customFieldQueriesModel.queries[0].value.length).toEqual(2) + expect( + ( + component.customFieldQueriesModel.queries[0] + .value[0] as CustomFieldQueryAtom + ).serialize() + ).toEqual(['42', CustomFieldQueryOperator.Exists, 'true']) })) it('should ingest filter rules for has any custom fields', fakeAsync(() => { - // expect(component.customFieldQueriesModel.getSelectedItems()).toHaveLength(0) - // component.filterRules = [ - // { - // rule_type: FILTER_HAS_CUSTOM_FIELDS_ANY, - // value: '42', - // }, - // { - // rule_type: FILTER_HAS_CUSTOM_FIELDS_ANY, - // value: '43', - // }, - // ] - // expect(component.customFieldQueriesModel.logicalOperator).toEqual( - // LogicalOperator.Or - // ) - // expect(component.customFieldQueriesModel.getSelectedItems()).toEqual( - // custom_fields - // ) - // // coverage - // component.filterRules = [ - // { - // rule_type: FILTER_HAS_CUSTOM_FIELDS_ANY, - // value: null, - // }, - // ] - })) - - it('should ingest filter rules for has any custom field', fakeAsync(() => { - // expect(component.customFieldQueriesModel.getSelectedItems()).toHaveLength(0) - // component.filterRules = [ - // { - // rule_type: FILTER_HAS_ANY_CUSTOM_FIELDS, - // value: '1', - // }, - // ] - // expect(component.customFieldQueriesModel.getSelectedItems()).toHaveLength(1) - // expect(component.customFieldQueriesModel.get(null)).toBeTruthy() + expect(component.customFieldQueriesModel.isEmpty()).toBeTruthy() + component.filterRules = [ + { + rule_type: FILTER_HAS_CUSTOM_FIELDS_ANY, + value: '42,43', + }, + ] + expect(component.customFieldQueriesModel.queries[0].operator).toEqual( + CustomFieldQueryLogicalOperator.Or + ) + expect(component.customFieldQueriesModel.queries[0].value.length).toEqual(2) + expect( + ( + component.customFieldQueriesModel.queries[0] + .value[0] as CustomFieldQueryAtom + ).serialize() + ).toEqual(['42', CustomFieldQueryOperator.Exists, 'true']) })) it('should ingest filter rules for exclude tag(s)', fakeAsync(() => { diff --git a/src-ui/src/app/components/document-list/filter-editor/filter-editor.component.ts b/src-ui/src/app/components/document-list/filter-editor/filter-editor.component.ts index e23b586c9..c1b3ec2f1 100644 --- a/src-ui/src/app/components/document-list/filter-editor/filter-editor.component.ts +++ b/src-ui/src/app/components/document-list/filter-editor/filter-editor.component.ts @@ -96,6 +96,7 @@ import { CustomFieldQueryExpression, CustomFieldQueryAtom, CustomFieldQueryLogicalOperator, + CustomFieldQueryOperator, } from 'src/app/data/custom-field-query' import { CustomFieldQueriesModel } from '../../common/custom-fields-query-dropdown/custom-fields-query-dropdown.component' @@ -559,7 +560,9 @@ export class FilterEditorComponent this.customFieldQueriesModel.addExpression( new CustomFieldQueryExpression([ CustomFieldQueryLogicalOperator.And, - rule.value.split(','), + rule.value + .split(',') + .map((id) => [id, CustomFieldQueryOperator.Exists, 'true']), ]) ) break @@ -567,7 +570,9 @@ export class FilterEditorComponent this.customFieldQueriesModel.addExpression( new CustomFieldQueryExpression([ CustomFieldQueryLogicalOperator.Or, - rule.value.split(','), + rule.value + .split(',') + .map((id) => [id, CustomFieldQueryOperator.Exists, 'true']), ]) ) break diff --git a/src-ui/src/app/data/custom-field-query.ts b/src-ui/src/app/data/custom-field-query.ts index bd1d6d8fa..ab801d85e 100644 --- a/src-ui/src/app/data/custom-field-query.ts +++ b/src-ui/src/app/data/custom-field-query.ts @@ -268,6 +268,8 @@ export class CustomFieldQueryExpression extends CustomFieldQueryElement { super(CustomFieldQueryElementType.Expression) let values ;[this._operator, values] = expressionArray + console.log(values) + if (!values || values.length === 0) { this._value = [] } else if (values?.length > 0 && values[0] instanceof Array) {