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 bf5240f1b..8885d240f 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 @@ -1250,30 +1250,12 @@ 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', - }, - ]) - })) - it('should convert user input to correct filter rules on mime type', fakeAsync(() => { component.textFilterInput.nativeElement.value = 'pdf' component.textFilterInput.nativeElement.dispatchEvent(new Event('input')) const textFieldTargetDropdown = fixture.debugElement.queryAll( By.directive(NgbDropdownItem) - )[4] + )[3] textFieldTargetDropdown.triggerEventHandler('click') // TEXT_FILTER_TARGET_MIME_TYPE fixture.detectChanges() tick(400) @@ -1291,8 +1273,8 @@ describe('FilterEditorComponent', () => { component.textFilterInput.nativeElement.dispatchEvent(new Event('input')) const textFieldTargetDropdown = fixture.debugElement.queryAll( By.directive(NgbDropdownItem) - )[5] - textFieldTargetDropdown.triggerEventHandler('click') // TEXT_FILTER_TARGET_ASN + )[4] + textFieldTargetDropdown.triggerEventHandler('click') // TEXT_FILTER_TARGET_FULLTEXT_QUERY fixture.detectChanges() tick(400) expect(component.textFilterTarget).toEqual('fulltext-query') @@ -1701,7 +1683,7 @@ describe('FilterEditorComponent', () => { component.textFilterInput.nativeElement.dispatchEvent(new Event('input')) const textFieldTargetDropdown = fixture.debugElement.queryAll( By.directive(NgbDropdownItem) - )[5] + )[4] textFieldTargetDropdown.triggerEventHandler('click') fixture.detectChanges() tick(400) @@ -2156,6 +2138,36 @@ describe('FilterEditorComponent', () => { }) }) + it('should hide deprecated custom fields target from default text filter targets', () => { + expect(component.textFilterTargets).not.toContainEqual({ + id: 'custom-fields', + name: $localize`Custom fields (Deprecated)`, + }) + }) + + it('should keep deprecated custom fields target available for legacy filters', fakeAsync(() => { + component.filterRules = [ + { + rule_type: FILTER_CUSTOM_FIELDS_TEXT, + value: 'foo', + }, + ] + fixture.detectChanges() + tick() + + expect(component.textFilterTarget).toEqual('custom-fields') + expect(component.textFilterTargets).toContainEqual({ + id: 'custom-fields', + name: $localize`Custom fields (Deprecated)`, + }) + expect(component.filterRules).toEqual([ + { + rule_type: FILTER_CUSTOM_FIELDS_TEXT, + value: 'foo', + }, + ]) + })) + it('should call autocomplete endpoint on input', fakeAsync(() => { component.textFilterTarget = 'fulltext-query' // TEXT_FILTER_TARGET_FULLTEXT_QUERY const autocompleteSpy = jest.spyOn(searchService, 'autocomplete') 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 f7b50181b..5be6425ac 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 @@ -195,10 +195,6 @@ 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_MIME_TYPE, name: $localize`File type` }, { id: TEXT_FILTER_TARGET_FULLTEXT_QUERY, @@ -206,6 +202,14 @@ const DEFAULT_TEXT_FILTER_TARGET_OPTIONS = [ }, ] +const LEGACY_TEXT_FILTER_TARGET_OPTIONS = [ + { + id: TEXT_FILTER_TARGET_CUSTOM_FIELDS, + // Kept only so legacy saved views can render and be edited away from. + name: $localize`Custom fields (Deprecated)`, + }, +] + const TEXT_FILTER_TARGET_MORELIKE_OPTION = { id: TEXT_FILTER_TARGET_FULLTEXT_MORELIKE, name: $localize`More like`, @@ -353,12 +357,14 @@ export class FilterEditorComponent _moreLikeDoc: Document get textFilterTargets() { + let targets = DEFAULT_TEXT_FILTER_TARGET_OPTIONS if (this.textFilterTarget == TEXT_FILTER_TARGET_FULLTEXT_MORELIKE) { - return DEFAULT_TEXT_FILTER_TARGET_OPTIONS.concat([ - TEXT_FILTER_TARGET_MORELIKE_OPTION, - ]) + targets = targets.concat([TEXT_FILTER_TARGET_MORELIKE_OPTION]) } - return DEFAULT_TEXT_FILTER_TARGET_OPTIONS + if (this.textFilterTarget == TEXT_FILTER_TARGET_CUSTOM_FIELDS) { + targets = targets.concat(LEGACY_TEXT_FILTER_TARGET_OPTIONS) + } + return targets } textFilterTarget = TEXT_FILTER_TARGET_TITLE_CONTENT