Skip to content

Commit

Permalink
Prevent duplicate names from appearing in cell actions (#118648) (#11…
Browse files Browse the repository at this point in the history
…8803)

Co-authored-by: Kevin Qualters <56408403+kqualters-elastic@users.noreply.github.com>
  • Loading branch information
kibanamachine and kqualters-elastic authored Nov 16, 2021
1 parent 1511c02 commit 31cd5f1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 <></>;
Expand All @@ -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) ? (
<FormattedFieldValue
Component={Component}
Expand All @@ -102,7 +101,8 @@ const cellActionLink = [
<></>
);
}
: EmptyComponent,
: EmptyComponent;
},
];

export const cellActions: TGridCellAction[] = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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))
);

0 comments on commit 31cd5f1

Please sign in to comment.