Skip to content

Commit

Permalink
[frontend] disable redirect on row click
Browse files Browse the repository at this point in the history
  • Loading branch information
ValentinBouzinFiligran committed Sep 6, 2024
1 parent 5907817 commit ea8eab2
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ type OCTIDataTableProps = Pick<DataTableProps, 'dataColumns'
| 'disableLineSelection'
| 'disableToolBar'
| 'disableSelectAll'
| 'disableRedirectOnRowClick'
| 'entityTypes'> & {
lineFragment: GraphQLTaggedNode
preloadedPaginationProps: UsePreloadedPaginationFragment<OperationType>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ type OCTIDataTableProps = Pick<DataTableProps, 'dataColumns'
| 'disableLineSelection'
| 'disableToolBar'
| 'disableSelectAll'
| 'disableRedirectOnRowClick'
| 'filtersComponent'
| 'variant'> & {
data: unknown,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ const DataTableComponent = ({
disableLineSelection,
disableToolBar,
disableSelectAll,
disableRedirectOnRowClick,
onLineClick,
}: DataTableProps) => {
const localStorageColumns = useDataTableLocalStorage<LocalStorageColumns>(`${storageKey}_columns`, {}, true)[0];
Expand All @@ -59,7 +60,7 @@ const DataTableComponent = ({
...(currentColumn?.size ? { size: currentColumn?.size } : {}),
});
}),
...(actions ? [] : [{ id: 'navigate', visible: true } as DataTableColumn]),
...(actions || disableRedirectOnRowClick ? [] : [{ id: 'navigate', visible: true } as DataTableColumn]),
];

const [columns, setColumns] = useState<DataTableColumns>(columnsInitialState);
Expand Down Expand Up @@ -120,6 +121,7 @@ const DataTableComponent = ({
disableNavigation,
disableToolBar,
disableSelectAll,
disableRedirectOnRowClick,
onLineClick,
} as DataTableContextProps}
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ const DataTableLine = ({
actions,
disableNavigation,
onLineClick,
disableRedirectOnRowClick,
variant,
} = useDataTableContext();
const data = useLineData(row);
Expand Down Expand Up @@ -139,12 +140,31 @@ const DataTableLine = ({
} = useDataTableToggle(storageKey);

const startsWithSelect = effectiveColumns.at(0)?.id === 'select';

const handleSelectLine = (event) => {
event.preventDefault();
event.stopPropagation();
if (event.shiftKey) {
onToggleShiftEntity(index, data, event);
} else {
onToggleEntity(data, event);
}
};

const handleRowClick = (event) => {
if (disableRedirectOnRowClick) {
handleSelectLine(event);
return undefined;
}
if (variant !== DataTableVariant.widget) internalOnClick();
return undefined;
};

return (
<div
key={row.id}
className={classes.row}
onMouseDown={variant === DataTableVariant.widget ? internalOnClick : undefined}
onClick={variant !== DataTableVariant.widget ? internalOnClick : undefined}
onClick={handleRowClick}
style={{ cursor: (navigable || Boolean(onLineClick)) ? 'pointer' : 'unset' }}
data-testid={getMainRepresentative(data)}
>
Expand All @@ -158,15 +178,7 @@ const DataTableLine = ({
>

<Checkbox
onClick={(event) => {
event.preventDefault();
event.stopPropagation();
if (event.shiftKey) {
onToggleShiftEntity(index, data, event);
} else {
onToggleEntity(data, event);
}
}}
onClick={handleSelectLine}
checked={
(selectAll
&& !((data.id || 'id') in (deSelectedElements || {})))
Expand All @@ -175,14 +187,15 @@ const DataTableLine = ({
/>
</div>
)}
{effectiveColumns.slice(startsWithSelect ? 1 : 0, actions ? undefined : -1).map((column) => (
{effectiveColumns.slice(startsWithSelect ? 1 : 0, actions || disableRedirectOnRowClick ? undefined : -1).map((column) => (
<DataTableCell
key={column.id}
cell={column}
data={data}
storageHelpers={storageHelpers}
/>
))}

<div
key={`navigate_${data.id}`}
className={classes.cellContainer}
Expand All @@ -199,11 +212,12 @@ const DataTableLine = ({
>
{actions && actions(data)}
{effectiveColumns.at(-1)?.id === 'navigate' && (
<IconButton onClick={() => navigate(link)}>
<KeyboardArrowRightOutlined />
</IconButton>
<IconButton onClick={() => navigate(link)}>
<KeyboardArrowRightOutlined />
</IconButton>
)}
</div>

</div>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ export interface DataTableContextProps {
disableNavigation: DataTableProps['disableNavigation']
disableToolBar: DataTableProps['disableToolBar']
disableSelectAll: DataTableProps['disableSelectAll']
disableRedirectOnRowClick: DataTableProps['disableRedirectOnRowClick']
onLineClick: DataTableProps['onLineClick']
}

Expand Down Expand Up @@ -126,6 +127,7 @@ export interface DataTableProps {
disableLineSelection?: boolean
disableToolBar?: boolean
disableSelectAll?: boolean
disableRedirectOnRowClick?: boolean
onLineClick?: (line: any) => void
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -819,6 +819,7 @@ const StixCoreRelationshipCreationFromEntity: FunctionComponent<StixCoreRelation
<DataTable
disableToolBar
disableSelectAll
disableRedirectOnRowClick
rootRef={tableRootRef ?? undefined}
variant={DataTableVariant.inline}
dataColumns={buildColumns(platformModuleHelpers)}
Expand Down

0 comments on commit ea8eab2

Please sign in to comment.