Skip to content

Commit cb5d51a

Browse files
committed
fix redirection useComputeLink
1 parent 60b614c commit cb5d51a

File tree

3 files changed

+25
-9
lines changed

3 files changed

+25
-9
lines changed

opencti-platform/opencti-front/src/components/dataGrid/components/DataTableLine.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -121,11 +121,11 @@ const DataTableLine = ({
121121

122122
// Memoize link to avoid recomputations
123123
let link = useMemo(() => useComputeLink(data), [data]);
124-
if (redirectionMode && redirectionMode !== 'overview') {
124+
if (redirectionMode && redirectionMode !== 'overview' && link !== undefined) {
125125
link = `${link}/${redirectionMode}`;
126126
}
127127

128-
const navigable = !disableNavigation && !onLineClick && !selectOnLineClick;
128+
const navigable = !disableNavigation && !onLineClick && !selectOnLineClick && !!link;
129129
const clickable = !!(navigable || selectOnLineClick || onLineClick);
130130

131131
const handleSelectLine = (event: React.MouseEvent) => {
@@ -137,7 +137,8 @@ const DataTableLine = ({
137137
};
138138

139139
const handleNavigate = (event: React.MouseEvent) => {
140-
if (!navigable) return;
140+
if (!navigable || !link) return;
141+
141142
if (event.ctrlKey) {
142143
window.open(link, '_blank');
143144
} else {
@@ -241,7 +242,7 @@ const DataTableLine = ({
241242
>
242243
{actions && actions(data)}
243244
{endsWithNavigate && (
244-
<IconButton onClick={() => navigate(link)}>
245+
<IconButton onClick={() => (link ? navigate(link) : undefined)}>
245246
<KeyboardArrowRightOutlined />
246247
</IconButton>
247248
)}

opencti-platform/opencti-front/src/components/dataGrid/dataTableTypes.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export interface DataTableContextProps {
4949
useDataTable: ReturnType<DataTableProps['useDataTable']>
5050
useDataCellHelpers: DataTableProps['useDataCellHelpers']
5151
useDataTableToggle: ReturnType<DataTableProps['useDataTableToggle']>
52-
useComputeLink: (entity: any) => string
52+
useComputeLink: (entity: any) => string | undefined
5353
useDataTableColumnsLocalStorage: ReturnType<DataTableProps['useDataTableColumnsLocalStorage']>
5454
useDataTablePaginationLocalStorage: ReturnType<DataTableProps['useDataTablePaginationLocalStorage']>
5555
onAddFilter: DataTableProps['onAddFilter']
@@ -111,7 +111,7 @@ export interface DataTableProps {
111111
initialValue: LocalStorage,
112112
ignoreUri?: boolean,
113113
) => PaginationLocalStorage<T>
114-
useComputeLink?: (entity: any) => string
114+
useComputeLink?: (entity: any) => string | undefined
115115
useDataTableToggle: (key: string) => {
116116
selectedElements: Record<string, any>
117117
deSelectedElements: Record<string, any>

opencti-platform/opencti-front/src/private/components/profile/Notifications.tsx

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import { hexToRGB } from '../../../utils/Colors';
2929
import useApiMutation from '../../../utils/hooks/useApiMutation';
3030
import Transition from '../../../components/Transition';
3131
import { deleteNode } from '../../../utils/store';
32+
import { isNotEmptyField } from '../../../utils/utils';
3233

3334
export const LOCAL_STORAGE_KEY = 'notifiers';
3435

@@ -156,7 +157,11 @@ const Notifications: FunctionComponent = () => {
156157
platformModuleHelpers: { isRuntimeFieldEnable },
157158
} = useAuth();
158159

159-
const { viewStorage, helpers, paginationOptions } = usePaginationLocalStorage<NotificationsLinesPaginationQuery$variables>(
160+
const {
161+
viewStorage,
162+
helpers,
163+
paginationOptions,
164+
} = usePaginationLocalStorage<NotificationsLinesPaginationQuery$variables>(
160165
LOCAL_STORAGE_KEY,
161166
initialValues,
162167
);
@@ -424,13 +429,23 @@ const Notifications: FunctionComponent = () => {
424429
availableEntityTypes={['Notification']}
425430
actions={renderActions}
426431
markAsReadEnabled={true}
432+
useComputeLink={({ notification_content, notification_type }: NotificationsLine_node$data) => {
433+
const events = notification_content.map((n) => n.events).flat();
434+
const firstEvent = events.at(0);
435+
const isDigest = notification_type === 'digest';
436+
const firstOperation = isDigest ? 'multiple' : (firstEvent?.operation ?? 'none');
437+
const isLinkAvailable = events.length === 1 && isNotEmptyField(firstEvent?.instance_id) && firstOperation !== 'delete';
438+
if (!isLinkAvailable) return undefined;
439+
return `/dashboard/id/${firstEvent.instance_id}`;
440+
}}
441+
427442
/>
428443
)}
429444
{notificationToDelete && (
430445
<Dialog
431-
PaperProps={{ elevation: 1 }}
446+
slotProps={{ paper: { elevation: 1 } }}
432447
open={!!notificationToDelete}
433-
TransitionComponent={Transition}
448+
slots={{ transition: Transition }}
434449
onClose={handleCloseDelete}
435450
>
436451
<DialogContent>

0 commit comments

Comments
 (0)