mirror of
https://github.com/elastic/kibana.git
synced 2025-06-27 18:51:07 -04:00
## Summary This PR removes all imports of Route from react-router-dom and '@kbn/kibana-react-plugin/public' and instead imports Route from @kbn/shared-ux-router. ### Context Based on https://github.com/elastic/kibana/issues/132629#issue-1243243678 This PR executes steps 2 - 4: > 2. To make the transition easier, we want to re-export other react-router-dom exports alongside the modified' Route'. > 3. Solutions should start using that Route component in place of the one from react-router-dom. I.e. replace all occurrences of import { ... } from 'react-router-dom' with import { ... } from '@kbn/shared-ux-router'. > 4. All manual calls to useExecutionContext are not needed anymore and should be removed. ### Future PR Looks like this might be getting worked on in: https://github.com/elastic/kibana/pull/145863 (thanks!) > Introduce an ESlint rule that ensures that react-router-dom is not used directly in Kibana and that imports go through the new @kbn/shared-ux-router package. This is tangentially accomplished through https://github.com/elastic/kibana/pull/150340 but only addresses using Route through @kbn/kibana-react-plugin/public' ### Checklist Delete any items that are not applicable to this PR. - [x] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios --------- Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com> Co-authored-by: Tiago Costa <tiagoffcc@hotmail.com>
86 lines
2.7 KiB
TypeScript
86 lines
2.7 KiB
TypeScript
/*
|
|
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
|
* or more contributor license agreements. Licensed under the Elastic License
|
|
* 2.0 and the Server Side Public License, v 1; you may not use this file except
|
|
* in compliance with, at your election, the Elastic License 2.0 or the Server
|
|
* Side Public License, v 1.
|
|
*/
|
|
|
|
import React from 'react';
|
|
import ReactDOM from 'react-dom';
|
|
import { Router, Redirect } from 'react-router-dom';
|
|
import { Route } from '@kbn/shared-ux-router';
|
|
import { I18nProvider } from '@kbn/i18n-react';
|
|
import { AppMountParameters, CoreStart } from '@kbn/core/public';
|
|
import { RedirectAppLinks } from '@kbn/kibana-react-plugin/public';
|
|
import { AppPluginStartDependencies } from './types';
|
|
import { SearchExamplePage, ExampleLink } from './common/example_page';
|
|
import { SearchExamplesApp } from './search/app';
|
|
import { SearchSessionsExampleApp } from './search_sessions/app';
|
|
import { SqlSearchExampleApp } from './sql_search/app';
|
|
|
|
const LINKS: ExampleLink[] = [
|
|
{
|
|
path: '/search',
|
|
title: 'Search',
|
|
},
|
|
{
|
|
path: '/sql-search',
|
|
title: 'SQL Search',
|
|
},
|
|
{
|
|
path: '/search-sessions',
|
|
title: 'Search Sessions',
|
|
},
|
|
{
|
|
path: 'https://github.com/elastic/kibana/blob/main/src/plugins/data/README.mdx',
|
|
title: 'README (GitHub)',
|
|
},
|
|
];
|
|
|
|
export const renderApp = (
|
|
{ notifications, savedObjects, http, application }: CoreStart,
|
|
{ data, navigation, unifiedSearch }: AppPluginStartDependencies,
|
|
{ element, history }: AppMountParameters
|
|
) => {
|
|
ReactDOM.render(
|
|
<I18nProvider>
|
|
<RedirectAppLinks application={application}>
|
|
<SearchExamplePage exampleLinks={LINKS} basePath={http.basePath}>
|
|
<Router history={history}>
|
|
<Route path={LINKS[0].path}>
|
|
<SearchExamplesApp
|
|
notifications={notifications}
|
|
navigation={navigation}
|
|
data={data}
|
|
http={http}
|
|
unifiedSearch={unifiedSearch}
|
|
/>
|
|
</Route>
|
|
<Route path={LINKS[1].path}>
|
|
<SqlSearchExampleApp notifications={notifications} data={data} />
|
|
</Route>
|
|
<Route path={LINKS[2].path}>
|
|
<SearchSessionsExampleApp
|
|
navigation={navigation}
|
|
notifications={notifications}
|
|
data={data}
|
|
unifiedSearch={unifiedSearch}
|
|
/>
|
|
</Route>
|
|
|
|
<Route path="/" exact={true}>
|
|
<Redirect to={LINKS[0].path} />
|
|
</Route>
|
|
</Router>
|
|
</SearchExamplePage>
|
|
</RedirectAppLinks>
|
|
</I18nProvider>,
|
|
element
|
|
);
|
|
|
|
return () => {
|
|
data.search.session.clear();
|
|
ReactDOM.unmountComponentAtNode(element);
|
|
};
|
|
};
|