mirror of
https://github.com/inventree/InvenTree.git
synced 2026-07-21 22:23:03 +00:00
[bug] Bom table fix (#12436)
* Fix logic for table context menu * Memoize handleCellContextMenu
This commit is contained in:
@@ -766,69 +766,82 @@ export function InvenTreeTableInternal<T extends Record<string, any>>({
|
|||||||
}, [props.onCellContextMenu, props.rowActions, props.modelType]);
|
}, [props.onCellContextMenu, props.rowActions, props.modelType]);
|
||||||
|
|
||||||
// Callback when a cell is right-clicked
|
// Callback when a cell is right-clicked
|
||||||
const handleCellContextMenu = ({
|
const handleCellContextMenu = useCallback(
|
||||||
record,
|
({
|
||||||
column,
|
record,
|
||||||
event
|
column,
|
||||||
}: {
|
event
|
||||||
record: any;
|
}: {
|
||||||
column: any;
|
record: any;
|
||||||
event: any;
|
column: any;
|
||||||
}) => {
|
event: any;
|
||||||
if (column?.noContext === true) {
|
}) => {
|
||||||
return;
|
if (column?.noContext === true) {
|
||||||
}
|
return;
|
||||||
if (props.onCellContextMenu) {
|
}
|
||||||
return props.onCellContextMenu(record, event);
|
if (props.onCellContextMenu) {
|
||||||
}
|
return props.onCellContextMenu(record, event);
|
||||||
|
|
||||||
const empty = () => {};
|
|
||||||
let items: ContextMenuItemOptions[] = [];
|
|
||||||
|
|
||||||
if (!!props.rowActions) {
|
|
||||||
items = props.rowActions(record).map((action) => ({
|
|
||||||
key: action.title ?? '',
|
|
||||||
title: action.title ?? '',
|
|
||||||
color: action.color,
|
|
||||||
icon: action.icon,
|
|
||||||
onClick: action.onClick ?? empty,
|
|
||||||
hidden: action.hidden,
|
|
||||||
disabled: action.disabled
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (props.modelType && props.detailAction !== false) {
|
|
||||||
// Add action to navigate to the detail view
|
|
||||||
const accessor = props.modelField ?? 'pk';
|
|
||||||
const pk = resolveItem(record, accessor);
|
|
||||||
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({
|
const empty = () => {};
|
||||||
key: 'detail',
|
let items: ContextMenuItemOptions[] = [];
|
||||||
title: detailsText,
|
|
||||||
icon: <IconArrowRight />,
|
|
||||||
onClick: (event: any) => {
|
|
||||||
cancelEvent(event);
|
|
||||||
if (eventModified(event as any)) {
|
|
||||||
navigateToLink(url, navigate, event);
|
|
||||||
} else {
|
|
||||||
showRowPreview(pk);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
return showContextMenu?.(items)(event);
|
if (!!props.rowActions) {
|
||||||
};
|
items = props.rowActions(record).map((action) => ({
|
||||||
|
key: action.title ?? '',
|
||||||
|
title: action.title ?? '',
|
||||||
|
color: action.color,
|
||||||
|
icon: action.icon,
|
||||||
|
onClick: action.onClick ?? empty,
|
||||||
|
hidden: action.hidden,
|
||||||
|
disabled: action.disabled
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (props.modelType && props.detailAction !== false) {
|
||||||
|
// Add action to navigate to the detail view
|
||||||
|
const accessor = props.modelField ?? 'pk';
|
||||||
|
const pk = resolveItem(record, accessor);
|
||||||
|
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({
|
||||||
|
key: 'detail',
|
||||||
|
title: detailsText,
|
||||||
|
icon: <IconArrowRight />,
|
||||||
|
onClick: (event: any) => {
|
||||||
|
cancelEvent(event);
|
||||||
|
if (!showPreviewPanel || eventModified(event as any)) {
|
||||||
|
navigateToLink(url, navigate, event);
|
||||||
|
} else {
|
||||||
|
showRowPreview(pk);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return showContextMenu?.(items)(event);
|
||||||
|
},
|
||||||
|
[
|
||||||
|
props.onCellContextMenu,
|
||||||
|
props.rowActions,
|
||||||
|
props.modelType,
|
||||||
|
props.detailAction,
|
||||||
|
props.modelField,
|
||||||
|
showPreviewPanel,
|
||||||
|
showRowPreview,
|
||||||
|
showContextMenu,
|
||||||
|
navigate
|
||||||
|
]
|
||||||
|
);
|
||||||
|
|
||||||
// Pagination refresh table if pageSize changes
|
// Pagination refresh table if pageSize changes
|
||||||
const updatePageSize = useCallback((size: number) => {
|
const updatePageSize = useCallback((size: number) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user