kibana/x-pack/plugins/triggers_actions_ui/public/application/app.tsx
Yuliia Naumenko b11f7830cb
[Alerting UI] Replaced AppContextProvider introduced by the plugin with KibanaContextProvider (#83248)
* Replaced AppContextProvider introduced by the plugin with KibanaContextProvider

* Removed unused files

* Fixed jest test

* Removed ActionsConnectorContext

* exposed addConnectorFlyout and editConnectorFlyouts as a plugin start result

* removed rest of unused connectors context

* fixed capabilities

* fixed jest tests

* fixed jest tests

* fixed jest tests

* fixed uptime

* fixed typecheck errors

* fixed typechecks

* fixed jest tests

* fixed type

* fixed uptime settings by pathing the correct plugin dependancy

* fixed security detection rules

* fixed due to commetns

* fixed jest tests

* fixed type check

* removed orig files

* fixed cases UI issues

* fixed due to comments

* fixed due to comments

* fixed kibana crash

* fixed es-lint
2020-11-24 00:07:47 -08:00

77 lines
2.8 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;
* you may not use this file except in compliance with the Elastic License.
*/
import React, { lazy } from 'react';
import { Switch, Route, Redirect, Router } from 'react-router-dom';
import { ChromeBreadcrumb, CoreStart, ScopedHistory } from 'kibana/public';
import { render, unmountComponentAtNode } from 'react-dom';
import { I18nProvider } from '@kbn/i18n/react';
import { KibanaFeature } from '../../../features/common';
import { Section, routeToAlertDetails } from './constants';
import { ActionTypeRegistryContract, AlertTypeRegistryContract } from '../types';
import { ChartsPluginStart } from '../../../../../src/plugins/charts/public';
import { DataPublicPluginStart } from '../../../../../src/plugins/data/public';
import { PluginStartContract as AlertingStart } from '../../../alerts/public';
import { suspendedComponentWithProps } from './lib/suspended_component_with_props';
import { Storage } from '../../../../../src/plugins/kibana_utils/public';
import { setSavedObjectsClient } from '../common/lib/data_apis';
import { KibanaContextProvider } from '../common/lib/kibana';
const TriggersActionsUIHome = lazy(async () => import('./home'));
const AlertDetailsRoute = lazy(
() => import('./sections/alert_details/components/alert_details_route')
);
export interface TriggersAndActionsUiServices extends CoreStart {
data: DataPublicPluginStart;
charts: ChartsPluginStart;
alerts?: AlertingStart;
storage?: Storage;
setBreadcrumbs: (crumbs: ChromeBreadcrumb[]) => void;
actionTypeRegistry: ActionTypeRegistryContract;
alertTypeRegistry: AlertTypeRegistryContract;
history: ScopedHistory;
kibanaFeatures: KibanaFeature[];
element: HTMLElement;
}
export const renderApp = (deps: TriggersAndActionsUiServices) => {
const { element, savedObjects } = deps;
const sections: Section[] = ['alerts', 'connectors'];
const sectionsRegex = sections.join('|');
setSavedObjectsClient(savedObjects.client);
render(
<I18nProvider>
<KibanaContextProvider services={{ ...deps }}>
<Router history={deps.history}>
<AppWithoutRouter sectionsRegex={sectionsRegex} />
</Router>
</KibanaContextProvider>
</I18nProvider>,
element
);
return () => {
unmountComponentAtNode(element);
};
};
export const AppWithoutRouter = ({ sectionsRegex }: { sectionsRegex: string }) => {
return (
<Switch>
<Route
path={`/:section(${sectionsRegex})`}
component={suspendedComponentWithProps(TriggersActionsUIHome, 'xl')}
/>
<Route
path={routeToAlertDetails}
component={suspendedComponentWithProps(AlertDetailsRoute, 'xl')}
/>
<Redirect from={'/'} to="alerts" />
</Switch>
);
};