Skip to content

Commit

Permalink
[URL UPDATE] Change '/app/enterprise_search/app_search' to '/app/app_…
Browse files Browse the repository at this point in the history
…search'

- This needs to be done because App Search and Workplace search *have* to be registered as separate plugins to have 2 distinct nav links
- Currently Kibana doesn't support nested app names (see: elastic#59190) but potentially will in the future

- To support this change, we need to update applications/index.tsx to NOT handle '/app/enterprise_search' level routing, but instead accept an async imported app component (e.g. AppSearch, WorkplaceSearch).
- AppSearch should now treat its router as root '/' instead of '/app_search'
- (Addl) Per Josh Dover's recommendation, switch to `<Router history={params.history}>` from `<BrowserRouter basename={params.appBasePath}>` since they're deprecating appBasePath

- Update breadcrumbs helper since '/app/enterprise_search' will not link anywhere meaningful for the foreseeable future, so the Enterprise Search root should not go anywhere
  • Loading branch information
cee-chen committed May 7, 2020
1 parent 0cca6c6 commit b7b3779
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ export const AppSearch: React.FC<> = () => {

return (
<>
<Route exact path="/app_search">
{!enterpriseSearchUrl ? <Redirect to="/app_search/setup_guide" /> : <EngineOverview />}
<Route exact path="/">
{!enterpriseSearchUrl ? <Redirect to="/setup_guide" /> : <EngineOverview />}
</Route>
<Route path="/app_search/setup_guide">
<Route path="/setup_guide">
<SetupGuide />
</Route>
</>
Expand Down
24 changes: 11 additions & 13 deletions x-pack/plugins/enterprise_search/public/applications/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,14 @@

import React from 'react';
import ReactDOM from 'react-dom';
import { BrowserRouter, Route, Redirect } from 'react-router-dom';
import { Router, Route, Redirect } from 'react-router-dom';

import { CoreStart, AppMountParams, HttpHandler } from 'src/core/public';
import { ClientConfigType, PluginsSetup } from '../plugin';
import { TSetBreadcrumbs } from './shared/kibana_breadcrumbs';
import { ILicense } from '../../../../licensing/public';
import { LicenseProvider } from './shared/licensing';

import { AppSearch } from './app_search';

export interface IKibanaContext {
enterpriseSearchUrl?: string;
http(): HttpHandler;
Expand All @@ -25,7 +23,14 @@ export interface IKibanaContext {

export const KibanaContext = React.createContext();

/**
* This file serves as a reusable wrapper to share Kibana-level context and other helpers
* between various Enterprise Search plugins (e.g. AppSearch, WorkplaceSearch, ES landing page)
* which should be imported and passed in as the first param in plugin.ts.
*/

export const renderApp = (
App: React.Element,
core: CoreStart,
params: AppMountParams,
config: ClientConfigType,
Expand All @@ -41,16 +46,9 @@ export const renderApp = (
}}
>
<LicenseProvider>
<BrowserRouter basename={params.appBasePath}>
<Route exact path="/">
{/* This will eventually contain an Enterprise Search landing page,
and we'll also actually have a /workplace_search route */}
<Redirect to="/app_search" />
</Route>
<Route path="/app_search">
<AppSearch />
</Route>
</BrowserRouter>
<Router history={params.history}>
<App />
</Router>
</LicenseProvider>
</KibanaContext.Provider>,
params.element
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,20 @@ interface IGenerateBreadcrumbProps {
history: History;
}

export const generateBreadcrumb = ({ text, path, history }: IGenerateBreadcrumbProps) => ({
text,
href: history.createHref({ pathname: path }),
onClick: event => {
if (letBrowserHandleEvent(event)) return;
event.preventDefault();
history.push(path);
},
});
export const generateBreadcrumb = ({ text, path, history }: IGenerateBreadcrumbProps) => {
const breadcrumb = { text };

if (path) {
breadcrumb.href = history.createHref({ pathname: path });
breadcrumb.onClick = event => {
if (letBrowserHandleEvent(event)) return;
event.preventDefault();
history.push(path);
};
}

return breadcrumb;
};

/**
* Product-specific breadcrumb helpers
Expand All @@ -39,12 +44,9 @@ type TBreadcrumbs = EuiBreadcrumb[] | [];
export const enterpriseSearchBreadcrumbs = (history: History) => (
breadcrumbs: TBreadcrumbs = []
) => [
generateBreadcrumb({ text: 'Enterprise Search', path: '/', history }),
generateBreadcrumb({ text: 'Enterprise Search' }),
...breadcrumbs.map(({ text, path }) => generateBreadcrumb({ text, path, history })),
];

export const appSearchBreadcrumbs = (history: History) => (breadcrumbs: TBreadcrumbs = []) =>
enterpriseSearchBreadcrumbs(history)([
{ text: 'App Search', path: '/app_search' },
...breadcrumbs,
]);
enterpriseSearchBreadcrumbs(history)([{ text: 'App Search', path: '/' }, ...breadcrumbs]);
13 changes: 8 additions & 5 deletions x-pack/plugins/enterprise_search/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,29 +40,32 @@ export class EnterpriseSearchPlugin implements Plugin {
const config = this.config;

core.application.register({
id: 'enterprise_search',
title: 'App Search', // TODO: This will eventually be 'Enterprise Search' once there's more than just App Search in here
id: 'app_search',
title: 'App Search',
// appRoute: '/app/enterprise_search/app_search', // TODO: Switch to this once https://github.com/elastic/kibana/issues/59190 is in
category: DEFAULT_APP_CATEGORIES.enterpriseSearch,
mount: async (params: AppMountParameters) => {
const [coreStart] = await core.getStartServices();

const { renderApp } = await import('./applications');
const { AppSearch } = await import('./applications/app_search');

return renderApp(coreStart, params, config, plugins);
return renderApp(AppSearch, coreStart, params, config, plugins);
},
});
// TODO: Workplace Search will need to register its own plugin.

plugins.home.featureCatalogue.register({
id: 'app_search',
title: 'App Search',
icon: AppSearchLogo,
description:
'Leverage dashboards, analytics, and APIs for advanced application search made simple.',
path: '/app/enterprise_search/app_search',
path: '/app/app_search', // TODO: Switch to '/app/enterprise_search/app_search' once https://github.com/elastic/kibana/issues/59190 is in
category: FeatureCatalogueCategory.DATA,
showOnHomePage: true,
});
// TODO: Workplace Search will likely also register its own feature catalogue section/card.
// TODO: Workplace Search will need to register its own feature catalogue section/card.
}

public start(core: CoreStart) {}
Expand Down

0 comments on commit b7b3779

Please sign in to comment.