Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Index Management] Fix broken app links #71007

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ export class PolicyTable extends Component {
icon: 'list',
onClick: () => {
this.props.navigateToApp('management', {
path: `/data/index_management${getIndexListUri(`ilm.policy:${policy.name}`)}`,
path: `/data/index_management${getIndexListUri(`ilm.policy:${policy.name}`, true)}`,
});
},
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,11 @@ export const services = {
services.uiMetricService.setup({ reportUiStats() {} } as any);
setExtensionsService(services.extensionsService);
setUiMetricService(services.uiMetricService);
const appDependencies = { services, core: { getUrlForApp: () => {} }, plugins: {} } as any;
const appDependencies = {
services,
core: { getUrlForApp: () => {} },
plugins: {},
} as any;

export const setupEnvironment = () => {
// Mock initialization of services
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,6 @@ export const IndexManagementHome: React.FunctionComponent<RouteComponentProps<Ma
component={DataStreamList}
/>
<Route exact path={`/${Section.Indices}`} component={IndexList} />
<Route exact path={`/${Section.Indices}/filter/:filter?`} component={IndexList} />
<Route
exact
path={[`/${Section.IndexTemplates}`, `/${Section.IndexTemplates}/:templateName?`]}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ const HEADERS = {

export class IndexTable extends Component {
static getDerivedStateFromProps(props, state) {
// Deselct any indices which no longer exist, e.g. they've been deleted.
// Deselect any indices which no longer exist, e.g. they've been deleted.
const { selectedIndicesMap } = state;
const indexNames = props.indices.map((index) => index.name);
const selectedIndexNames = Object.keys(selectedIndicesMap);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ import {
EuiFlexItem,
EuiCodeBlock,
} from '@elastic/eui';
import { useAppContext } from '../../../../../app_context';
import { TemplateDeserialized } from '../../../../../../../common';
import { getILMPolicyPath } from '../../../../../services/navigation';
import { getILMPolicyPath } from '../../../../../services/routing';

interface Props {
templateDetails: TemplateDeserialized;
Expand Down Expand Up @@ -51,6 +52,10 @@ export const TabSummary: React.FunctionComponent<Props> = ({ templateDetails })

const numIndexPatterns = indexPatterns.length;

const {
core: { getUrlForApp },
} = useAppContext();

return (
<EuiFlexGroup data-test-subj="summaryTab">
<EuiFlexItem>
Expand Down Expand Up @@ -153,7 +158,13 @@ export const TabSummary: React.FunctionComponent<Props> = ({ templateDetails })
</EuiDescriptionListTitle>
<EuiDescriptionListDescription>
{ilmPolicy && ilmPolicy.name ? (
<EuiLink href={getILMPolicyPath(ilmPolicy.name)}>{ilmPolicy.name}</EuiLink>
<EuiLink
Copy link
Contributor

@cjcenizal cjcenizal Jul 8, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a note that we need an href here too, so users can copy the url or open the link in a new tab. If you grep for reactRouterNavigate you can see how we use this utility in various plugins to provide both an href and an onClick.

Copy link
Contributor Author

@alisonelizabeth alisonelizabeth Jul 8, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cjcenizal thanks for pointing this out! From what I can see, reactRouterNavigate doesn't work when navigating to other apps. I came across #67697, which suggests using history.parentHistory. This would work, however, it is private in ScopedHistory. I will change it back to a href for now, but there will be a full page refresh.

href={getUrlForApp('management', {
path: getILMPolicyPath(ilmPolicy.name),
})}
>
{ilmPolicy.name}
</EuiLink>
) : (
i18nTexts.none
)}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,28 @@ export const getTemplateCloneLink = (name: string, isLegacy?: boolean) => {
return encodeURI(url);
};

export const getILMPolicyPath = (policyName: string) => {
return encodeURI(
`/data/index_lifecycle_management/policies/edit/${encodeURIComponent(policyName)}`
);
};

export const getIndexListUri = (filter?: string, includeHiddenIndices?: boolean) => {
const hiddenIndicesParam =
typeof includeHiddenIndices !== 'undefined' ? includeHiddenIndices : false;
if (filter) {
// React router tries to decode url params but it can't because the browser partially
// decodes them. So we have to encode both the URL and the filter to get it all to
// work correctly for filters with URL unsafe characters in them.
return encodeURI(
`/indices?includeHiddenIndices=${hiddenIndicesParam}&filter=${encodeURIComponent(filter)}`
);
}

// If no filter, URI is already safe so no need to encode.
return '/indices';
};

export const decodePathFromReactRouter = (pathname: string): string => {
let decodedPath;
try {
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/index_management/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ export const plugin = () => {

export { IndexManagementPluginSetup };

export { getIndexListUri } from './application/services/navigation';
export { getIndexListUri } from './application/services/routing';