From a488cc0115f9a4b9da8d6b7bb5556140cfe745c3 Mon Sep 17 00:00:00 2001
From: Michael Shamoon <4887959+shamoon@users.noreply.github.com>
Date: Fri, 25 Nov 2022 08:23:12 -0800
Subject: [PATCH] Use statistics endpoint for paperless-ngx
---
src/utils/config/service-helpers.js | 3 ---
src/widgets/paperlessngx/component.jsx | 25 ++++++-------------------
src/widgets/paperlessngx/widget.js | 14 +++-----------
3 files changed, 9 insertions(+), 33 deletions(-)
diff --git a/src/utils/config/service-helpers.js b/src/utils/config/service-helpers.js
index d8367de3..15740d22 100644
--- a/src/utils/config/service-helpers.js
+++ b/src/utils/config/service-helpers.js
@@ -118,7 +118,6 @@ export function cleanServiceGroups(groups) {
container,
currency, // coinmarketcap widget
symbols,
- inboxTag, // paperlessngx widget
} = cleanedService.widget;
cleanedService.widget = {
@@ -130,8 +129,6 @@ export function cleanServiceGroups(groups) {
if (currency) cleanedService.widget.currency = currency;
if (symbols) cleanedService.widget.symbols = symbols;
-
- if (inboxTag) cleanedService.widget.inboxTag = inboxTag;
if (type === "docker") {
if (server) cleanedService.widget.server = server;
diff --git a/src/widgets/paperlessngx/component.jsx b/src/widgets/paperlessngx/component.jsx
index 131c0419..d0c2e12f 100644
--- a/src/widgets/paperlessngx/component.jsx
+++ b/src/widgets/paperlessngx/component.jsx
@@ -5,26 +5,13 @@ import useWidgetAPI from "utils/proxy/use-widget-api";
export default function Component({ service }) {
const { widget } = service;
- const { data: inboxData, error: inboxError } = useWidgetAPI(widget, "inbox",
- {
- query: `tag:${widget.inboxTag}`,
- format: "json",
- fields: "count"
- });
+ const { data: statisticsData, error: statisticsError } = useWidgetAPI(widget, "statistics");
-
- const { data: documentData, error: documentError } = useWidgetAPI(widget, "documents",
- {
- fields: "count",
- format: "json",
- });
-
- if (inboxError || documentError) {
- const finalError = inboxError ?? documentError;
- return ;
+ if (statisticsError) {
+ return ;
}
- if (!inboxData || !documentData) {
+ if (!statisticsData) {
return (
@@ -35,8 +22,8 @@ export default function Component({ service }) {
return (
-
-
+ {statisticsData.documents_inbox !== undefined && }
+
);
}
diff --git a/src/widgets/paperlessngx/widget.js b/src/widgets/paperlessngx/widget.js
index 9671a053..8af8079d 100644
--- a/src/widgets/paperlessngx/widget.js
+++ b/src/widgets/paperlessngx/widget.js
@@ -5,18 +5,10 @@ const widget = {
proxyHandler: genericProxyHandler,
mappings: {
- "inbox": {
- endpoint: "documents/",
- params: ["format", "query", "fields"],
+ "statistics": {
+ endpoint: "statistics/?format=json",
validate: [
- "count"
- ]
- },
- "documents": {
- endpoint: "documents/",
- params: ["format", "fields"],
- validate: [
- "count"
+ "documents_total"
]
},
},