Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PUI] Make breadcrumbs adjustable #8027

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/backend/InvenTree/common/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2529,6 +2529,12 @@ class Meta:
'validator': [int, MinValueValidator(0)],
'default': 100,
},
'ENABLE_LAST_BREADCRUMB': {
'name': _('Show Last Breadcrumb'),
'description': _('Show the current page in breadcrumbs'),
'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(() => {
SchrodingersGat marked this conversation as resolved.
Show resolved Hide resolved
if (userSettings.isSet('ENABLE_LAST_BREADCRUMB', false)) {
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 @@ -87,7 +87,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
6 changes: 2 additions & 4 deletions src/frontend/src/pages/build/BuildDetail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -531,10 +531,8 @@ export default function BuildDetail() {
editAction={editBuild.open}
editEnabled={user.hasChangePermission(ModelType.part)}
imageUrl={build.part_detail?.image ?? build.part_detail?.thumbnail}
breadcrumbs={[
{ name: t`Build Orders`, url: '/build' },
{ name: build.reference, url: `/build/${build.pk}` }
]}
breadcrumbs={[{ name: t`Build Orders`, url: '/build' }]}
last_crumb={[{ name: build.reference, url: `/build/${build.pk}` }]}
actions={buildActions}
/>
<PanelGroup
Expand Down
7 changes: 7 additions & 0 deletions src/frontend/src/pages/company/CompanyDetail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ import { StockItemTable } from '../../tables/stock/StockItemTable';
export type CompanyDetailProps = {
title: string;
breadcrumbs: Breadcrumb[];
last_crumb_url: string;
};

/**
Expand Down Expand Up @@ -341,6 +342,12 @@ export default function CompanyDetail(props: Readonly<CompanyDetailProps>) {
actions={companyActions}
imageUrl={company.image}
breadcrumbs={props.breadcrumbs}
last_crumb={[
{
name: company.name,
url: `${props.last_crumb_url}/${company.pk}/`
}
]}
badges={badges}
editAction={editCompany.open}
editEnabled={user.hasChangePermission(ModelType.company)}
Expand Down
1 change: 1 addition & 0 deletions src/frontend/src/pages/company/CustomerDetail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export default function CustomerDetail() {
<CompanyDetail
title={t`Customer`}
breadcrumbs={[{ name: t`Sales`, url: '/sales/' }]}
last_crumb_url="/sales/customer"
/>
);
}
1 change: 1 addition & 0 deletions src/frontend/src/pages/company/ManufacturerDetail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export default function ManufacturerDetail() {
<CompanyDetail
title={t`Manufacturer`}
breadcrumbs={[{ name: t`Purchasing`, url: '/purchasing/' }]}
last_crumb_url="/purchasing/manufacturer"
/>
);
}
9 changes: 9 additions & 0 deletions src/frontend/src/pages/company/ManufacturerPartDetail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,15 @@ export default function ManufacturerPartDetail() {
title={t`ManufacturerPart`}
subtitle={`${manufacturerPart.MPN} - ${manufacturerPart.part_detail?.name}`}
breadcrumbs={breadcrumbs}
last_crumb={[
{
name: manufacturerPart.MPN,
url: getDetailUrl(
ModelType.manufacturerpart,
manufacturerPart.pk
)
}
]}
actions={manufacturerPartActions}
imageUrl={manufacturerPart?.part_detail?.thumbnail}
editAction={editManufacturerPart.open}
Expand Down
1 change: 1 addition & 0 deletions src/frontend/src/pages/company/SupplierDetail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export default function SupplierDetail() {
<CompanyDetail
title={t`Supplier`}
breadcrumbs={[{ name: t`Purchasing`, url: '/purchasing/' }]}
last_crumb_url="/purchasing/supplier"
/>
);
}
6 changes: 6 additions & 0 deletions src/frontend/src/pages/company/SupplierPartDetail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,12 @@ export default function SupplierPartDetail() {
title={t`Supplier Part`}
subtitle={`${supplierPart.SKU} - ${supplierPart?.part_detail?.name}`}
breadcrumbs={breadcrumbs}
last_crumb={[
{
name: supplierPart.SKU,
url: `/purchasing/supplier-part/${supplierPart.pk}/`
}
]}
badges={badges}
actions={supplierPartActions}
imageUrl={supplierPart?.part_detail?.thumbnail}
Expand Down
6 changes: 6 additions & 0 deletions src/frontend/src/pages/part/PartDetail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1082,6 +1082,12 @@ export default function PartDetail() {
imageUrl={part.image}
badges={badges}
breadcrumbs={breadcrumbs}
last_crumb={[
{
name: part.name,
url: `/part/${part.pk}/`
}
]}
breadcrumbAction={() => {
setTreeOpen(true);
}}
Expand Down
6 changes: 6 additions & 0 deletions src/frontend/src/pages/purchasing/PurchaseOrderDetail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,12 @@ export default function PurchaseOrderDetail() {
subtitle={order.description}
imageUrl={order.supplier_detail?.image}
breadcrumbs={[{ name: t`Purchasing`, url: '/purchasing/' }]}
last_crumb={[
{
name: order.reference,
url: `/purchasing/purchase-order/${order.pk}`
}
]}
actions={poActions}
badges={orderBadges}
editAction={editPurchaseOrder.open}
Expand Down
3 changes: 3 additions & 0 deletions src/frontend/src/pages/sales/ReturnOrderDetail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,9 @@ export default function ReturnOrderDetail() {
badges={orderBadges}
actions={orderActions}
breadcrumbs={[{ name: t`Sales`, url: '/sales/' }]}
last_crumb={[
{ name: order.reference, url: `/sales/return-order/${order.pk}` }
]}
editAction={editReturnOrder.open}
editEnabled={user.hasChangePermission(ModelType.returnorder)}
/>
Expand Down
3 changes: 3 additions & 0 deletions src/frontend/src/pages/sales/SalesOrderDetail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,9 @@ export default function SalesOrderDetail() {
badges={orderBadges}
actions={soActions}
breadcrumbs={[{ name: t`Sales`, url: '/sales/' }]}
last_crumb={[
{ name: order.reference, url: `/sales/sales-order/${order.pk}` }
]}
editAction={editSalesOrder.open}
editEnabled={user.hasChangePermission(ModelType.salesorder)}
/>
Expand Down
6 changes: 6 additions & 0 deletions src/frontend/src/pages/stock/LocationDetail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,12 @@ export default function Stock() {
editAction={editLocation.open}
editEnabled={user.hasChangePermission(ModelType.stocklocation)}
breadcrumbs={breadcrumbs}
last_crumb={[
{
name: location.name,
url: `/stock/location/${location.pk}/`
}
]}
breadcrumbAction={() => {
setTreeOpen(true);
}}
Expand Down
6 changes: 6 additions & 0 deletions src/frontend/src/pages/stock/StockDetail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -612,6 +612,12 @@ export default function StockDetail() {
editEnabled={user.hasChangePermission(ModelType.stockitem)}
badges={stockBadges}
breadcrumbs={breadcrumbs}
last_crumb={[
{
name: stockitem.name,
url: `/stock/item/${stockitem.pk}/`
}
]}
breadcrumbAction={() => {
setTreeOpen(true);
}}
Expand Down
Loading