Skip to content

Commit

Permalink
[Unified Observability] Remove core and plugins from PluginContext (#…
Browse files Browse the repository at this point in the history
…133466)

* replace core and plugins with specific dependencies

* remove core and plugins from tests

* clean unused plugins variable

Co-authored-by: Kibana Machine <[email protected]>
  • Loading branch information
estermv and kibanamachine authored Jun 8, 2022
1 parent e48db81 commit bb3d525
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 30 deletions.
2 changes: 0 additions & 2 deletions x-pack/plugins/observability/public/application/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,6 @@ export const renderApp = ({
value={{
appMountParameters,
config,
core,
plugins,
observabilityRuleTypeRegistry,
ObservabilityPageTemplate,
kibanaFeatures,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@

import { i18n } from '@kbn/i18n';
import React from 'react';
import { useKibana } from '@kbn/kibana-react-plugin/public';
import type { AppDataType } from '../../../shared/exploratory_view/types';
import { SectionContainer } from '..';
import { getDataHandler } from '../../../../data_handler';
import { FETCH_STATUS, useFetcher } from '../../../../hooks/use_fetcher';
import { useHasData } from '../../../../hooks/use_has_data';
import { useDatePickerContext } from '../../../../hooks/use_date_picker_context';
import { usePluginContext } from '../../../../hooks/use_plugin_context';
import CoreVitals from '../../../shared/core_web_vitals';
import { BucketSize } from '../../../../pages/overview';
import { getExploratoryViewEmbeddable } from '../../../shared/exploratory_view/embeddable';
Expand All @@ -22,20 +22,25 @@ import {
SERVICE_NAME,
TRANSACTION_DURATION,
} from '../../../shared/exploratory_view/configurations/constants/elasticsearch_fieldnames';
import { ObservabilityAppServices } from '../../../../application/types';

interface Props {
bucketSize: BucketSize;
}

export function UXSection({ bucketSize }: Props) {
const { forceUpdate, hasDataMap } = useHasData();
const { core, plugins } = usePluginContext();
const { services } = useKibana<ObservabilityAppServices>();
const { relativeStart, relativeEnd, absoluteStart, absoluteEnd, lastUpdated } =
useDatePickerContext();
const uxHasDataResponse = hasDataMap.ux;
const serviceName = uxHasDataResponse?.serviceName as string;

const ExploratoryViewEmbeddable = getExploratoryViewEmbeddable(core, plugins);
const ExploratoryViewEmbeddable = getExploratoryViewEmbeddable(
services.uiSettings,
services.dataViews,
services.lens
);

const seriesList: AllSeries = [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@

import React, { useCallback, useEffect, useState } from 'react';
import { EuiLoadingSpinner } from '@elastic/eui';
import { CoreStart } from '@kbn/core/public';
import { EuiThemeProvider } from '@kbn/kibana-react-plugin/common';
import type { IUiSettingsClient } from '@kbn/core/public';
import { DataViewsPublicPluginStart } from '@kbn/data-views-plugin/public';
import { LensPublicStart } from '@kbn/lens-plugin/public';
import type { ExploratoryEmbeddableProps, ExploratoryEmbeddableComponentProps } from './embeddable';
import { ObservabilityDataViews } from '../../../../utils/observability_data_views';
import { ObservabilityPublicPluginsStart } from '../../../../plugin';
import type { DataViewState } from '../hooks/use_app_data_view';
import type { AppDataType } from '../types';

Expand All @@ -26,24 +27,29 @@ function ExploratoryViewEmbeddable(props: ExploratoryEmbeddableComponentProps) {
}

export function getExploratoryViewEmbeddable(
core: CoreStart,
plugins: ObservabilityPublicPluginsStart
uiSettings?: IUiSettingsClient,
dataViews?: DataViewsPublicPluginStart,
lens?: LensPublicStart
) {
return (props: ExploratoryEmbeddableProps) => {
if (!dataViews || !lens) {
return null;
}

const [indexPatterns, setIndexPatterns] = useState<DataViewState>({} as DataViewState);
const [loading, setLoading] = useState(false);

const series = props.attributes && props.attributes[0];

const isDarkMode = core.uiSettings.get('theme:darkMode');
const isDarkMode = uiSettings?.get('theme:darkMode');

const loadIndexPattern = useCallback(
async ({ dataType }: { dataType: AppDataType }) => {
const dataTypesIndexPatterns = props.dataTypesIndexPatterns;

setLoading(true);
try {
const obsvIndexP = new ObservabilityDataViews(plugins.dataViews);
const obsvIndexP = new ObservabilityDataViews(dataViews);
const indPattern = await obsvIndexP.getDataView(
dataType,
dataTypesIndexPatterns?.[dataType]
Expand All @@ -70,7 +76,7 @@ export function getExploratoryViewEmbeddable(

return (
<EuiThemeProvider darkMode={isDarkMode}>
<ExploratoryViewEmbeddable {...props} indexPatterns={indexPatterns} lens={plugins.lens} />
<ExploratoryViewEmbeddable {...props} indexPatterns={indexPatterns} lens={lens} />
</EuiThemeProvider>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,16 @@
* 2.0.
*/

import { AppMountParameters, CoreStart } from '@kbn/core/public';
import { AppMountParameters } from '@kbn/core/public';
import { createContext } from 'react';
import { KibanaFeature } from '@kbn/features-plugin/common';
import { ObservabilityPublicPluginsStart } from '../plugin';
import { ConfigSchema } from '..';
import { ObservabilityRuleTypeRegistry } from '../rules/create_observability_rule_type_registry';
import type { LazyObservabilityPageTemplateProps } from '../components/shared/page_template/lazy_page_template';

export interface PluginContextValue {
appMountParameters: AppMountParameters;
config: ConfigSchema;
core: CoreStart;
plugins: ObservabilityPublicPluginsStart;
observabilityRuleTypeRegistry: ObservabilityRuleTypeRegistry;
ObservabilityPageTemplate: React.ComponentType<LazyObservabilityPageTemplateProps>;
kibanaFeatures: KibanaFeature[];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import { createKibanaReactContext } from '@kbn/kibana-react-plugin/public';
import { KibanaPageTemplate } from '@kbn/shared-ux-components';
import { HasDataContextProvider } from '../../context/has_data_context';
import { PluginContext } from '../../context/plugin_context';
import { ObservabilityPublicPluginsStart } from '../../plugin';
import { registerDataHandler, unregisterDataHandler } from '../../data_handler';
import { OverviewPage } from '.';
import { alertsFetchData } from './mock/alerts.mock';
Expand Down Expand Up @@ -90,8 +89,6 @@ const withCore = makeDecorator({
rules: { enabled: true },
},
},
core: {} as CoreStart,
plugins: {} as ObservabilityPublicPluginsStart,
observabilityRuleTypeRegistry: createObservabilityRuleTypeRegistryMock(),
ObservabilityPageTemplate: KibanaPageTemplate,
kibanaFeatures: [],
Expand Down
6 changes: 5 additions & 1 deletion x-pack/plugins/observability/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,11 @@ export class Plugin
},
createExploratoryViewUrl,
getAppDataView: getAppDataView(pluginsStart.dataViews),
ExploratoryViewEmbeddable: getExploratoryViewEmbeddable(coreStart, pluginsStart),
ExploratoryViewEmbeddable: getExploratoryViewEmbeddable(
coreStart.uiSettings,
pluginsStart.dataViews,
pluginsStart.lens
),
useRulesLink: createUseRulesLink(config.unsafe.rules.enabled),
};
}
Expand Down
10 changes: 0 additions & 10 deletions x-pack/plugins/observability/public/utils/test_helper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,13 @@ import { KibanaPageTemplate } from '@kbn/shared-ux-components';
import translations from '@kbn/translations-plugin/translations/ja-JP.json';
import { EuiThemeProvider } from '@kbn/kibana-react-plugin/common';
import { dataPluginMock } from '@kbn/data-plugin/public/mocks';
import { ObservabilityPublicPluginsStart } from '../plugin';
import { PluginContext } from '../context/plugin_context';
import { createObservabilityRuleTypeRegistryMock } from '../rules/observability_rule_type_registry_mock';

const appMountParameters = { setHeaderActionMenu: () => {} } as unknown as AppMountParameters;

export const core = coreMock.createStart();
export const data = dataPluginMock.createStartContract();
const dataViewsMock = () => {
return {};
};

const plugins = {
dataViews: dataViewsMock,
} as unknown as ObservabilityPublicPluginsStart;

const config = {
unsafe: {
Expand All @@ -50,8 +42,6 @@ export const render = (component: React.ReactNode) => {
value={{
appMountParameters,
config,
core,
plugins,
observabilityRuleTypeRegistry,
ObservabilityPageTemplate: KibanaPageTemplate,
kibanaFeatures: [],
Expand Down

0 comments on commit bb3d525

Please sign in to comment.