Skip to content

Commit

Permalink
Tweak naming / add useCallback for handler
Browse files Browse the repository at this point in the history
  • Loading branch information
Kerry350 committed Feb 10, 2021
1 parent 07856b4 commit 2c2f599
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,8 @@ export const AnalyzeCategoryDatasetInMlAction: React.FunctionComponent<{
},
});

const mlLinkOnClick = useCallback(() => {
const handleClick = useCallback(() => {
if (!viewAnomalyInMachineLearningLink) return;

application.navigateToUrl(viewAnomalyInMachineLearningLink);
}, [application, viewAnomalyInMachineLearningLink]);

Expand All @@ -53,7 +52,7 @@ export const AnalyzeCategoryDatasetInMlAction: React.FunctionComponent<{
iconType="machineLearningApp"
data-test-subj="analyzeCategoryDatasetInMlButton"
href={viewAnomalyInMachineLearningLink}
onClick={mlLinkOnClick}
onClick={handleClick}
/>
</EuiToolTip>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export const TopCategoriesSection: React.FunctionComponent<{
changeSortOptions,
}) => {
const {
services: { ml, http, application },
services: { ml, http },
} = useKibanaContextForPlugin();

const analyzeInMlLink = useMlHref(ml, http.basePath.get(), {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,11 @@ export const LogEntryExampleMessage: React.FunctionComponent<Props> = ({
},
});

const handleMlLinkClick = useCallback(() => {
if (!viewAnomalyInMachineLearningLink) return;
application.navigateToUrl(viewAnomalyInMachineLearningLink);
}, [viewAnomalyInMachineLearningLink, application]);

const menuItems = useMemo(() => {
if (!viewInStreamLinkProps.onClick || !viewAnomalyInMachineLearningLink) {
return undefined;
Expand All @@ -153,7 +158,7 @@ export const LogEntryExampleMessage: React.FunctionComponent<Props> = ({
},
{
label: VIEW_ANOMALY_IN_ML_LABEL,
onClick: () => application.navigateToUrl(viewAnomalyInMachineLearningLink),
onClick: handleMlLinkClick,
href: viewAnomalyInMachineLearningLink,
},
];
Expand All @@ -162,7 +167,7 @@ export const LogEntryExampleMessage: React.FunctionComponent<Props> = ({
openLogEntryFlyout,
viewInStreamLinkProps,
viewAnomalyInMachineLearningLink,
application,
handleMlLinkClick,
]);

return (
Expand Down

0 comments on commit 2c2f599

Please sign in to comment.