Prevent duplicate names from appearing in cell actions (#118648) (#118803)

Co-authored-by: Kevin Qualters <56408403+kqualters-elastic@users.noreply.github.com>
This commit is contained in:
Kibana Machine 2021-11-16 18:22:55 -05:00 committed by GitHub
parent 1511c023ae
commit 31cd5f1d8d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 9 deletions

View file

@ -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) ? (
<FormattedFieldValue
Component={Component}
@ -102,7 +101,8 @@ const cellActionLink = [
<></>
);
}
: EmptyComponent,
: EmptyComponent;
},
];
export const cellActions: TGridCellAction[] = [

View file

@ -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))
);