mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Enable "link" column for tables (#6765)
- Have to handle click events cleverly
This commit is contained in:
parent
0cb4e8ec1c
commit
7227670142
@ -17,6 +17,7 @@ import { useMemo, useState } from 'react';
|
||||
|
||||
import { api } from '../../App';
|
||||
import { UserRoles } from '../../enums/Roles';
|
||||
import { cancelEvent } from '../../functions/events';
|
||||
import { InvenTreeIcon } from '../../functions/icons';
|
||||
import { useUserState } from '../../states/UserState';
|
||||
import { PartThumbTable } from '../../tables/part/PartThumbTable';
|
||||
@ -267,9 +268,8 @@ function ImageActionButtons({
|
||||
size="lg"
|
||||
tooltipAlignment="top"
|
||||
onClick={(event: any) => {
|
||||
event?.preventDefault();
|
||||
event?.stopPropagation();
|
||||
event?.nativeEvent?.stopImmediatePropagation();
|
||||
cancelEvent(event);
|
||||
|
||||
modals.open({
|
||||
title: <StylishText size="xl">{t`Select Image`}</StylishText>,
|
||||
size: 'xxl',
|
||||
@ -288,9 +288,7 @@ function ImageActionButtons({
|
||||
size="lg"
|
||||
tooltipAlignment="top"
|
||||
onClick={(event: any) => {
|
||||
event?.preventDefault();
|
||||
event?.stopPropagation();
|
||||
event?.nativeEvent?.stopImmediatePropagation();
|
||||
cancelEvent(event);
|
||||
modals.open({
|
||||
title: <StylishText size="xl">{t`Upload Image`}</StylishText>,
|
||||
children: (
|
||||
@ -310,9 +308,7 @@ function ImageActionButtons({
|
||||
size="lg"
|
||||
tooltipAlignment="top"
|
||||
onClick={(event: any) => {
|
||||
event?.preventDefault();
|
||||
event?.stopPropagation();
|
||||
event?.nativeEvent?.stopImmediatePropagation();
|
||||
cancelEvent(event);
|
||||
removeModal(apiPath, setImage);
|
||||
}}
|
||||
/>
|
||||
@ -349,9 +345,7 @@ export function DetailsImage(props: DetailImageProps) {
|
||||
}, [props.imageActions]);
|
||||
|
||||
const expandImage = (event: any) => {
|
||||
event?.preventDefault();
|
||||
event?.stopPropagation();
|
||||
event?.nativeEvent?.stopImmediatePropagation();
|
||||
cancelEvent(event);
|
||||
modals.open({
|
||||
children: <ApiImage src={img} />,
|
||||
withCloseButton: false
|
||||
|
6
src/frontend/src/functions/events.tsx
Normal file
6
src/frontend/src/functions/events.tsx
Normal file
@ -0,0 +1,6 @@
|
||||
// Helper function to cancel event propagation
|
||||
export function cancelEvent(event: any) {
|
||||
event?.preventDefault();
|
||||
event?.stopPropagation();
|
||||
event?.nativeEvent?.stopImmediatePropagation();
|
||||
}
|
@ -2,6 +2,7 @@
|
||||
* Common rendering functions for table column data.
|
||||
*/
|
||||
import { t } from '@lingui/macro';
|
||||
import { Anchor } from '@mantine/core';
|
||||
|
||||
import { Thumbnail } from '../components/images/Thumbnail';
|
||||
import { ProgressBar } from '../components/items/ProgressBar';
|
||||
@ -10,6 +11,7 @@ import { TableStatusRenderer } from '../components/render/StatusRenderer';
|
||||
import { RenderOwner } from '../components/render/User';
|
||||
import { formatCurrency, renderDate } from '../defaults/formatters';
|
||||
import { ModelType } from '../enums/ModelType';
|
||||
import { cancelEvent } from '../functions/events';
|
||||
import { TableColumn } from './Column';
|
||||
import { ProjectCodeHoverCard } from './TableHoverCard';
|
||||
|
||||
@ -55,11 +57,36 @@ export function DescriptionColumn({
|
||||
};
|
||||
}
|
||||
|
||||
export function LinkColumn(): TableColumn {
|
||||
export function LinkColumn({
|
||||
accessor = 'link'
|
||||
}: {
|
||||
accessor?: string;
|
||||
}): TableColumn {
|
||||
return {
|
||||
accessor: 'link',
|
||||
sortable: false
|
||||
// TODO: Custom URL hyperlink renderer?
|
||||
accessor: accessor,
|
||||
sortable: false,
|
||||
render: (record: any) => {
|
||||
let url = record[accessor];
|
||||
|
||||
if (!url) {
|
||||
return '-';
|
||||
}
|
||||
|
||||
return (
|
||||
<Anchor
|
||||
href={url}
|
||||
target="_blank"
|
||||
rel="noreferrer noopener"
|
||||
onClick={(event: any) => {
|
||||
cancelEvent(event);
|
||||
|
||||
window.open(url, '_blank', 'noopener,noreferrer');
|
||||
}}
|
||||
>
|
||||
{url}
|
||||
</Anchor>
|
||||
);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -4,6 +4,7 @@ import { Menu } from '@mantine/core';
|
||||
import { IconCopy, IconDots, IconEdit, IconTrash } from '@tabler/icons-react';
|
||||
import { ReactNode, useMemo, useState } from 'react';
|
||||
|
||||
import { cancelEvent } from '../functions/events';
|
||||
import { notYetImplemented } from '../functions/notifications';
|
||||
|
||||
// Type definition for a table row action
|
||||
@ -93,9 +94,7 @@ export function RowActions({
|
||||
// Prevent default event handling
|
||||
// Ref: https://icflorescu.github.io/mantine-datatable/examples/links-or-buttons-inside-clickable-rows-or-cells
|
||||
function openMenu(event: any) {
|
||||
event?.preventDefault();
|
||||
event?.stopPropagation();
|
||||
event?.nativeEvent?.stopImmediatePropagation();
|
||||
cancelEvent(event);
|
||||
setOpened(!opened);
|
||||
}
|
||||
|
||||
@ -118,9 +117,7 @@ export function RowActions({
|
||||
icon={action.icon}
|
||||
onClick={(event) => {
|
||||
// Prevent clicking on the action from selecting the row itself
|
||||
event?.preventDefault();
|
||||
event?.stopPropagation();
|
||||
event?.nativeEvent?.stopImmediatePropagation();
|
||||
cancelEvent(event);
|
||||
|
||||
if (action.onClick) {
|
||||
action.onClick();
|
||||
|
@ -11,6 +11,7 @@ import { YesNoButton } from '../../components/items/YesNoButton';
|
||||
import { ApiEndpoints } from '../../enums/ApiEndpoints';
|
||||
import { ModelType } from '../../enums/ModelType';
|
||||
import { UserRoles } from '../../enums/Roles';
|
||||
import { cancelEvent } from '../../functions/events';
|
||||
import {
|
||||
useCreateApiFormModal,
|
||||
useEditApiFormModal
|
||||
@ -60,9 +61,7 @@ function ParameterCell({
|
||||
}
|
||||
|
||||
const handleClick = useCallback((event: any) => {
|
||||
event?.preventDefault();
|
||||
event?.stopPropagation();
|
||||
event?.nativeEvent?.stopImmediatePropagation();
|
||||
cancelEvent(event);
|
||||
onEdit();
|
||||
}, []);
|
||||
|
||||
|
@ -162,7 +162,7 @@ function partTableColumns(): TableColumn[] {
|
||||
render: (record: any) =>
|
||||
formatPriceRange(record.pricing_min, record.pricing_max)
|
||||
},
|
||||
LinkColumn()
|
||||
LinkColumn({})
|
||||
];
|
||||
}
|
||||
|
||||
|
@ -54,7 +54,7 @@ export function ManufacturerPartTable({ params }: { params: any }): ReactNode {
|
||||
sortable: true
|
||||
},
|
||||
DescriptionColumn({}),
|
||||
LinkColumn()
|
||||
LinkColumn({})
|
||||
];
|
||||
}, [params]);
|
||||
|
||||
|
@ -26,6 +26,7 @@ import { useUserState } from '../../states/UserState';
|
||||
import {
|
||||
CurrencyColumn,
|
||||
LinkColumn,
|
||||
NoteColumn,
|
||||
ReferenceColumn,
|
||||
TargetDateColumn,
|
||||
TotalPriceColumn
|
||||
@ -177,11 +178,8 @@ export function PurchaseOrderLineItemTable({
|
||||
? RenderStockLocation({ instance: record.destination_detail })
|
||||
: '-'
|
||||
},
|
||||
{
|
||||
accessor: 'notes',
|
||||
title: t`Notes`
|
||||
},
|
||||
LinkColumn()
|
||||
NoteColumn(),
|
||||
LinkColumn({})
|
||||
];
|
||||
}, [orderId, user]);
|
||||
|
||||
|
@ -122,7 +122,7 @@ export function SupplierPartTable({ params }: { params: any }): ReactNode {
|
||||
);
|
||||
}
|
||||
},
|
||||
LinkColumn(),
|
||||
LinkColumn({}),
|
||||
NoteColumn(),
|
||||
{
|
||||
accessor: 'available',
|
||||
|
Loading…
Reference in New Issue
Block a user