From 9e744a0665dbf98e80f3bd153886b522dcb19e8c Mon Sep 17 00:00:00 2001 From: shamoon <4887959+shamoon@users.noreply.github.com> Date: Wed, 31 Dec 2025 16:58:45 -0800 Subject: [PATCH] Also for CF --- .../custom-fields.component.html | 18 ++++++++++---- .../custom-fields.component.spec.ts | 24 +++++++++++++------ .../custom-fields/custom-fields.component.ts | 6 +++-- 3 files changed, 35 insertions(+), 13 deletions(-) diff --git a/src-ui/src/app/components/manage/custom-fields/custom-fields.component.html b/src-ui/src/app/components/manage/custom-fields/custom-fields.component.html index 185e9da35..0a6d80658 100644 --- a/src-ui/src/app/components/manage/custom-fields/custom-fields.component.html +++ b/src-ui/src/app/components/manage/custom-fields/custom-fields.component.html @@ -42,7 +42,13 @@ @if (field.document_count > 0) { - + Filter Documents ({{ field.document_count }}) } @@ -57,9 +63,13 @@ @if (field.document_count > 0) {
- + +  Documents{{ field.document_count }} +
} diff --git a/src-ui/src/app/components/manage/custom-fields/custom-fields.component.spec.ts b/src-ui/src/app/components/manage/custom-fields/custom-fields.component.spec.ts index e94470d64..b86d476f3 100644 --- a/src-ui/src/app/components/manage/custom-fields/custom-fields.component.spec.ts +++ b/src-ui/src/app/components/manage/custom-fields/custom-fields.component.spec.ts @@ -4,6 +4,7 @@ import { provideHttpClient, withInterceptorsFromDi } from '@angular/common/http' import { provideHttpClientTesting } from '@angular/common/http/testing' import { FormsModule, ReactiveFormsModule } from '@angular/forms' import { By } from '@angular/platform-browser' +import { RouterTestingModule } from '@angular/router/testing' import { NgbModal, NgbModalModule, @@ -61,6 +62,7 @@ describe('CustomFieldsComponent', () => { NgbModalModule, NgbPopoverModule, NgxBootstrapIconsModule.pick(allIcons), + RouterTestingModule, CustomFieldsComponent, IfPermissionsDirective, PageHeaderComponent, @@ -108,7 +110,9 @@ describe('CustomFieldsComponent', () => { const toastInfoSpy = jest.spyOn(toastService, 'showInfo') const reloadSpy = jest.spyOn(component, 'reload') - const createButton = fixture.debugElement.queryAll(By.css('button'))[1] + const createButton = fixture.debugElement + .queryAll(By.css('button')) + .find((btn) => btn.nativeElement.textContent.trim().includes('Add Field')) createButton.triggerEventHandler('click') expect(modal).not.toBeUndefined() @@ -133,7 +137,11 @@ describe('CustomFieldsComponent', () => { const toastInfoSpy = jest.spyOn(toastService, 'showInfo') const reloadSpy = jest.spyOn(component, 'reload') - const editButton = fixture.debugElement.queryAll(By.css('button'))[2] + const editButton = fixture.debugElement + .queryAll(By.css('button')) + .find((btn) => + btn.nativeElement.textContent.trim().includes(fields[0].name) + ) editButton.triggerEventHandler('click') expect(modal).not.toBeUndefined() @@ -158,7 +166,9 @@ describe('CustomFieldsComponent', () => { const deleteSpy = jest.spyOn(customFieldsService, 'delete') const reloadSpy = jest.spyOn(component, 'reload') - const deleteButton = fixture.debugElement.queryAll(By.css('button'))[5] + const deleteButton = fixture.debugElement + .queryAll(By.css('button')) + .find((btn) => btn.nativeElement.textContent.trim().includes('Delete')) deleteButton.triggerEventHandler('click') expect(modal).not.toBeUndefined() @@ -176,10 +186,10 @@ describe('CustomFieldsComponent', () => { expect(reloadSpy).toHaveBeenCalled() }) - it('should support filter documents', () => { - const filterSpy = jest.spyOn(listViewService, 'quickFilter') - component.filterDocuments(fields[0]) - expect(filterSpy).toHaveBeenCalledWith([ + it('should provide document filter url', () => { + const urlSpy = jest.spyOn(listViewService, 'getQuickFilterUrl') + component.getDocumentFilterUrl(fields[0]) + expect(urlSpy).toHaveBeenCalledWith([ { rule_type: FILTER_CUSTOM_FIELDS_QUERY, value: JSON.stringify([ diff --git a/src-ui/src/app/components/manage/custom-fields/custom-fields.component.ts b/src-ui/src/app/components/manage/custom-fields/custom-fields.component.ts index 9e7ecf78a..8ecd713ef 100644 --- a/src-ui/src/app/components/manage/custom-fields/custom-fields.component.ts +++ b/src-ui/src/app/components/manage/custom-fields/custom-fields.component.ts @@ -1,4 +1,5 @@ import { Component, OnInit, inject } from '@angular/core' +import { RouterModule } from '@angular/router' import { NgbDropdownModule, NgbModal, @@ -36,6 +37,7 @@ import { LoadingComponentWithPermissions } from '../../loading-component/loading NgbDropdownModule, NgbPaginationModule, NgxBootstrapIconsModule, + RouterModule, ], }) export class CustomFieldsComponent @@ -130,8 +132,8 @@ export class CustomFieldsComponent return DATA_TYPE_LABELS.find((l) => l.id === field.data_type).name } - filterDocuments(field: CustomField) { - this.documentListViewService.quickFilter([ + getDocumentFilterUrl(field: CustomField) { + return this.documentListViewService.getQuickFilterUrl([ { rule_type: FILTER_CUSTOM_FIELDS_QUERY, value: JSON.stringify([