mirror of
https://github.com/inventree/InvenTree.git
synced 2026-05-06 09:43:38 +00:00
Implement Latest parts dashboard widget (#11540)
* Implement Latest parts dashboard widget * Removed unused variables * Fix StylishText include
This commit is contained in:
@@ -1,11 +1,14 @@
|
|||||||
"""InvenTree API version information."""
|
"""InvenTree API version information."""
|
||||||
|
|
||||||
# InvenTree API version
|
# 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."""
|
"""Increment this API version number whenever there is a significant change to the API that any clients need to know about."""
|
||||||
|
|
||||||
INVENTREE_API_TEXT = """
|
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
|
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
|
- Adds new "bom" ruleset and associated permissions for BOM management, separate from the "part" ruleset which remains focused on part management
|
||||||
|
|
||||||
|
|||||||
@@ -1057,6 +1057,7 @@ class PartList(
|
|||||||
filter_backends = SEARCH_ORDER_FILTER
|
filter_backends = SEARCH_ORDER_FILTER
|
||||||
|
|
||||||
ordering_fields = [
|
ordering_fields = [
|
||||||
|
'id',
|
||||||
'name',
|
'name',
|
||||||
'creation_date',
|
'creation_date',
|
||||||
'IPN',
|
'IPN',
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import GetStartedWidget from './widgets/GetStartedWidget';
|
|||||||
import LanguageSelectDashboardWidget from './widgets/LanguageSelectWidget';
|
import LanguageSelectDashboardWidget from './widgets/LanguageSelectWidget';
|
||||||
import NewsWidget from './widgets/NewsWidget';
|
import NewsWidget from './widgets/NewsWidget';
|
||||||
import QueryCountDashboardWidget from './widgets/QueryCountDashboardWidget';
|
import QueryCountDashboardWidget from './widgets/QueryCountDashboardWidget';
|
||||||
|
import QueryDashboardWidget from './widgets/QueryDashboardWidget';
|
||||||
import StocktakeDashboardWidget from './widgets/StocktakeDashboardWidget';
|
import StocktakeDashboardWidget from './widgets/StocktakeDashboardWidget';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -48,7 +49,15 @@ function BuiltinQueryCountWidgets(): DashboardWidgetProps[] {
|
|||||||
bom_valid: false // Only show parts with invalid BOMs
|
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'
|
// TODO: 'recently updated stock'
|
||||||
QueryCountDashboardWidget({
|
QueryCountDashboardWidget({
|
||||||
title: t`Low Stock`,
|
title: t`Low Stock`,
|
||||||
|
|||||||
@@ -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 (
|
||||||
|
<Anchor href='#' onClick={onFollowLink} underline='never'>
|
||||||
|
<Group
|
||||||
|
gap='xs'
|
||||||
|
wrap='nowrap'
|
||||||
|
justify='space-between'
|
||||||
|
align='center'
|
||||||
|
style={{ height: '100%' }}
|
||||||
|
>
|
||||||
|
<Group gap='xs'>
|
||||||
|
<InvenTreeIcon icon={icon ?? modelProperties.icon} />
|
||||||
|
<StylishText size='md'>{title}</StylishText>
|
||||||
|
</Group>
|
||||||
|
</Group>
|
||||||
|
</Anchor>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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: () => (
|
||||||
|
<QueryWidget modelType={modelType} title={title} params={params} />
|
||||||
|
)
|
||||||
|
};
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user