Skip to content

Commit

Permalink
[frontend] trial
Browse files Browse the repository at this point in the history
  • Loading branch information
Kedae committed Sep 23, 2024
1 parent 6a98262 commit 4bc9722
Showing 1 changed file with 11 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { createStyles } from '@mui/styles';
import { useNavigate } from 'react-router-dom';
import { useDataTableContext } from '../dataTableUtils';
import type { DataTableCellProps, DataTableLineProps } from '../dataTableTypes';
import { DataTableColumn } from '../dataTableTypes';
import { DataTableColumn, DataTableVariant } from '../dataTableTypes';
import type { Theme } from '../../Theme';
import { getMainRepresentative } from '../../../utils/defaultRepresentatives';

Expand Down Expand Up @@ -118,6 +118,7 @@ const DataTableLine = ({
disableNavigation,
onLineClick,
selectOnLineClick,
variant,
} = useDataTableContext();
const data = useLineData(row);

Expand All @@ -142,6 +143,8 @@ const DataTableLine = ({
const endWithNavigate = effectiveColumns.at(-1)?.id === 'navigate';

const handleSelectLine = (event: React.MouseEvent) => {
event.preventDefault();
event.stopPropagation();
if (event.shiftKey) {
onToggleShiftEntity(index, data, event);
} else {
Expand All @@ -152,12 +155,14 @@ const DataTableLine = ({
const handleRowClick = (event: React.MouseEvent) => {
event.preventDefault();
event.stopPropagation();
if (onLineClick) {
if (selectOnLineClick) {
handleSelectLine(event);
} else if (onLineClick) {
onLineClick(data);
} else if (navigable) {
if (event.ctrlKey || event.button === 1) {
if (event.ctrlKey) {
window.open(link, '_blank');
} else if (event.button !== 2) {
} else {
navigate(link);
}
}
Expand All @@ -168,8 +173,8 @@ const DataTableLine = ({
key={row.id}
className={classes.row}
// using onMouseDown to redirect before drag and drop happens when used in dashboard widgets
onMouseDown={handleRowClick}
onClick={selectOnLineClick ? handleSelectLine : undefined}
onMouseDown={variant === DataTableVariant.widget ? handleRowClick : undefined}
onClick={variant !== DataTableVariant.widget ? handleRowClick : undefined}
style={{ cursor: clickable ? 'pointer' : 'unset' }}
data-testid={getMainRepresentative(data)}
>
Expand Down

0 comments on commit 4bc9722

Please sign in to comment.