Fix: support multiple inbox tags from stats widget (#7281)

This commit is contained in:
shamoon 2024-07-22 10:07:51 -07:00 committed by GitHub
parent 82340ad6e3
commit 6b2e5559ca
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
9 changed files with 30 additions and 25 deletions

View File

@ -9,7 +9,7 @@ test('dashboard inbox link', async ({ page }) => {
await page.routeFromHAR(REQUESTS_HAR1, { notFound: 'fallback' }) await page.routeFromHAR(REQUESTS_HAR1, { notFound: 'fallback' })
await page.goto('/dashboard') await page.goto('/dashboard')
await page.getByRole('link', { name: 'Documents in inbox' }).click() await page.getByRole('link', { name: 'Documents in inbox' }).click()
await expect(page).toHaveURL(/tags__id__all=9/) await expect(page).toHaveURL(/tags__id__in=9/)
await expect(page.locator('pngx-document-list')).toHaveText(/8 documents/) await expect(page.locator('pngx-document-list')).toHaveText(/8 documents/)
}) })

View File

@ -236,7 +236,7 @@
"content": { "content": {
"size": -1, "size": -1,
"mimeType": "application/json", "mimeType": "application/json",
"text": "{\"documents_total\":61,\"documents_inbox\":8,\"inbox_tag\":9,\"document_file_type_counts\":[{\"mime_type\":\"application/pdf\",\"mime_type_count\":57},{\"mime_type\":\"text/plain\",\"mime_type_count\":3},{\"mime_type\":\"text/csv\",\"mime_type_count\":1}],\"character_count\":2407053}" "text": "{\"documents_total\":61,\"documents_inbox\":8,\"inbox_tags\":[9],\"document_file_type_counts\":[{\"mime_type\":\"application/pdf\",\"mime_type_count\":57},{\"mime_type\":\"text/plain\",\"mime_type_count\":3},{\"mime_type\":\"text/csv\",\"mime_type_count\":1}],\"character_count\":2407053}"
}, },
"headersSize": -1, "headersSize": -1,
"bodySize": -1, "bodySize": -1,
@ -250,7 +250,7 @@
"time": 0.609, "time": 0.609,
"request": { "request": {
"method": "GET", "method": "GET",
"url": "http://localhost:8000/api/documents/?page=1&page_size=10&ordering=-created&truncate_content=true&tags__id__all=9", "url": "http://localhost:8000/api/documents/?page=1&page_size=10&ordering=-created&truncate_content=true&tags__id__in=9",
"httpVersion": "HTTP/1.1", "httpVersion": "HTTP/1.1",
"cookies": [], "cookies": [],
"headers": [ "headers": [
@ -284,7 +284,7 @@
"value": "true" "value": "true"
}, },
{ {
"name": "tags__id__all", "name": "tags__id__in",
"value": "9" "value": "9"
} }
], ],
@ -468,7 +468,7 @@
"time": 0.951, "time": 0.951,
"request": { "request": {
"method": "GET", "method": "GET",
"url": "http://localhost:8000/api/documents/?page=1&page_size=50&ordering=-created&truncate_content=true&tags__id__all=9", "url": "http://localhost:8000/api/documents/?page=1&page_size=50&ordering=-created&truncate_content=true&tags__id__in=9",
"httpVersion": "HTTP/1.1", "httpVersion": "HTTP/1.1",
"cookies": [], "cookies": [],
"headers": [ "headers": [
@ -502,7 +502,7 @@
"value": "true" "value": "true"
}, },
{ {
"name": "tags__id__all", "name": "tags__id__in",
"value": "9" "value": "9"
} }
], ],

View File

@ -236,7 +236,7 @@
"content": { "content": {
"size": -1, "size": -1,
"mimeType": "application/json", "mimeType": "application/json",
"text": "{\"documents_total\":61,\"documents_inbox\":8,\"inbox_tag\":9,\"document_file_type_counts\":[{\"mime_type\":\"application/pdf\",\"mime_type_count\":57},{\"mime_type\":\"text/plain\",\"mime_type_count\":3},{\"mime_type\":\"text/csv\",\"mime_type_count\":1}],\"character_count\":2407053}" "text": "{\"documents_total\":61,\"documents_inbox\":8,\"inbox_tags\":[9],\"document_file_type_counts\":[{\"mime_type\":\"application/pdf\",\"mime_type_count\":57},{\"mime_type\":\"text/plain\",\"mime_type_count\":3},{\"mime_type\":\"text/csv\",\"mime_type_count\":1}],\"character_count\":2407053}"
}, },
"headersSize": -1, "headersSize": -1,
"bodySize": -1, "bodySize": -1,
@ -250,7 +250,7 @@
"time": 0.622, "time": 0.622,
"request": { "request": {
"method": "GET", "method": "GET",
"url": "http://localhost:8000/api/documents/?page=1&page_size=10&ordering=-created&truncate_content=true&tags__id__all=9", "url": "http://localhost:8000/api/documents/?page=1&page_size=10&ordering=-created&truncate_content=true&tags__id__in=9",
"httpVersion": "HTTP/1.1", "httpVersion": "HTTP/1.1",
"cookies": [], "cookies": [],
"headers": [ "headers": [
@ -284,7 +284,7 @@
"value": "true" "value": "true"
}, },
{ {
"name": "tags__id__all", "name": "tags__id__in",
"value": "9" "value": "9"
} }
], ],

View File

@ -236,7 +236,7 @@
"content": { "content": {
"size": -1, "size": -1,
"mimeType": "application/json", "mimeType": "application/json",
"text": "{\"documents_total\":61,\"documents_inbox\":8,\"inbox_tag\":9,\"document_file_type_counts\":[{\"mime_type\":\"application/pdf\",\"mime_type_count\":57},{\"mime_type\":\"text/plain\",\"mime_type_count\":3},{\"mime_type\":\"text/csv\",\"mime_type_count\":1}],\"character_count\":2407053}" "text": "{\"documents_total\":61,\"documents_inbox\":8,\"inbox_tags\":[9],\"document_file_type_counts\":[{\"mime_type\":\"application/pdf\",\"mime_type_count\":57},{\"mime_type\":\"text/plain\",\"mime_type_count\":3},{\"mime_type\":\"text/csv\",\"mime_type_count\":1}],\"character_count\":2407053}"
}, },
"headersSize": -1, "headersSize": -1,
"bodySize": -1, "bodySize": -1,

View File

@ -236,7 +236,7 @@
"content": { "content": {
"size": -1, "size": -1,
"mimeType": "application/json", "mimeType": "application/json",
"text": "{\"documents_total\":61,\"documents_inbox\":8,\"inbox_tag\":9,\"document_file_type_counts\":[{\"mime_type\":\"application/pdf\",\"mime_type_count\":57},{\"mime_type\":\"text/plain\",\"mime_type_count\":3},{\"mime_type\":\"text/csv\",\"mime_type_count\":1}],\"character_count\":2407053}" "text": "{\"documents_total\":61,\"documents_inbox\":8,\"inbox_tags\":[9],\"document_file_type_counts\":[{\"mime_type\":\"application/pdf\",\"mime_type_count\":57},{\"mime_type\":\"text/plain\",\"mime_type_count\":3},{\"mime_type\":\"text/csv\",\"mime_type_count\":1}],\"character_count\":2407053}"
}, },
"headersSize": -1, "headersSize": -1,
"bodySize": -1, "bodySize": -1,

View File

@ -75,7 +75,7 @@ describe('StatisticsWidgetComponent', () => {
const mockStats = { const mockStats = {
documents_total: 200, documents_total: 200,
documents_inbox: 18, documents_inbox: 18,
inbox_tag: 10, inbox_tags: [10],
} }
const req = httpTestingController.expectOne( const req = httpTestingController.expectOne(
@ -100,7 +100,7 @@ describe('StatisticsWidgetComponent', () => {
const mockStats = { const mockStats = {
documents_total: 200, documents_total: 200,
documents_inbox: 18, documents_inbox: 18,
inbox_tag: 10, inbox_tags: [10],
document_file_type_counts: [ document_file_type_counts: [
{ {
mime_type: 'application/pdf', mime_type: 'application/pdf',

View File

@ -1,7 +1,7 @@
import { HttpClient } from '@angular/common/http' import { HttpClient } from '@angular/common/http'
import { Component, OnDestroy, OnInit } from '@angular/core' import { Component, OnDestroy, OnInit } from '@angular/core'
import { Observable, Subscription } from 'rxjs' import { Observable, Subscription } from 'rxjs'
import { FILTER_HAS_TAGS_ALL } from 'src/app/data/filter-rule-type' import { FILTER_HAS_TAGS_ANY } from 'src/app/data/filter-rule-type'
import { ConsumerStatusService } from 'src/app/services/consumer-status.service' import { ConsumerStatusService } from 'src/app/services/consumer-status.service'
import { DocumentListViewService } from 'src/app/services/document-list-view.service' import { DocumentListViewService } from 'src/app/services/document-list-view.service'
import { environment } from 'src/environments/environment' import { environment } from 'src/environments/environment'
@ -11,7 +11,7 @@ import { ComponentWithPermissions } from 'src/app/components/with-permissions/wi
export interface Statistics { export interface Statistics {
documents_total?: number documents_total?: number
documents_inbox?: number documents_inbox?: number
inbox_tag?: number inbox_tags?: number[]
document_file_type_counts?: DocumentFileType[] document_file_type_counts?: DocumentFileType[]
character_count?: number character_count?: number
tag_count?: number tag_count?: number
@ -110,8 +110,10 @@ export class StatisticsWidgetComponent
goToInbox() { goToInbox() {
this.documentListViewService.quickFilter([ this.documentListViewService.quickFilter([
{ {
rule_type: FILTER_HAS_TAGS_ALL, rule_type: FILTER_HAS_TAGS_ANY,
value: this.statistics.inbox_tag.toString(), value: this.statistics.inbox_tags
.map((tagID) => tagID.toString())
.join(','),
}, },
]) ])
} }

View File

@ -954,7 +954,7 @@ class TestDocumentApi(DirectoriesMixin, DocumentConsumeDelayMixin, APITestCase):
self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(response.status_code, status.HTTP_200_OK)
self.assertEqual(response.data["documents_total"], 3) self.assertEqual(response.data["documents_total"], 3)
self.assertEqual(response.data["documents_inbox"], 1) self.assertEqual(response.data["documents_inbox"], 1)
self.assertEqual(response.data["inbox_tag"], tag_inbox.pk) self.assertEqual(response.data["inbox_tags"], [tag_inbox.pk])
self.assertEqual( self.assertEqual(
response.data["document_file_type_counts"][0]["mime_type_count"], response.data["document_file_type_counts"][0]["mime_type_count"],
2, 2,
@ -975,7 +975,7 @@ class TestDocumentApi(DirectoriesMixin, DocumentConsumeDelayMixin, APITestCase):
response = self.client.get("/api/statistics/") response = self.client.get("/api/statistics/")
self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(response.status_code, status.HTTP_200_OK)
self.assertEqual(response.data["documents_inbox"], None) self.assertEqual(response.data["documents_inbox"], None)
self.assertEqual(response.data["inbox_tag"], None) self.assertEqual(response.data["inbox_tags"], None)
def test_statistics_multiple_users(self): def test_statistics_multiple_users(self):
""" """

View File

@ -1418,13 +1418,11 @@ class StatisticsView(APIView):
documents_total = documents.count() documents_total = documents.count()
inbox_tag = tags.filter(is_inbox_tag=True) inbox_tags = tags.filter(is_inbox_tag=True)
documents_inbox = ( documents_inbox = (
documents.filter(tags__is_inbox_tag=True, tags__id__in=tags) documents.filter(tags__id__in=inbox_tags).distinct().count()
.distinct() if inbox_tags.exists()
.count()
if inbox_tag.exists()
else None else None
) )
@ -1454,7 +1452,12 @@ class StatisticsView(APIView):
{ {
"documents_total": documents_total, "documents_total": documents_total,
"documents_inbox": documents_inbox, "documents_inbox": documents_inbox,
"inbox_tag": inbox_tag.first().pk if inbox_tag.exists() else None, "inbox_tag": inbox_tags.first().pk
if inbox_tags.exists()
else None, # backwards compatibility
"inbox_tags": [tag.pk for tag in inbox_tags]
if inbox_tags.exists()
else None,
"document_file_type_counts": document_file_type_counts, "document_file_type_counts": document_file_type_counts,
"character_count": character_count, "character_count": character_count,
"tag_count": len(tags), "tag_count": len(tags),