From 047754ea63d6ad4a038c89f1c9041ab3ea2e4e19 Mon Sep 17 00:00:00 2001 From: shamoon <4887959+shamoon@users.noreply.github.com> Date: Mon, 2 Sep 2024 20:11:58 -0700 Subject: [PATCH] Add back custom field text search field --- .../filter-editor.component.spec.ts | 52 +++++++++---------- .../filter-editor/filter-editor.component.ts | 34 ++++++------ 2 files changed, 43 insertions(+), 43 deletions(-) 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 ffae1ce3b..13eb9d11c 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 @@ -316,15 +316,15 @@ describe('FilterEditorComponent', () => { })) it('should ingest text filter rules for custom fields', fakeAsync(() => { - // expect(component.textFilter).toEqual(null) - // component.filterRules = [ - // { - // rule_type: FILTER_CUSTOM_FIELDS_TEXT, - // value: 'foo', - // }, - // ] - // expect(component.textFilter).toEqual('foo') - // expect(component.textFilterTarget).toEqual('custom-fields') // TEXT_FILTER_TARGET_CUSTOM_FIELDS + expect(component.textFilter).toEqual(null) + component.filterRules = [ + { + rule_type: FILTER_CUSTOM_FIELDS_TEXT, + value: 'foo', + }, + ] + expect(component.textFilter).toEqual('foo') + expect(component.textFilterTarget).toEqual('custom-fields') // TEXT_FILTER_TARGET_CUSTOM_FIELDS })) it('should ingest text filter rules for doc asn is null', fakeAsync(() => { @@ -1170,21 +1170,21 @@ describe('FilterEditorComponent', () => { })) it('should convert user input to correct filter rules on custom fields query', fakeAsync(() => { - // component.textFilterInput.nativeElement.value = 'foo' - // component.textFilterInput.nativeElement.dispatchEvent(new Event('input')) - // const textFieldTargetDropdown = fixture.debugElement.queryAll( - // By.directive(NgbDropdownItem) - // )[3] - // textFieldTargetDropdown.triggerEventHandler('click') // TEXT_FILTER_TARGET_CUSTOM_FIELDS - // fixture.detectChanges() - // tick(400) - // expect(component.textFilterTarget).toEqual('custom-fields') - // expect(component.filterRules).toEqual([ - // { - // rule_type: FILTER_CUSTOM_FIELDS_TEXT, - // value: 'foo', - // }, - // ]) + component.textFilterInput.nativeElement.value = 'foo' + component.textFilterInput.nativeElement.dispatchEvent(new Event('input')) + const textFieldTargetDropdown = fixture.debugElement.queryAll( + By.directive(NgbDropdownItem) + )[3] + textFieldTargetDropdown.triggerEventHandler('click') // TEXT_FILTER_TARGET_CUSTOM_FIELDS + fixture.detectChanges() + tick(400) + expect(component.textFilterTarget).toEqual('custom-fields') + expect(component.filterRules).toEqual([ + { + rule_type: FILTER_CUSTOM_FIELDS_TEXT, + value: 'foo', + }, + ]) })) it('should convert user input to correct filter rules on full text query', fakeAsync(() => { @@ -1192,7 +1192,7 @@ describe('FilterEditorComponent', () => { component.textFilterInput.nativeElement.dispatchEvent(new Event('input')) const textFieldTargetDropdown = fixture.debugElement.queryAll( By.directive(NgbDropdownItem) - )[3] + )[4] textFieldTargetDropdown.triggerEventHandler('click') // TEXT_FILTER_TARGET_ASN fixture.detectChanges() tick(400) @@ -1596,7 +1596,7 @@ describe('FilterEditorComponent', () => { component.textFilterInput.nativeElement.dispatchEvent(new Event('input')) const textFieldTargetDropdown = fixture.debugElement.queryAll( By.directive(NgbDropdownItem) - )[3] + )[4] textFieldTargetDropdown.triggerEventHandler('click') fixture.detectChanges() tick(400) 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 f55d7a8eb..5a64f8ead 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 @@ -97,6 +97,7 @@ import { CustomFieldQueriesModel, CustomFieldQueryAtom, CustomFieldQueryExpression, + CustomFieldQueryLogicalOperator, } from '../../common/custom-fields-query-dropdown/custom-fields-query-dropdown.component' const TEXT_FILTER_TARGET_TITLE = 'title' @@ -104,6 +105,7 @@ const TEXT_FILTER_TARGET_TITLE_CONTENT = 'title-content' const TEXT_FILTER_TARGET_ASN = 'asn' const TEXT_FILTER_TARGET_FULLTEXT_QUERY = 'fulltext-query' const TEXT_FILTER_TARGET_FULLTEXT_MORELIKE = 'fulltext-morelike' +const TEXT_FILTER_TARGET_CUSTOM_FIELDS = 'custom-fields' const TEXT_FILTER_MODIFIER_EQUALS = 'equals' const TEXT_FILTER_MODIFIER_NULL = 'is null' @@ -139,6 +141,10 @@ const DEFAULT_TEXT_FILTER_TARGET_OPTIONS = [ name: $localize`Title & content`, }, { id: TEXT_FILTER_TARGET_ASN, name: $localize`ASN` }, + { + id: TEXT_FILTER_TARGET_CUSTOM_FIELDS, + name: $localize`Custom fields`, + }, { id: TEXT_FILTER_TARGET_FULLTEXT_QUERY, name: $localize`Advanced search`, @@ -384,7 +390,8 @@ export class FilterEditorComponent this.textFilterTarget = TEXT_FILTER_TARGET_ASN break case FILTER_CUSTOM_FIELDS_TEXT: - console.log('FILTER_CUSTOM_FIELDS_TEXT', rule.value) + this._textFilter = rule.value + this.textFilterTarget = TEXT_FILTER_TARGET_CUSTOM_FIELDS break case FILTER_FULLTEXT_QUERY: let allQueryArgs = rule.value.split(',') @@ -543,22 +550,6 @@ export class FilterEditorComponent // TODO: handle error? } break - case FILTER_HAS_CUSTOM_FIELDS_ALL: - console.log('FILTER_HAS_CUSTOM_FIELDS_ALL', rule.value) - // TODO: fully implement - break - case FILTER_HAS_CUSTOM_FIELDS_ANY: - console.log('FILTER_HAS_CUSTOM_FIELDS_ANY', rule.value) - // TODO: fully implement - break - case FILTER_HAS_ANY_CUSTOM_FIELDS: - console.log('FILTER_HAS_ANY_CUSTOM_FIELDS', rule.value) - // TODO: fully implement - break - case FILTER_DOES_NOT_HAVE_CUSTOM_FIELDS: - console.log('FILTER_DOES_NOT_HAVE_CUSTOM_FIELDS', rule.value) - // TODO: fully implement - break case FILTER_ASN_ISNULL: this.textFilterTarget = TEXT_FILTER_TARGET_ASN this.textFilterModifier = @@ -661,6 +652,15 @@ export class FilterEditorComponent }) } } + if ( + this._textFilter && + this.textFilterTarget == TEXT_FILTER_TARGET_CUSTOM_FIELDS + ) { + filterRules.push({ + rule_type: FILTER_CUSTOM_FIELDS_TEXT, + value: this._textFilter, + }) + } if ( this._textFilter && this.textFilterTarget == TEXT_FILTER_TARGET_FULLTEXT_QUERY