From cc6069238821021110f74544c90eccdeb9233004 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mikl=C3=B3s=20M=C3=A1rton?= Date: Mon, 4 May 2026 12:25:48 +0200 Subject: [PATCH] Implement Latest parts dashboard widget (#11540) * Implement Latest parts dashboard widget * Removed unused variables * Fix StylishText include --- .../InvenTree/InvenTree/api_version.py | 5 +- src/backend/InvenTree/part/api.py | 1 + .../dashboard/DashboardWidgetLibrary.tsx | 11 ++- .../widgets/QueryDashboardWidget.tsx | 96 +++++++++++++++++++ 4 files changed, 111 insertions(+), 2 deletions(-) create mode 100644 src/frontend/src/components/dashboard/widgets/QueryDashboardWidget.tsx diff --git a/src/backend/InvenTree/InvenTree/api_version.py b/src/backend/InvenTree/InvenTree/api_version.py index 8e4a0312df..4c7c25654e 100644 --- a/src/backend/InvenTree/InvenTree/api_version.py +++ b/src/backend/InvenTree/InvenTree/api_version.py @@ -1,11 +1,14 @@ """InvenTree API version information.""" # InvenTree API version -INVENTREE_API_VERSION = 481 +INVENTREE_API_VERSION = 482 """Increment this API version number whenever there is a significant change to the API that any clients need to know about.""" INVENTREE_API_TEXT = """ +v482 -> 2026-03-15 : https://github.com/inventree/InvenTree/pull/11540 + - Add id to the ordering fields of the Parts model + v481 -> 2026-04-28 : https://github.com/inventree/InvenTree/pull/11825 - Adds new "bom" ruleset and associated permissions for BOM management, separate from the "part" ruleset which remains focused on part management diff --git a/src/backend/InvenTree/part/api.py b/src/backend/InvenTree/part/api.py index 0b543e4871..23e154f751 100644 --- a/src/backend/InvenTree/part/api.py +++ b/src/backend/InvenTree/part/api.py @@ -1057,6 +1057,7 @@ class PartList( filter_backends = SEARCH_ORDER_FILTER ordering_fields = [ + 'id', 'name', 'creation_date', 'IPN', diff --git a/src/frontend/src/components/dashboard/DashboardWidgetLibrary.tsx b/src/frontend/src/components/dashboard/DashboardWidgetLibrary.tsx index 7b2352a18f..979d4d0f6c 100644 --- a/src/frontend/src/components/dashboard/DashboardWidgetLibrary.tsx +++ b/src/frontend/src/components/dashboard/DashboardWidgetLibrary.tsx @@ -9,6 +9,7 @@ import GetStartedWidget from './widgets/GetStartedWidget'; import LanguageSelectDashboardWidget from './widgets/LanguageSelectWidget'; import NewsWidget from './widgets/NewsWidget'; import QueryCountDashboardWidget from './widgets/QueryCountDashboardWidget'; +import QueryDashboardWidget from './widgets/QueryDashboardWidget'; import StocktakeDashboardWidget from './widgets/StocktakeDashboardWidget'; /** @@ -48,7 +49,15 @@ function BuiltinQueryCountWidgets(): DashboardWidgetProps[] { bom_valid: false // Only show parts with invalid BOMs } }), - // TODO: 'latest parts' + QueryDashboardWidget({ + label: 'latest-parts', + title: t`Latest parts`, + description: t`Latest parts`, + modelType: ModelType.part, + params: { + ordering: '-id' + } + }), // TODO: 'recently updated stock' QueryCountDashboardWidget({ title: t`Low Stock`, diff --git a/src/frontend/src/components/dashboard/widgets/QueryDashboardWidget.tsx b/src/frontend/src/components/dashboard/widgets/QueryDashboardWidget.tsx new file mode 100644 index 0000000000..527041c50a --- /dev/null +++ b/src/frontend/src/components/dashboard/widgets/QueryDashboardWidget.tsx @@ -0,0 +1,96 @@ +import { Anchor, Group } from '@mantine/core'; +import { type ReactNode, useCallback } from 'react'; +import { useNavigate } from 'react-router-dom'; + +import { StylishText } from '@lib/components/StylishText'; +import { ModelInformationDict } from '@lib/enums/ModelInformation'; +import type { ModelType } from '@lib/enums/ModelType'; +import { navigateToLink } from '@lib/functions/Navigation'; +import type { InvenTreeIconType } from '@lib/types/Icons'; +import { InvenTreeIcon } from '../../../functions/icons'; +import type { DashboardWidgetProps } from '../DashboardWidget'; + +/** + * A simple dashboard widget for displaying a link to a particular query + */ +function QueryWidget({ + modelType, + title, + icon, + params +}: Readonly<{ + modelType: ModelType; + title: string; + icon?: keyof InvenTreeIconType; + params: any; +}>): ReactNode { + const navigate = useNavigate(); + const modelProperties = ModelInformationDict[modelType]; + + const onFollowLink = useCallback( + (event: any) => { + if (modelProperties.url_overview) { + let url = modelProperties.url_overview; + + if (params) { + url += '?'; + for (const key in params) { + url += `${key}=${params[key]}&`; + } + } + + navigateToLink(url, navigate, event); + } + }, + [modelProperties, params] + ); + + return ( + + + + + {title} + + + + ); +} + +/** + * Construct a dashboard widget descriptor, which displays just a link to a particular query + */ +export default function QueryDashboardWidget({ + label, + title, + description, + modelType, + enabled = true, + params +}: { + label: string; + title: string; + description: string; + modelType: ModelType; + enabled?: boolean; + params: any; +}): DashboardWidgetProps { + return { + label: label, + title: title, + description: description, + enabled: enabled, + modelType: modelType, + minWidth: 2, + minHeight: 1, + render: () => ( + + ) + }; +}