]> git.ipfire.org Git - thirdparty/paperless-ngx.git/commitdiff
Fixhancement: more saved view count refreshes (#10694)
authorshamoon <4887959+shamoon@users.noreply.github.com>
Tue, 26 Aug 2025 20:27:49 +0000 (13:27 -0700)
committerGitHub <noreply@github.com>
Tue, 26 Aug 2025 20:27:49 +0000 (13:27 -0700)
src-ui/src/app/components/dashboard/dashboard.component.spec.ts
src-ui/src/app/components/dashboard/widgets/saved-view-widget/saved-view-widget.component.ts
src-ui/src/app/components/document-list/document-list.component.spec.ts
src-ui/src/app/components/document-list/document-list.component.ts
src-ui/src/app/services/rest/saved-view.service.ts

index 31f4379e87aeb65bbc88395567424abcd68db7a3..ac2823182fd3205b4efc07b0af656689a7d2c74e 100644 (file)
@@ -106,6 +106,7 @@ describe('DashboardComponent', () => {
               }),
             dashboardViews: saved_views.filter((v) => v.show_on_dashboard),
             allViews: saved_views,
+            setDocumentCount: jest.fn(),
           },
         },
         provideHttpClient(withInterceptorsFromDi()),
index f24e988f4fdbd40d77991428546e8f724693814d..198feb4231ce6cb4237533e6e79cbcac43359417 100644 (file)
@@ -52,6 +52,7 @@ import {
 } from 'src/app/services/permissions.service'
 import { CustomFieldsService } from 'src/app/services/rest/custom-fields.service'
 import { DocumentService } from 'src/app/services/rest/document.service'
+import { SavedViewService } from 'src/app/services/rest/saved-view.service'
 import { SettingsService } from 'src/app/services/settings.service'
 import { WebsocketStatusService } from 'src/app/services/websocket-status.service'
 import { WidgetFrameComponent } from '../widget-frame/widget-frame.component'
@@ -94,6 +95,7 @@ export class SavedViewWidgetComponent
   permissionsService = inject(PermissionsService)
   private settingsService = inject(SettingsService)
   private customFieldService = inject(CustomFieldsService)
+  private savedViewService = inject(SavedViewService)
 
   public DisplayMode = DisplayMode
   public DisplayField = DisplayField
@@ -181,6 +183,7 @@ export class SavedViewWidgetComponent
           this.show = true
           this.documents = result.results
           this.count = result.count
+          this.savedViewService.setDocumentCount(this.savedView, result.count)
         }),
         delay(500)
       )
index aae043fdb33dddad7084f4503995560c324a7fc8..a64d79e499e478b1bac29fe12739d61324354ede 100644 (file)
@@ -199,6 +199,14 @@ describe('DocumentListComponent', () => {
     }
     const queryParams = { id: view.id.toString() }
     const getSavedViewSpy = jest.spyOn(savedViewService, 'getCached')
+    const setCountSpy = jest.spyOn(savedViewService, 'setDocumentCount')
+    jest.spyOn(documentService, 'listFiltered').mockReturnValue(
+      of({
+        results: docs,
+        count: 3,
+        all: docs.map((d) => d.id),
+      })
+    )
     getSavedViewSpy.mockReturnValue(of(view))
     const activateSavedViewSpy = jest.spyOn(
       documentListService,
@@ -215,6 +223,7 @@ describe('DocumentListComponent', () => {
       view,
       convertToParamMap(queryParams)
     )
+    expect(setCountSpy).toHaveBeenCalledWith(view, 3)
   })
 
   it('should 404 on load saved view from URL if no view', () => {
@@ -248,6 +257,34 @@ describe('DocumentListComponent', () => {
     expect(getSavedViewSpy).toHaveBeenCalledWith(view.id)
   })
 
+  it('should update saved view document count on load saved view from query params', () => {
+    jest.spyOn(savedViewService, 'getCached').mockReturnValue(
+      of({
+        id: 10,
+        sort_field: 'added',
+        sort_reverse: true,
+        filter_rules: [],
+      })
+    )
+    jest.spyOn(documentService, 'listFiltered').mockReturnValue(
+      of({
+        results: docs,
+        count: 3,
+        all: docs.map((d) => d.id),
+      })
+    )
+    const setCountSpy = jest.spyOn(savedViewService, 'setDocumentCount')
+    jest.spyOn(documentService, 'listFiltered').mockReturnValue(
+      of({
+        results: docs,
+        count: 3,
+        all: docs.map((d) => d.id),
+      })
+    )
+    component.loadViewConfig(10)
+    expect(setCountSpy).toHaveBeenCalledWith(expect.any(Object), 3)
+  })
+
   it('should support 3 different display modes', () => {
     jest.spyOn(documentListService, 'documents', 'get').mockReturnValue(docs)
     fixture.detectChanges()
index 8a31f9e9f8c9792b20df541c0ae06bd7b1d3ced6..aca686fcf32c320eb7ea573e370090015221dfd7 100644 (file)
@@ -264,7 +264,9 @@ export class DocumentListComponent
           view,
           convertToParamMap(this.route.snapshot.queryParams)
         )
-        this.list.reload()
+        this.list.reload(() => {
+          this.savedViewService.setDocumentCount(view, this.list.collectionSize)
+        })
         this.updateDisplayCustomFields()
         this.unmodifiedFilterRules = view.filter_rules
       })
@@ -399,7 +401,9 @@ export class DocumentListComponent
       .subscribe((view) => {
         this.unmodifiedSavedView = view
         this.list.activateSavedView(view)
-        this.list.reload()
+        this.list.reload(() => {
+          this.savedViewService.setDocumentCount(view, this.list.collectionSize)
+        })
       })
   }
 
index a8f4202551921d50c9c32266acede4d53128a0fe..4ea2cef65f3436e1731130ce48959da136a7a80d 100644 (file)
@@ -140,11 +140,15 @@ export class SavedViewService extends AbstractPaperlessService<SavedView> {
         )
         .pipe(takeUntil(this.unsubscribeNotifier))
         .subscribe((results: Results<Document>) => {
-          this.savedViewDocumentCounts.set(view.id, results.count)
+          this.setDocumentCount(view, results.count)
         })
     })
   }
 
+  public setDocumentCount(view: SavedView, count: number) {
+    this.savedViewDocumentCounts.set(view.id, count)
+  }
+
   public getDocumentCount(view: SavedView): number {
     return this.savedViewDocumentCounts.get(view.id)
   }