Skip to content

Commit

Permalink
fix link navigation
Browse files Browse the repository at this point in the history
  • Loading branch information
alisonelizabeth committed Jul 8, 2020
1 parent 97c4234 commit e11fda6
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { HttpSetup } from 'kibana/public';
import {
notificationServiceMock,
docLinksServiceMock,
applicationServiceMock,
} from '../../../../../../../../../../src/core/public/mocks';

import { ComponentTemplatesProvider } from '../../../component_templates_context';
Expand All @@ -28,6 +29,7 @@ const appDependencies = {
docLinks: docLinksServiceMock.createStartContract(),
toasts: notificationServiceMock.createSetupContract().toasts,
setBreadcrumbs: () => {},
navigateToApp: applicationServiceMock.createStartContract().navigateToApp,
};

export const setupEnvironment = () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export const TabSummary: React.FunctionComponent<Props> = ({
componentTemplateDetails,
showCallToAction,
}) => {
const { httpClient } = useComponentTemplatesContext();
const { navigateToApp } = useComponentTemplatesContext();

const { version, _meta, _kbnMeta } = componentTemplateDetails;

Expand Down Expand Up @@ -61,9 +61,11 @@ export const TabSummary: React.FunctionComponent<Props> = ({
values={{
createLink: (
<EuiLink
href={httpClient.basePath.prepend(
'/app/management/data/index_management/create_template'
)}
onClick={() =>
navigateToApp('management', {
path: '/data/index_management/create_template',
})
}
>
<FormattedMessage
id="xpack.idxMgmt.componentTemplateDetails.summaryTab.createTemplateLink"
Expand All @@ -73,9 +75,9 @@ export const TabSummary: React.FunctionComponent<Props> = ({
),
editLink: (
<EuiLink
href={httpClient.basePath.prepend(
'/app/management/data/index_management/templates'
)}
onClick={() =>
navigateToApp('management', { path: '/data/index_management/templates' })
}
>
<FormattedMessage
id="xpack.idxMgmt.componentTemplateDetails.summaryTab.updateTemplateLink"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/

import React, { createContext, useContext } from 'react';
import { HttpSetup, DocLinksStart, NotificationsSetup } from 'src/core/public';
import { HttpSetup, DocLinksStart, NotificationsSetup, CoreStart } from 'src/core/public';

import { ManagementAppMountParams } from 'src/plugins/management/public';
import { getApi, getUseRequest, getSendRequest, getDocumentation, getBreadcrumbs } from './lib';
Expand All @@ -19,6 +19,7 @@ interface Props {
docLinks: DocLinksStart;
toasts: NotificationsSetup['toasts'];
setBreadcrumbs: ManagementAppMountParams['setBreadcrumbs'];
navigateToApp: CoreStart['application']['navigateToApp'];
}

interface Context {
Expand All @@ -29,6 +30,7 @@ interface Context {
breadcrumbs: ReturnType<typeof getBreadcrumbs>;
trackMetric: (type: 'loaded' | 'click' | 'count', eventName: string) => void;
toasts: NotificationsSetup['toasts'];
navigateToApp: CoreStart['application']['navigateToApp'];
}

export const ComponentTemplatesProvider = ({
Expand All @@ -38,7 +40,15 @@ export const ComponentTemplatesProvider = ({
value: Props;
children: React.ReactNode;
}) => {
const { httpClient, apiBasePath, trackMetric, docLinks, toasts, setBreadcrumbs } = value;
const {
httpClient,
apiBasePath,
trackMetric,
docLinks,
toasts,
setBreadcrumbs,
navigateToApp,
} = value;

const useRequest = getUseRequest(httpClient);
const sendRequest = getSendRequest(httpClient);
Expand All @@ -49,7 +59,16 @@ export const ComponentTemplatesProvider = ({

return (
<ComponentTemplatesContext.Provider
value={{ api, documentation, trackMetric, toasts, httpClient, apiBasePath, breadcrumbs }}
value={{
api,
documentation,
trackMetric,
toasts,
httpClient,
apiBasePath,
breadcrumbs,
navigateToApp,
}}
>
{children}
</ComponentTemplatesContext.Provider>
Expand Down
3 changes: 2 additions & 1 deletion x-pack/plugins/index_management/public/application/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export const renderApp = (
return () => undefined;
}

const { i18n, docLinks, notifications } = core;
const { i18n, docLinks, notifications, application } = core;
const { Context: I18nContext } = i18n;
const { services, history, setBreadcrumbs } = dependencies;

Expand All @@ -36,6 +36,7 @@ export const renderApp = (
docLinks,
toasts: notifications.toasts,
setBreadcrumbs,
navigateToApp: application.navigateToApp,
};

render(
Expand Down

0 comments on commit e11fda6

Please sign in to comment.