[Security Solution][Detections] Follow up cleanup after two bugfixes (#87516)

## Summary

This is a follow-up PR addressing some of the comments in:

- https://github.com/elastic/kibana/pull/86908
- https://github.com/elastic/kibana/pull/87004
This commit is contained in:
Georgii Gorbachev 2021-01-06 19:37:36 +01:00 committed by GitHub
parent 48694bbbad
commit e50ad384f7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 31 additions and 14 deletions

View file

@ -122,16 +122,16 @@ const getAvailableFields = (
selectedFields: IFieldType[],
fieldTypeFilter: string[]
): IFieldType[] => {
const map = new Map<string, IFieldType>();
const fieldsByName = new Map<string, IFieldType>();
existingFields.forEach((f) => map.set(f.name, f));
selectedFields.forEach((f) => map.set(f.name, f));
existingFields.forEach((f) => fieldsByName.set(f.name, f));
selectedFields.forEach((f) => fieldsByName.set(f.name, f));
const array = Array.from(map.values());
const uniqueFields = Array.from(fieldsByName.values());
if (fieldTypeFilter.length > 0) {
return array.filter(({ type }) => fieldTypeFilter.includes(type));
return uniqueFields.filter(({ type }) => fieldTypeFilter.includes(type));
}
return array;
return uniqueFields;
};

View file

@ -22,7 +22,11 @@ const DocLink: FC<DocLinkProps> = ({ guidePath = 'security', docPath, linkText }
const url = `${ELASTIC_WEBSITE_URL}guide/en/${guidePath}/${DOC_LINK_VERSION}/${docPath}`;
const ariaLabel = `${linkText} - ${COMMON_ARIA_LABEL_ENDING}`;
return <ExternalLink url={url} text={linkText} ariaLabel={ariaLabel} />;
return (
<ExternalLink url={url} ariaLabel={ariaLabel}>
{linkText}
</ExternalLink>
);
};
/**

View file

@ -5,21 +5,34 @@
*/
import React, { FC } from 'react';
import { EuiLink } from '@elastic/eui';
import { EuiLink, EuiToolTip } from '@elastic/eui';
interface ExternalLinkProps {
url: string;
text: string;
children?: React.ReactNode;
ariaLabel?: string;
}
/**
* A simplistic text link for opening external urls in a new browser tab.
* A link for opening external urls in a new browser tab.
*/
export const ExternalLink: FC<ExternalLinkProps> = ({ url, text, ariaLabel }) => {
export const ExternalLink: FC<ExternalLinkProps> = ({ url, children, ariaLabel }) => {
if (!children) {
return null;
}
return (
<EuiLink href={url} aria-label={ariaLabel} external target="_blank" rel="noopener">
{text}
</EuiLink>
<EuiToolTip content={url} position="top" data-test-subj="externalLinkTooltip">
<EuiLink
href={url}
aria-label={ariaLabel}
external
target="_blank"
rel="noopener"
data-test-subj="externalLink"
>
{children}
</EuiLink>
</EuiToolTip>
);
};