Skip to content

Commit

Permalink
[Index Management] Fix broken app links (#71007)
Browse files Browse the repository at this point in the history
  • Loading branch information
alisonelizabeth authored Jul 9, 2020
1 parent cfbdf1f commit d37b053
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 28 deletions.
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
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';

0 comments on commit d37b053

Please sign in to comment.