Skip to content

Commit

Permalink
[Index Management] Fix ILM policy link trigger an SPA friendly naviga…
Browse files Browse the repository at this point in the history
…tion (elastic#199252)

## Summary

Close elastic#87876 

Use `core.application.navigateToUrl` navigate to given URL in a SPA
friendly.


https://github.com/user-attachments/assets/1918eb3d-fbec-46d9-8eae-b4a26ebd36a2
  • Loading branch information
viajes7 authored and CAWilson94 committed Dec 12, 2024
1 parent 71b7367 commit ac0ddcd
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -812,7 +812,7 @@ describe('Data Streams tab', () => {

const { actions, findDetailPanelIlmPolicyLink } = testBed;
await actions.clickNameAt(0);
expect(findDetailPanelIlmPolicyLink().prop('href')).toBe('/test/my_ilm_policy');
expect(findDetailPanelIlmPolicyLink().prop('data-href')).toBe('/test/my_ilm_policy');
});

test('with an ILM url locator and no ILM policy', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ export const DataStreamDetailPanel: React.FunctionComponent<Props> = ({
const { error, data: dataStream, isLoading } = useLoadDataStream(dataStreamName);

const ilmPolicyLink = useIlmLocator(ILM_PAGES_POLICY_EDIT, dataStream?.ilmPolicyName);
const { history, config } = useAppContext();
const { history, config, core } = useAppContext();
let indicesLink;

let content;
Expand Down Expand Up @@ -193,7 +193,11 @@ export const DataStreamDetailPanel: React.FunctionComponent<Props> = ({
>
<>
{ilmPolicyLink ? (
<EuiLink data-test-subj={'ilmPolicyLink'} href={ilmPolicyLink}>
<EuiLink
data-test-subj={'ilmPolicyLink'}
data-href={ilmPolicyLink}
onClick={() => core.application.navigateToUrl(ilmPolicyLink)}
>
<EuiTextColor color="subdued">{ilmPolicyName}</EuiTextColor>
</EuiLink>
) : (
Expand All @@ -204,7 +208,11 @@ export const DataStreamDetailPanel: React.FunctionComponent<Props> = ({
) : (
<>
{ilmPolicyLink ? (
<EuiLink data-test-subj={'ilmPolicyLink'} href={ilmPolicyLink}>
<EuiLink
data-test-subj={'ilmPolicyLink'}
data-href={ilmPolicyLink}
onClick={() => core.application.navigateToUrl(ilmPolicyLink)}
>
{ilmPolicyName}
</EuiLink>
) : (
Expand Down Expand Up @@ -429,7 +437,7 @@ export const DataStreamDetailPanel: React.FunctionComponent<Props> = ({
defaultMessage="To edit data retention for this data stream, you must edit its associated {link}."
values={{
link: (
<EuiLink href={ilmPolicyLink}>
<EuiLink onClick={() => core.application.navigateToUrl(ilmPolicyLink)}>
<FormattedMessage
id="xpack.idxMgmt.dataStreamsDetailsPanel.editDataRetentionModal.fullyManagedByILMButtonLabel"
defaultMessage="ILM policy"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,8 @@ const MixedIndicesCallout = ({
dataStreamName,
history,
}: MixedIndicesCalloutProps) => {
const { core } = useAppContext();

return (
<EuiCallOut
title={i18n.translate(
Expand All @@ -177,7 +179,10 @@ const MixedIndicesCallout = ({
defaultMessage="One or more indices are managed by an ILM policy ({viewAllIndicesLink}). Updating data retention for this data stream won't affect these indices. Instead you will have to update the {ilmPolicyLink} policy."
values={{
ilmPolicyLink: (
<EuiLink data-test-subj="viewIlmPolicyLink" href={ilmPolicyLink}>
<EuiLink
data-test-subj="viewIlmPolicyLink"
onClick={() => core.application.navigateToUrl(ilmPolicyLink)}
>
{ilmPolicyName}
</EuiLink>
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export const TabSummary: React.FunctionComponent<Props> = ({ templateDetails })

const numIndexPatterns = indexPatterns.length;

const { history } = useAppContext();
const { history, core } = useAppContext();
const ilmPolicyLink = useIlmLocator(ILM_PAGES_POLICY_EDIT, ilmPolicy?.name);

return (
Expand Down Expand Up @@ -171,7 +171,9 @@ export const TabSummary: React.FunctionComponent<Props> = ({ templateDetails })
</EuiDescriptionListTitle>
<EuiDescriptionListDescription>
{ilmPolicy?.name && ilmPolicyLink ? (
<EuiLink href={ilmPolicyLink}>{ilmPolicy!.name}</EuiLink>
<EuiLink onClick={() => core.application.navigateToUrl(ilmPolicyLink)}>
{ilmPolicy!.name}
</EuiLink>
) : (
ilmPolicy?.name || i18nTexts.none
)}
Expand Down

0 comments on commit ac0ddcd

Please sign in to comment.