Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion x-pack/plugins/observability/kibana.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@
"embeddable",
"kibanaReact",
"kibanaUtils",
"lens"
"lens",
"usageCollection"
],
"extraPublicDirs": [
"common"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,12 @@ describe('renderApp', () => {
observabilityRuleTypeRegistry: createObservabilityRuleTypeRegistryMock(),
ObservabilityPageTemplate: KibanaPageTemplate,
kibanaFeatures: [],
usageCollection: {
components: {
ApplicationUsageTrackingProvider: (props) => null,
},
reportUiCounter: jest.fn(),
},
});
unmount();
}).not.toThrowError();
Expand Down
61 changes: 35 additions & 26 deletions x-pack/plugins/observability/public/application/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
RedirectAppLinks,
} from '@kbn/kibana-react-plugin/public';
import { Storage } from '@kbn/kibana-utils-plugin/public';
import { UsageCollectionSetup } from '@kbn/usage-collection-plugin/public';
import { ConfigSchema } from '..';
import type { LazyObservabilityPageTemplateProps } from '../components/shared/page_template/lazy_page_template';
import { DatePickerContextProvider } from '../context/date_picker_context';
Expand Down Expand Up @@ -54,6 +55,7 @@ export const renderApp = ({
observabilityRuleTypeRegistry,
ObservabilityPageTemplate,
kibanaFeatures,
usageCollection,
}: {
config: ConfigSchema;
core: CoreStart;
Expand All @@ -62,6 +64,7 @@ export const renderApp = ({
appMountParameters: AppMountParameters;
ObservabilityPageTemplate: React.ComponentType<LazyObservabilityPageTemplateProps>;
kibanaFeatures: KibanaFeature[];
usageCollection: UsageCollectionSetup;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: this is declared as an optional dependency

Suggested change
usageCollection: UsageCollectionSetup;
usageCollection?: UsageCollectionSetup;

}) => {
const { element, history, theme$ } = appMountParameters;
const i18nCore = core.i18n;
Expand All @@ -77,34 +80,40 @@ export const renderApp = ({
// ensure all divs are .kbnAppWrappers
element.classList.add(APP_WRAPPER_CLASS);

const ApplicationUsageTrackingProvider =
usageCollection?.components.ApplicationUsageTrackingProvider ?? React.Fragment;
ReactDOM.render(
<KibanaThemeProvider theme$={theme$}>
<KibanaContextProvider services={{ ...core, ...plugins, storage: new Storage(localStorage) }}>
<PluginContext.Provider
value={{
appMountParameters,
config,
observabilityRuleTypeRegistry,
ObservabilityPageTemplate,
kibanaFeatures,
}}
<ApplicationUsageTrackingProvider>
<KibanaThemeProvider theme$={theme$}>
<KibanaContextProvider
services={{ ...core, ...plugins, storage: new Storage(localStorage) }}
>
<Router history={history}>
<EuiThemeProvider darkMode={isDarkMode}>
<i18nCore.Context>
<RedirectAppLinks application={core.application} className={APP_WRAPPER_CLASS}>
<DatePickerContextProvider>
<HasDataContextProvider>
<App />
</HasDataContextProvider>
</DatePickerContextProvider>
</RedirectAppLinks>
</i18nCore.Context>
</EuiThemeProvider>
</Router>
</PluginContext.Provider>
</KibanaContextProvider>
</KibanaThemeProvider>,
<PluginContext.Provider
value={{
appMountParameters,
config,
observabilityRuleTypeRegistry,
ObservabilityPageTemplate,
kibanaFeatures,
}}
>
<Router history={history}>
<EuiThemeProvider darkMode={isDarkMode}>
<i18nCore.Context>
<RedirectAppLinks application={core.application} className={APP_WRAPPER_CLASS}>
<DatePickerContextProvider>
<HasDataContextProvider>
<App />
</HasDataContextProvider>
</DatePickerContextProvider>
</RedirectAppLinks>
</i18nCore.Context>
</EuiThemeProvider>
</Router>
</PluginContext.Provider>
</KibanaContextProvider>
</KibanaThemeProvider>
</ApplicationUsageTrackingProvider>,
element
);
return () => {
Expand Down
6 changes: 6 additions & 0 deletions x-pack/plugins/observability/public/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,9 @@

export { paths } from './paths';
export { translations } from './translations';

export enum AlertingPages {
alerts = 'alerts',
cases = 'cases',
rules = 'rules',
}
4 changes: 4 additions & 0 deletions x-pack/plugins/observability/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import {
} from '@kbn/triggers-actions-ui-plugin/public';
import { KibanaFeature } from '@kbn/features-plugin/common';

import { UsageCollectionSetup } from '@kbn/usage-collection-plugin/public';
import { ConfigSchema } from '.';
import { observabilityAppId, observabilityFeatureId, casesPath } from '../common';
import { createLazyObservabilityPageTemplate } from './components/shared';
Expand All @@ -52,9 +53,11 @@ export interface ObservabilityPublicPluginsSetup {
data: DataPublicPluginSetup;
triggersActionsUi: TriggersAndActionsUIPublicPluginSetup;
home?: HomePublicPluginSetup;
usageCollection: UsageCollectionSetup;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as my previous comment: kibana.json declares this dependency optional. We should account for it in TS.

}

export interface ObservabilityPublicPluginsStart {
usageCollection: UsageCollectionSetup;
cases: CasesUiStart;
embeddable: EmbeddableStart;
home?: HomePublicPluginStart;
Expand Down Expand Up @@ -169,6 +172,7 @@ export class Plugin
observabilityRuleTypeRegistry,
ObservabilityPageTemplate: navigation.PageTemplate,
kibanaFeatures,
usageCollection: pluginsSetup.usageCollection,
});
};

Expand Down
20 changes: 17 additions & 3 deletions x-pack/plugins/observability/public/routes/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import * as t from 'io-ts';
import React from 'react';
import { TrackApplicationView } from '@kbn/usage-collection-plugin/public';
import { casesPath } from '../../common';
import { CasesPage } from '../pages/cases';
import { AlertsPage } from '../pages/alerts/containers/alerts_page';
Expand All @@ -16,6 +17,7 @@ import { OverviewPage } from '../pages/overview';
import { jsonRt } from './json_rt';
import { ObservabilityExploratoryView } from '../components/shared/exploratory_view/obsv_exploratory_view';
import { RulesPage } from '../pages/rules';
import { AlertingPages } from '../config';

export type RouteParams<T extends keyof typeof routes> = DecodeParams<typeof routes[T]['params']>;

Expand Down Expand Up @@ -60,14 +62,22 @@ export const routes = {
},
[casesPath]: {
handler: () => {
return <CasesPage />;
return (
<TrackApplicationView viewId={AlertingPages.cases}>
<CasesPage />
</TrackApplicationView>
);
},
params: {},
exact: false,
},
'/alerts': {
handler: () => {
return <AlertsPage />;
return (
<TrackApplicationView viewId={AlertingPages.alerts}>
<AlertsPage />
</TrackApplicationView>
);
},
params: {
// Technically gets a '_a' param by using Kibana URL state sync helpers
Expand All @@ -90,7 +100,11 @@ export const routes = {
},
'/alerts/rules': {
handler: () => {
return <RulesPage />;
return (
<TrackApplicationView viewId={AlertingPages.rules}>
<RulesPage />
</TrackApplicationView>
);
},
params: {},
exact: true,
Expand Down