Skip to content

Commit

Permalink
Add user settings for last breadcrumb
Browse files Browse the repository at this point in the history
  • Loading branch information
matmair committed Aug 28, 2024
1 parent 411f31d commit 5e084b4
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 4 deletions.
8 changes: 8 additions & 0 deletions src/backend/InvenTree/common/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2528,6 +2528,14 @@ class Meta:
'validator': [int, MinValueValidator(0)],
'default': 100,
},
'ENABLE_LAST_BREADCRUMB': {
'name': _('Show Last Breadcrumb'),
'description': _(
'Show the current page in breadcrumbs of the navigation bar (if available)'
),
'default': False,
'validator': bool,
},
'NOTIFICATION_ERROR_REPORT': {
'name': _('Receive error reports'),
'description': _('Receive notifications for system errors'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
{% include "InvenTree/settings/setting.html" with key="DISPLAY_SCHEDULE_TAB" icon="fa-calendar-alt" user_setting=True %}
{% include "InvenTree/settings/setting.html" with key="DISPLAY_STOCKTAKE_TAB" icon="fa-clipboard-check" user_setting=True %}
{% include "InvenTree/settings/setting.html" with key="TABLE_STRING_MAX_LENGTH" icon="fa-table" user_setting=True %}
{% include "InvenTree/settings/setting.html" with key="ENABLE_LAST_BREADCRUMB" icon="fa-table" user_setting=True %}
</tbody>
</table>
</div>
Expand Down
19 changes: 16 additions & 3 deletions src/frontend/src/components/nav/PageDetail.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { Group, Paper, Space, Stack, Text } from '@mantine/core';
import { useHotkeys } from '@mantine/hooks';
import { Fragment, ReactNode } from 'react';
import { Fragment, ReactNode, useMemo } from 'react';

import { useUserSettingsState } from '../../states/SettingsState';
import { ApiImage } from '../images/ApiImage';
import { StylishText } from '../items/StylishText';
import { Breadcrumb, BreadcrumbList } from './BreadcrumbList';
Expand All @@ -14,6 +15,7 @@ interface PageDetailInterface {
detail?: ReactNode;
badges?: ReactNode[];
breadcrumbs?: Breadcrumb[];
last_crumb?: Breadcrumb[];
breadcrumbAction?: () => void;
actions?: ReactNode[];
editAction?: () => void;
Expand All @@ -34,11 +36,13 @@ export function PageDetail({
badges,
imageUrl,
breadcrumbs,
last_crumb,
breadcrumbAction,
actions,
editAction,
editEnabled
}: Readonly<PageDetailInterface>) {
const userSettings = useUserSettingsState();
useHotkeys([
[
'mod+E',
Expand All @@ -50,12 +54,21 @@ export function PageDetail({
]
]);

// breadcrumb caching
const computedBreadcrumbs = useMemo(() => {
if (userSettings.isSet('ENABLE_LAST_BREADCRUMB')) {
return [...(breadcrumbs ?? []), ...(last_crumb ?? [])];
} else {
return breadcrumbs;
}
}, [breadcrumbs, last_crumb, userSettings]);

return (
<Stack gap="xs">
{breadcrumbs && breadcrumbs.length > 0 && (
{computedBreadcrumbs && computedBreadcrumbs.length > 0 && (
<BreadcrumbList
navCallback={breadcrumbAction}
breadcrumbs={breadcrumbs}
breadcrumbs={computedBreadcrumbs}
/>
)}
<Paper p="xs" radius="xs" shadow="xs">
Expand Down
3 changes: 2 additions & 1 deletion src/frontend/src/pages/Index/Settings/UserSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ export default function UserSettings() {
'PART_SHOW_QUANTITY_IN_FORMS',
'DISPLAY_SCHEDULE_TAB',
'DISPLAY_STOCKTAKE_TAB',
'TABLE_STRING_MAX_LENGTH'
'TABLE_STRING_MAX_LENGTH',
'ENABLE_LAST_BREADCRUMB'
]}
/>
)
Expand Down

0 comments on commit 5e084b4

Please sign in to comment.