2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-10-30 04:35:42 +00:00

Table refactoring: (#10662)

- Display model type in the "view details" action
This commit is contained in:
Oliver
2025-10-24 15:55:43 +11:00
committed by GitHub
parent c4805504c0
commit 1fa607b96a
4 changed files with 37 additions and 8 deletions

View File

@@ -173,6 +173,7 @@ export type RowViewProps = RowAction & RowModelProps;
* @param barcodeActions : any[] - List of barcode actions * @param barcodeActions : any[] - List of barcode actions
* @param tableFilters : TableFilter[] - List of custom filters * @param tableFilters : TableFilter[] - List of custom filters
* @param tableActions : any[] - List of custom action groups * @param tableActions : any[] - List of custom action groups
* @param detailAction: boolean - Enable detail action for each row (default = true)
* @param dataFormatter : (data: any) => any - Callback function to reformat data returned by server (if not in default format) * @param dataFormatter : (data: any) => any - Callback function to reformat data returned by server (if not in default format)
* @param rowActions : (record: any) => RowAction[] - Callback function to generate row actions * @param rowActions : (record: any) => RowAction[] - Callback function to generate row actions
* @param onRowClick : (record: any, index: number, event: any) => void - Callback function when a row is clicked * @param onRowClick : (record: any, index: number, event: any) => void - Callback function when a row is clicked
@@ -204,6 +205,7 @@ export type InvenTreeTableProps<T = any> = {
rowExpansion?: DataTableRowExpansionProps<T>; rowExpansion?: DataTableRowExpansionProps<T>;
dataFormatter?: (data: any) => any; dataFormatter?: (data: any) => any;
rowActions?: (record: T) => RowAction[]; rowActions?: (record: T) => RowAction[];
detailAction?: boolean;
onRowClick?: (record: T, index: number, event: any) => void; onRowClick?: (record: T, index: number, event: any) => void;
onCellClick?: DataTableCellClickHandler<T>; onCellClick?: DataTableCellClickHandler<T>;
modelType?: ModelType; modelType?: ModelType;

View File

@@ -1,4 +1,5 @@
import { RowActions } from '@lib/components/RowActions'; import { RowActions } from '@lib/components/RowActions';
import { ModelInformationDict } from '@lib/enums/ModelInformation';
import { resolveItem } from '@lib/functions/Conversion'; import { resolveItem } from '@lib/functions/Conversion';
import { cancelEvent } from '@lib/functions/Events'; import { cancelEvent } from '@lib/functions/Events';
import { getDetailUrl } from '@lib/functions/Navigation'; import { getDetailUrl } from '@lib/functions/Navigation';
@@ -678,14 +679,24 @@ export function InvenTreeTable<T extends Record<string, any>>({
})); }));
} }
if (props.modelType) { if (props.modelType && props.detailAction !== false) {
// Add action to navigate to the detail view // Add action to navigate to the detail view
const accessor = props.modelField ?? 'pk'; const accessor = props.modelField ?? 'pk';
const pk = resolveItem(record, accessor); const pk = resolveItem(record, accessor);
const url = getDetailUrl(props.modelType, pk); const url = getDetailUrl(props.modelType, pk);
const model: string | undefined =
ModelInformationDict[props.modelType]?.label?.();
let detailsText: string = t`View details`;
if (!!model) {
detailsText = t`View ${model}`;
}
items.push({ items.push({
key: 'detail', key: 'detail',
title: t`View details`, title: detailsText,
icon: <IconArrowRight />, icon: <IconArrowRight />,
onClick: (event: any) => { onClick: (event: any) => {
cancelEvent(event); cancelEvent(event);

View File

@@ -957,6 +957,7 @@ export default function BuildLineTable({
enableSelection: true, enableSelection: true,
enableLabels: true, enableLabels: true,
modelType: ModelType.buildline, modelType: ModelType.buildline,
detailAction: false,
onCellClick: () => {}, onCellClick: () => {},
rowExpansion: rowExpansion rowExpansion: rowExpansion
}} }}

View File

@@ -5,7 +5,8 @@ import { ActionButton } from '@lib/components/ActionButton';
import { import {
type RowAction, type RowAction,
RowDeleteAction, RowDeleteAction,
RowEditAction RowEditAction,
RowViewAction
} from '@lib/components/RowActions'; } from '@lib/components/RowActions';
import { ApiEndpoints } from '@lib/enums/ApiEndpoints'; import { ApiEndpoints } from '@lib/enums/ApiEndpoints';
import { ModelType } from '@lib/enums/ModelType'; import { ModelType } from '@lib/enums/ModelType';
@@ -15,6 +16,7 @@ import type { TableFilter } from '@lib/types/Filters';
import type { StockOperationProps } from '@lib/types/Forms'; import type { StockOperationProps } from '@lib/types/Forms';
import type { TableColumn } from '@lib/types/Tables'; import type { TableColumn } from '@lib/types/Tables';
import { IconTruckDelivery } from '@tabler/icons-react'; import { IconTruckDelivery } from '@tabler/icons-react';
import { useNavigate } from 'react-router-dom';
import { formatDate } from '../../defaults/formatters'; import { formatDate } from '../../defaults/formatters';
import { useSalesOrderAllocationFields } from '../../forms/SalesOrderForms'; import { useSalesOrderAllocationFields } from '../../forms/SalesOrderForms';
import { import {
@@ -61,6 +63,7 @@ export default function SalesOrderAllocationTable({
modelField?: string; modelField?: string;
}>) { }>) {
const user = useUserState(); const user = useUserState();
const navigate = useNavigate();
const tableId = useMemo(() => { const tableId = useMemo(() => {
let id = 'salesorderallocations'; let id = 'salesorderallocations';
@@ -221,13 +224,13 @@ export default function SalesOrderAllocationTable({
// Do not allow "shipped" items to be manipulated // Do not allow "shipped" items to be manipulated
const isShipped = !!record.shipment_detail?.shipment_date; const isShipped = !!record.shipment_detail?.shipment_date;
if (isShipped || !allowEdit) {
return [];
}
return [ return [
RowEditAction({ RowEditAction({
tooltip: t`Edit Allocation`, tooltip: t`Edit Allocation`,
hidden:
isShipped ||
!allowEdit ||
!user.hasChangeRole(UserRoles.sales_order),
onClick: () => { onClick: () => {
setSelectedAllocation(record.pk); setSelectedAllocation(record.pk);
setSelectedShipment(record.shipment); setSelectedShipment(record.shipment);
@@ -236,14 +239,26 @@ export default function SalesOrderAllocationTable({
}), }),
RowDeleteAction({ RowDeleteAction({
tooltip: t`Delete Allocation`, tooltip: t`Delete Allocation`,
hidden:
isShipped ||
!allowEdit ||
!user.hasDeleteRole(UserRoles.sales_order),
onClick: () => { onClick: () => {
setSelectedAllocation(record.pk); setSelectedAllocation(record.pk);
deleteAllocation.open(); deleteAllocation.open();
} }
}),
RowViewAction({
tooltip: t`View Shipment`,
title: t`View Shipment`,
hidden: !record.shipment || !!shipmentId,
modelId: record.shipment,
modelType: ModelType.salesordershipment,
navigate: navigate
}) })
]; ];
}, },
[allowEdit, user] [allowEdit, shipmentId, user]
); );
const stockOperationProps: StockOperationProps = useMemo(() => { const stockOperationProps: StockOperationProps = useMemo(() => {