2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-04-28 03:26:45 +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 textAlign?: 'left' | 'center' | 'right'; // The text alignment of the column
cellsStyle?: any; // The style of the cells in the column cellsStyle?: any; // The style of the cells in the column
extra?: any; // Extra data to pass to the render function 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; modelType?: ModelType;
rowStyle?: (record: T, index: number) => any; rowStyle?: (record: T, index: number) => any;
modelField?: string; modelField?: string;
onRowContextMenu?: (record: T, event: any) => void; onCellContextMenu?: (record: T, event: any) => void;
minHeight?: number; minHeight?: number;
noHeader?: boolean; noHeader?: boolean;
}; };
@ -568,16 +568,21 @@ export function InvenTreeTable<T extends Record<string, any>>({
[props.onRowClick, props.onCellClick] [props.onRowClick, props.onCellClick]
); );
// Callback when a row is right-clicked // Callback when a cell is right-clicked
const handleRowContextMenu = ({ const handleCellContextMenu = ({
record, record,
column,
event event
}: { }: {
record: any; record: any;
column: any;
event: any; event: any;
}) => { }) => {
if (props.onRowContextMenu) { if (column?.noContext === true) {
return props.onRowContextMenu(record, event); return;
}
if (props.onCellContextMenu) {
return props.onCellContextMenu(record, event);
} else if (props.rowActions) { } else if (props.rowActions) {
const empty = () => {}; const empty = () => {};
const items = props.rowActions(record).map((action) => ({ const items = props.rowActions(record).map((action) => ({
@ -693,7 +698,7 @@ export function InvenTreeTable<T extends Record<string, any>>({
overflow: 'hidden' overflow: 'hidden'
}) })
}} }}
onRowContextMenu={handleRowContextMenu} onCellContextMenu={handleCellContextMenu}
{...optionalParams} {...optionalParams}
/> />
</Box> </Box>

View File

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

View File

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

View File

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

View File

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

View File

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