]> git.ipfire.org Git - thirdparty/paperless-ngx.git/commitdiff
Fix: de-deduplicate children in tag list when filtering (#11229)
authorshamoon <4887959+shamoon@users.noreply.github.com>
Thu, 30 Oct 2025 14:02:00 +0000 (07:02 -0700)
committerGitHub <noreply@github.com>
Thu, 30 Oct 2025 14:02:00 +0000 (07:02 -0700)
src-ui/src/app/components/manage/tag-list/tag-list.component.spec.ts
src-ui/src/app/components/manage/tag-list/tag-list.component.ts

index 91cf092641aff895c8eeccb69f0c3dd0e5dcdddb..0db84182b245893de5db3f441f0a0088c8d999ae 100644 (file)
@@ -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', () => {
index bf5ad1b50765c46ffb4ea7dd03c6b9967e9b5be2..64ca121dfc89f1c403c277f1b29c5a848f7ffbed 100644 (file)
@@ -69,9 +69,13 @@ export class TagListComponent extends ManagementListComponent<Tag> {
   }
 
   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[] {