From 6b55740f563c4d0973779dd40fd021fa8c4d0cab Mon Sep 17 00:00:00 2001 From: shamoon <4887959+shamoon@users.noreply.github.com> Date: Thu, 30 Oct 2025 07:02:00 -0700 Subject: [PATCH] Fix: de-deduplicate children in tag list when filtering (#11229) --- .../manage/tag-list/tag-list.component.spec.ts | 17 ++++++++++++++--- .../manage/tag-list/tag-list.component.ts | 10 +++++++--- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/src-ui/src/app/components/manage/tag-list/tag-list.component.spec.ts b/src-ui/src/app/components/manage/tag-list/tag-list.component.spec.ts index 91cf092641..0db84182b2 100644 --- a/src-ui/src/app/components/manage/tag-list/tag-list.component.spec.ts +++ b/src-ui/src/app/components/manage/tag-list/tag-list.component.spec.ts @@ -73,9 +73,14 @@ describe('TagListComponent', () => { ) }) - it('should filter out child tags if name filter is empty, otherwise show all', () => { + it('should omit matching children from top level when their parent is present', () => { const tags = [ - { id: 1, name: 'Tag1', parent: null }, + { + id: 1, + name: 'Tag1', + parent: null, + children: [{ id: 2, name: 'Tag2', parent: 1 }], + }, { id: 2, name: 'Tag2', parent: 1 }, { id: 3, name: 'Tag3', parent: null }, ] @@ -86,7 +91,13 @@ describe('TagListComponent', () => { component['_nameFilter'] = 'Tag2' // Simulate non-empty name filter const filteredWithName = component.filterData(tags as any) - expect(filteredWithName.length).toBe(3) + expect(filteredWithName.length).toBe(2) + expect(filteredWithName.find((t) => t.id === 2)).toBeUndefined() + expect( + filteredWithName + .find((t) => t.id === 1) + ?.children?.some((c) => c.id === 2) + ).toBe(true) }) it('should request only parent tags when no name filter is applied', () => { diff --git a/src-ui/src/app/components/manage/tag-list/tag-list.component.ts b/src-ui/src/app/components/manage/tag-list/tag-list.component.ts index bf5ad1b507..64ca121dfc 100644 --- a/src-ui/src/app/components/manage/tag-list/tag-list.component.ts +++ b/src-ui/src/app/components/manage/tag-list/tag-list.component.ts @@ -69,9 +69,13 @@ export class TagListComponent extends ManagementListComponent { } filterData(data: Tag[]) { - return this.nameFilter?.length - ? [...data] - : data.filter((tag) => !tag.parent) + if (!this.nameFilter?.length) { + return data.filter((tag) => !tag.parent) + } + + // When filtering by name, exclude children if their parent is also present + const availableIds = new Set(data.map((tag) => tag.id)) + return data.filter((tag) => !tag.parent || !availableIds.has(tag.parent)) } protected override getSelectableIDs(tags: Tag[]): number[] { -- 2.47.3