Use a backend display_count to fix nested tag thing

This commit is contained in:
shamoon
2026-03-12 00:16:34 -07:00
parent 97602f79fb
commit 84e8caf25f
4 changed files with 17 additions and 6 deletions
@@ -230,10 +230,11 @@ describe('ManagementListComponent', () => {
expect(reloadSpy).toHaveBeenCalled()
})
it('should use API count for pagination and displayed total', fakeAsync(() => {
it('should use API count for pagination and nested ids for displayed total', fakeAsync(() => {
jest.spyOn(tagService, 'listFiltered').mockReturnValueOnce(
of({
count: 1,
display_count: 3,
results: tags.slice(0, 1),
})
)
@@ -242,7 +243,7 @@ describe('ManagementListComponent', () => {
tick(100)
expect(component.collectionSize).toBe(1)
expect(component.displayCollectionSize).toBe(1)
expect(component.displayCollectionSize).toBe(3)
}))
it('should support quick filter for objects', () => {
@@ -323,8 +324,9 @@ describe('ManagementListComponent', () => {
expect(component.togggleAll).toBe(true)
})
it('selectAll should fetch IDs when all IDs are not preloaded', () => {
it('selectAll should fetch IDs when clicked', () => {
;(tagService.listFiltered as jest.Mock).mockClear()
;(component as any).allIDs = []
component.collectionSize = tags.length
component.selectAll()
@@ -156,7 +156,7 @@ export abstract class ManagementListComponent<T extends MatchingModel>
}
protected getDisplayCollectionSize(results: Results<T>): number {
return this.getCollectionSize(results)
return results.display_count ?? this.getCollectionSize(results)
}
getDocumentCount(object: MatchingModel): number {
@@ -375,6 +375,13 @@ export abstract class ManagementListComponent<T extends MatchingModel>
return
}
this.fetchAllFilteredIds((ids) => {
this.selectedObjects = new Set(ids)
this.togggleAll = this.areAllPageItemsSelected()
})
}
private fetchAllFilteredIds(onLoaded?: (ids: number[]) => void): void {
this.service
.listFiltered(
1,
@@ -395,8 +402,7 @@ export abstract class ManagementListComponent<T extends MatchingModel>
)
.subscribe((ids) => {
this.allIDs = ids
this.selectedObjects = new Set(ids)
this.togggleAll = this.areAllPageItemsSelected()
onLoaded?.(ids)
})
}
+2
View File
@@ -3,6 +3,8 @@ import { Document } from './document'
export interface Results<T> {
count: number
display_count?: number
results: T[]
}
+1
View File
@@ -555,6 +555,7 @@ class TagViewSet(PermissionsAwareDocumentCountMixin, ModelViewSet):
page = self.paginate_queryset(queryset)
serializer = self.get_serializer(page, many=True)
response = self.get_paginated_response(serializer.data)
response.data["display_count"] = len(children_source)
api_version = int(request.version or settings.REST_FRAMEWORK["DEFAULT_VERSION"])
if descendant_pks and api_version < 10:
# Include children in the "all" field, if needed