Skip to content

Commit

Permalink
[Logs UI] Wrap log stream embeddable with proper providers (#91725)
Browse files Browse the repository at this point in the history
This declares the correct dependencies for the `LogStreamEmbeddable` and replaces parts of the custom provider hierarchy used therein with the common Logs UI `CoreProviders`.
  • Loading branch information
weltenwort committed Feb 18, 2021
1 parent 5f951bd commit 28fa873
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 30 deletions.
6 changes: 3 additions & 3 deletions x-pack/plugins/infra/public/apps/common_providers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,18 @@

import { AppMountParameters, CoreStart } from 'kibana/public';
import React, { useMemo } from 'react';
import { EuiThemeProvider } from '../../../../../src/plugins/kibana_react/common';
import {
useUiSetting$,
KibanaContextProvider,
useUiSetting$,
} from '../../../../../src/plugins/kibana_react/public';
import { EuiThemeProvider } from '../../../../../src/plugins/kibana_react/common';
import { Storage } from '../../../../../src/plugins/kibana_utils/public';
import { TriggersAndActionsUIPublicPluginStart } from '../../../triggers_actions_ui/public';
import { createKibanaContextForPlugin } from '../hooks/use_kibana';
import { InfraClientStartDeps } from '../types';
import { HeaderActionMenuProvider } from '../utils/header_action_menu_provider';
import { NavigationWarningPromptProvider } from '../utils/navigation_warning_prompt';
import { TriggersActionsProvider } from '../utils/triggers_actions_context';
import { Storage } from '../../../../../src/plugins/kibana_utils/public';

export const CommonInfraProviders: React.FC<{
appName: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,18 @@
* 2.0.
*/

import { CoreStart } from 'kibana/public';
import React from 'react';
import ReactDOM from 'react-dom';
import { CoreStart } from 'kibana/public';

import { I18nProvider } from '@kbn/i18n/react';
import { KibanaContextProvider } from '../../../../../../src/plugins/kibana_react/public';
import { EuiThemeProvider } from '../../../../../../src/plugins/kibana_react/common';
import { Query, TimeRange } from '../../../../../../src/plugins/data/public';
import {
Embeddable,
EmbeddableInput,
IContainer,
} from '../../../../../../src/plugins/embeddable/public';
import { EuiThemeProvider } from '../../../../../../src/plugins/kibana_react/common';
import { CoreProviders } from '../../apps/common_providers';
import { InfraClientStartDeps } from '../../types';
import { datemathToEpochMillis } from '../../utils/datemath';
import { LazyLogStreamWrapper } from './lazy_log_stream_wrapper';

Expand All @@ -33,7 +32,8 @@ export class LogStreamEmbeddable extends Embeddable<LogStreamEmbeddableInput> {
private node?: HTMLElement;

constructor(
private services: CoreStart,
private core: CoreStart,
private pluginDeps: InfraClientStartDeps,
initialInput: LogStreamEmbeddableInput,
parent?: IContainer
) {
Expand Down Expand Up @@ -73,20 +73,18 @@ export class LogStreamEmbeddable extends Embeddable<LogStreamEmbeddableInput> {
}

ReactDOM.render(
<I18nProvider>
<CoreProviders core={this.core} plugins={this.pluginDeps}>
<EuiThemeProvider>
<KibanaContextProvider services={this.services}>
<div style={{ width: '100%' }}>
<LazyLogStreamWrapper
startTimestamp={startTimestamp}
endTimestamp={endTimestamp}
height="100%"
query={this.input.query}
/>
</div>
</KibanaContextProvider>
<div style={{ width: '100%' }}>
<LazyLogStreamWrapper
startTimestamp={startTimestamp}
endTimestamp={endTimestamp}
height="100%"
query={this.input.query}
/>
</div>
</EuiThemeProvider>
</I18nProvider>,
</CoreProviders>,
this.node
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,32 @@
* 2.0.
*/

import { CoreStart } from 'kibana/public';
import { StartServicesAccessor } from 'kibana/public';
import {
EmbeddableFactoryDefinition,
IContainer,
} from '../../../../../../src/plugins/embeddable/public';
import { InfraClientStartDeps } from '../../types';
import {
LogStreamEmbeddable,
LOG_STREAM_EMBEDDABLE,
LogStreamEmbeddableInput,
LOG_STREAM_EMBEDDABLE,
} from './log_stream_embeddable';

export class LogStreamEmbeddableFactoryDefinition
implements EmbeddableFactoryDefinition<LogStreamEmbeddableInput> {
public readonly type = LOG_STREAM_EMBEDDABLE;

constructor(private getCoreServices: () => Promise<CoreStart>) {}
constructor(private getStartServices: StartServicesAccessor<InfraClientStartDeps>) {}

public async isEditable() {
const { application } = await this.getCoreServices();
const [{ application }] = await this.getStartServices();
return application.capabilities.logs.save as boolean;
}

public async create(initialInput: LogStreamEmbeddableInput, parent?: IContainer) {
const services = await this.getCoreServices();
return new LogStreamEmbeddable(services, initialInput, parent);
const [core, plugins] = await this.getStartServices();
return new LogStreamEmbeddable(core, plugins, initialInput, parent);
}

public getDisplayName() {
Expand Down
4 changes: 1 addition & 3 deletions x-pack/plugins/infra/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,9 @@ export class Plugin implements InfraClientPluginClass {
});
}

const getCoreServices = async () => (await core.getStartServices())[0];

pluginsSetup.embeddable.registerEmbeddableFactory(
LOG_STREAM_EMBEDDABLE,
new LogStreamEmbeddableFactoryDefinition(getCoreServices)
new LogStreamEmbeddableFactoryDefinition(core.getStartServices)
);

core.application.register({
Expand Down

0 comments on commit 28fa873

Please sign in to comment.