Skip to content

Commit

Permalink
use react router link. its an actual link, and its easier to test w/ …
Browse files Browse the repository at this point in the history
…react router

also, use `href` instead of a button
  • Loading branch information
oatkiller committed Feb 20, 2020
1 parent 90f3f10 commit c0bb87b
Showing 1 changed file with 4 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import { memo, useState, useMemo, useCallback } from 'react';
import React from 'react';
import {
EuiLink,
EuiDataGrid,
EuiDataGridColumn,
EuiPage,
Expand All @@ -20,7 +19,7 @@ import {
EuiBadge,
} from '@elastic/eui';
import { i18n } from '@kbn/i18n';
import { useHistory } from 'react-router-dom';
import { useHistory, Link } from 'react-router-dom';
import * as selectors from '../../store/alerts/selectors';
import { useAlertListSelector } from './hooks/use_alerts_selector';

Expand Down Expand Up @@ -112,15 +111,6 @@ export const AlertIndex = memo(() => {
[]
);

const handleAlertClick = useMemo(() => {
return (event: React.MouseEvent<HTMLElement>) => {
const alertId: string | undefined = event.currentTarget.dataset.alertId;
if (alertId !== undefined) {
history.push(urlWithSelectedAlert(alertId));
}
};
}, [history, urlWithSelectedAlert]);

const handleFlyoutClose = useCallback(() => {
history.push(urlWithoutSelectedAlert);
}, [history, urlWithoutSelectedAlert]);
Expand All @@ -135,18 +125,14 @@ export const AlertIndex = memo(() => {

if (columnId === 'alert_type') {
return (
<EuiLink
data-test-subj="alert-type-cell-link"
data-alert-id={'TODO'}
onClick={handleAlertClick}
>
<Link data-test-subj="alert-type-cell-link" to={urlWithSelectedAlert('TODO')}>
{i18n.translate(
'xpack.endpoint.application.endpoint.alerts.alertType.maliciousFileDescription',
{
defaultMessage: 'Malicious File',
}
)}
</EuiLink>
</Link>
);
} else if (columnId === 'event_type') {
return row.event.action;
Expand Down Expand Up @@ -179,7 +165,7 @@ export const AlertIndex = memo(() => {
}
return null;
};
}, [alertListData, formatter, handleAlertClick, pageSize, total]);
}, [alertListData, formatter, pageSize, total, urlWithSelectedAlert]);

const pagination = useMemo(() => {
return {
Expand Down

0 comments on commit c0bb87b

Please sign in to comment.