2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-04-27 19:16:44 +00:00

[PUI] fix Table Context Menu Links (#8623)

* Add switch to disable context menu
Fixes #8553

* make attachment links right-clickable
This commit is contained in:
Matthias Mair 2024-12-02 23:07:18 +01:00 committed by GitHub
parent 4f3e8cb0a0
commit a20fd9d231
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 24 additions and 11 deletions

View File

@ -18,6 +18,7 @@ export type TableColumnProps<T = any> = {
textAlign?: 'left' | 'center' | 'right'; // The text alignment of the column
cellsStyle?: any; // The style of the cells in the column
extra?: any; // Extra data to pass to the render function
noContext?: boolean; // Disable context menu for this column
};
/**

View File

@ -88,7 +88,7 @@ export type InvenTreeTableProps<T = any> = {
modelType?: ModelType;
rowStyle?: (record: T, index: number) => any;
modelField?: string;
onRowContextMenu?: (record: T, event: any) => void;
onCellContextMenu?: (record: T, event: any) => void;
minHeight?: number;
noHeader?: boolean;
};
@ -568,16 +568,21 @@ export function InvenTreeTable<T extends Record<string, any>>({
[props.onRowClick, props.onCellClick]
);
// Callback when a row is right-clicked
const handleRowContextMenu = ({
// Callback when a cell is right-clicked
const handleCellContextMenu = ({
record,
column,
event
}: {
record: any;
column: any;
event: any;
}) => {
if (props.onRowContextMenu) {
return props.onRowContextMenu(record, event);
if (column?.noContext === true) {
return;
}
if (props.onCellContextMenu) {
return props.onCellContextMenu(record, event);
} else if (props.rowActions) {
const empty = () => {};
const items = props.rowActions(record).map((action) => ({
@ -693,7 +698,7 @@ export function InvenTreeTable<T extends Record<string, any>>({
overflow: 'hidden'
})
}}
onRowContextMenu={handleRowContextMenu}
onCellContextMenu={handleCellContextMenu}
{...optionalParams}
/>
</Box>

View File

@ -48,7 +48,8 @@ function attachmentTableColumns(): TableColumn[] {
} else {
return '-';
}
}
},
noContext: true
},
{
accessor: 'comment',

View File

@ -61,7 +61,8 @@ export default function ImportSesssionTable() {
render: (record: any) => (
<AttachmentLink attachment={record.data_file} />
),
sortable: false
sortable: false,
noContext: true
},
DateColumn({
accessor: 'timestamp',

View File

@ -28,7 +28,8 @@ export default function StocktakeReportTable() {
title: t`Report`,
sortable: false,
switchable: false,
render: (record: any) => <AttachmentLink attachment={record.report} />
render: (record: any) => <AttachmentLink attachment={record.report} />,
noContext: true
},
{
accessor: 'part_count',

View File

@ -219,7 +219,8 @@ export function TemplateTable({
}
return <AttachmentLink attachment={record.template} />;
}
},
noContext: true
},
{
accessor: 'model_type',

View File

@ -195,7 +195,10 @@ export default function StockItemTestResultTable({
accessor: 'attachment',
title: t`Attachment`,
render: (record: any) =>
record.attachment && <AttachmentLink attachment={record.attachment} />
record.attachment && (
<AttachmentLink attachment={record.attachment} />
),
noContext: true
},
NoteColumn({}),
DateColumn({}),