Skip to content

Commit

Permalink
replace core and plugins with specific dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
estermv committed Jun 3, 2022
1 parent c1025d8 commit e2d6adf
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 15 deletions.
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
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 @@ -301,7 +301,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

0 comments on commit e2d6adf

Please sign in to comment.