From 62e8cde7fb973e721ea638193793c906d6f0b122 Mon Sep 17 00:00:00 2001 From: Kevin Qualters <56408403+kqualters-elastic@users.noreply.github.com> Date: Tue, 16 Nov 2021 16:39:04 -0500 Subject: [PATCH] Prevent duplicate names from appearing in cell actions (#118648) --- .../lib/cell_actions/default_cell_actions.tsx | 14 +++++++------- .../public/common/lib/cell_actions/helpers.ts | 6 ++++-- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/x-pack/plugins/security_solution/public/common/lib/cell_actions/default_cell_actions.tsx b/x-pack/plugins/security_solution/public/common/lib/cell_actions/default_cell_actions.tsx index 012b84e06ed825..3526724a54b414 100644 --- a/x-pack/plugins/security_solution/public/common/lib/cell_actions/default_cell_actions.tsx +++ b/x-pack/plugins/security_solution/public/common/lib/cell_actions/default_cell_actions.tsx @@ -60,14 +60,15 @@ const cellActionLink = [ header?: ColumnHeaderOptions; timelineId: string; pageSize: number; - }) => - getLink(header?.id, header?.type, header?.linkField) + }) => { + return getLink(header?.id, header?.type, header?.linkField) ? ({ rowIndex, columnId, Component, closePopover }: EuiDataGridColumnCellActionProps) => { const pageRowIndex = getPageRowIndex(rowIndex, pageSize); const ecs = pageRowIndex < ecsData.length ? ecsData[pageRowIndex] : null; - const linkValues = header && getOr([], header.linkField ?? '', ecs); + const link = getLink(columnId, header?.type, header?.linkField); + const linkField = header?.linkField ? header?.linkField : link?.linkField; + const linkValues = header && getOr([], linkField ?? '', ecs); const eventId = header && get('_id' ?? '', ecs); - if (pageRowIndex >= data.length) { // data grid expects each cell action always return an element, it crashes if returns null return <>; @@ -78,9 +79,7 @@ const cellActionLink = [ fieldName: columnId, }); - const link = getLink(columnId, header?.type, header?.linkField); const value = parseValue(head(values)); - return link && eventId && values && !isEmpty(value) ? ( ); } - : EmptyComponent, + : EmptyComponent; + }, ]; export const cellActions: TGridCellAction[] = [ diff --git a/x-pack/plugins/security_solution/public/common/lib/cell_actions/helpers.ts b/x-pack/plugins/security_solution/public/common/lib/cell_actions/helpers.ts index 1c40d8df48bfe2..2db645106fc5cb 100644 --- a/x-pack/plugins/security_solution/public/common/lib/cell_actions/helpers.ts +++ b/x-pack/plugins/security_solution/public/common/lib/cell_actions/helpers.ts @@ -35,6 +35,7 @@ export const COLUMNS_WITH_LINKS = [ { columnId: SIGNAL_RULE_NAME_FIELD_NAME, label: i18n.VIEW_RULE_DETAILS, + linkField: 'signal.rule.id', }, ...PORT_NAMES.map((p) => ({ columnId: p, @@ -59,7 +60,8 @@ export const COLUMNS_WITH_LINKS = [ ]; export const getLink = (cId?: string, fieldType?: string, linkField?: string) => - cId && COLUMNS_WITH_LINKS.find( - (c) => c.columnId === cId || (c.fieldType && fieldType === c.fieldType && linkField != null) + (c) => + (cId && c.columnId === cId) || + (c.fieldType && fieldType === c.fieldType && (linkField != null || c.linkField !== undefined)) );