2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-05-03 05:48:47 +00:00

Build required widget (#8610)

* Implement "required for build orders" dashboard widget

* Allow dashboard widges to be optionally disabled

* Fix for enabled check
This commit is contained in:
Oliver 2024-12-02 13:41:31 +11:00 committed by GitHub
parent f7697bd481
commit 147ca53629
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 24 additions and 12 deletions

View File

@ -15,6 +15,7 @@ export interface DashboardWidgetProps {
label: string; label: string;
title: string; title: string;
description: string; description: string;
enabled?: boolean;
minWidth?: number; minWidth?: number;
minHeight?: number; minHeight?: number;
render: () => JSX.Element; render: () => JSX.Element;
@ -35,12 +36,9 @@ export default function DashboardWidget({
removing: boolean; removing: boolean;
onRemove: () => void; onRemove: () => void;
}>) { }>) {
// TODO: Implement visibility check if (item.enabled == false) {
// if (!props?.visible?.() == false) { return null;
// return null; }
// }
// TODO: Add button to remove widget (if "editing")
return ( return (
<Paper withBorder key={item.label} shadow='sm' p='xs'> <Paper withBorder key={item.label} shadow='sm' p='xs'>

View File

@ -1,6 +1,7 @@
import { t } from '@lingui/macro'; import { t } from '@lingui/macro';
import { ModelType } from '../../enums/ModelType'; import { ModelType } from '../../enums/ModelType';
import { useGlobalSettingsState } from '../../states/SettingsState';
import type { DashboardWidgetProps } from './DashboardWidget'; import type { DashboardWidgetProps } from './DashboardWidget';
import ColorToggleDashboardWidget from './widgets/ColorToggleWidget'; import ColorToggleDashboardWidget from './widgets/ColorToggleWidget';
import GetStartedWidget from './widgets/GetStartedWidget'; import GetStartedWidget from './widgets/GetStartedWidget';
@ -13,6 +14,8 @@ import QueryCountDashboardWidget from './widgets/QueryCountDashboardWidget';
* @returns A list of built-in dashboard widgets which display the number of results for a particular query * @returns A list of built-in dashboard widgets which display the number of results for a particular query
*/ */
export function BuiltinQueryCountWidgets(): DashboardWidgetProps[] { export function BuiltinQueryCountWidgets(): DashboardWidgetProps[] {
const globalSettings = useGlobalSettingsState.getState();
return [ return [
QueryCountDashboardWidget({ QueryCountDashboardWidget({
label: 'sub-prt', label: 'sub-prt',
@ -38,22 +41,28 @@ export function BuiltinQueryCountWidgets(): DashboardWidgetProps[] {
modelType: ModelType.part, modelType: ModelType.part,
params: { low_stock: true, active: true } params: { low_stock: true, active: true }
}), }),
// TODO: Required for build orders QueryCountDashboardWidget({
title: t`Required for Build Orders`,
label: 'bld-req',
description: t`Show parts which are required for active build orders`,
modelType: ModelType.part,
params: { stock_to_build: true }
}),
QueryCountDashboardWidget({ QueryCountDashboardWidget({
title: t`Expired Stock Items`, title: t`Expired Stock Items`,
label: 'exp-stk', label: 'exp-stk',
description: t`Show the number of stock items which have expired`, description: t`Show the number of stock items which have expired`,
modelType: ModelType.stockitem, modelType: ModelType.stockitem,
params: { expired: true } params: { expired: true },
// TODO: Hide if expiry is disabled enabled: globalSettings.isSet('STOCK_ENABLE_EXPIRY')
}), }),
QueryCountDashboardWidget({ QueryCountDashboardWidget({
title: t`Stale Stock Items`, title: t`Stale Stock Items`,
label: 'stl-stk', label: 'stl-stk',
description: t`Show the number of stock items which are stale`, description: t`Show the number of stock items which are stale`,
modelType: ModelType.stockitem, modelType: ModelType.stockitem,
params: { stale: true } params: { stale: true },
// TODO: Hide if expiry is disabled enabled: globalSettings.isSet('STOCK_ENABLE_EXPIRY')
}), }),
QueryCountDashboardWidget({ QueryCountDashboardWidget({
title: t`Active Build Orders`, title: t`Active Build Orders`,

View File

@ -102,18 +102,21 @@ export default function QueryCountDashboardWidget({
title, title,
description, description,
modelType, modelType,
enabled = true,
params params
}: { }: {
label: string; label: string;
title: string; title: string;
description: string; description: string;
modelType: ModelType; modelType: ModelType;
enabled?: boolean;
params: any; params: any;
}): DashboardWidgetProps { }): DashboardWidgetProps {
return { return {
label: label, label: label,
title: title, title: title,
description: description, description: description,
enabled: enabled,
minWidth: 2, minWidth: 2,
minHeight: 1, minHeight: 1,
render: () => ( render: () => (

View File

@ -93,7 +93,9 @@ export function useDashboardItems(): DashboardLibraryProps {
}, [pluginQuery, inventreeContext]); }, [pluginQuery, inventreeContext]);
const items: DashboardWidgetProps[] = useMemo(() => { const items: DashboardWidgetProps[] = useMemo(() => {
return [...builtin, ...pluginDashboardItems]; const widgets = [...builtin, ...pluginDashboardItems];
return widgets.filter((item) => item.enabled ?? true);
}, [builtin, pluginDashboardItems]); }, [builtin, pluginDashboardItems]);
const loaded: boolean = useMemo(() => { const loaded: boolean = useMemo(() => {