This repository has been archived by the owner on Mar 31, 2024. It is now read-only.
forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Logs UI] <LogStream /> as a kibana embeddable (elastic#88618)
Co-authored-by: Kibana Machine <[email protected]>
- Loading branch information
1 parent
fb19aab
commit 53637d0
Showing
10 changed files
with
169 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
"features", | ||
"usageCollection", | ||
"spaces", | ||
|
||
"embeddable", | ||
"data", | ||
"dataEnhanced", | ||
"visTypeTimeseries", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
export * from './log_stream'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
91 changes: 91 additions & 0 deletions
91
x-pack/plugins/infra/public/components/log_stream/log_stream_embeddable.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
/* | ||
* 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 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 { datemathToEpochMillis } from '../../utils/datemath'; | ||
import { LazyLogStreamWrapper } from './lazy_log_stream_wrapper'; | ||
|
||
export const LOG_STREAM_EMBEDDABLE = 'LOG_STREAM_EMBEDDABLE'; | ||
|
||
export interface LogStreamEmbeddableInput extends EmbeddableInput { | ||
timeRange: TimeRange; | ||
query: Query; | ||
} | ||
|
||
export class LogStreamEmbeddable extends Embeddable<LogStreamEmbeddableInput> { | ||
public readonly type = LOG_STREAM_EMBEDDABLE; | ||
private node?: HTMLElement; | ||
|
||
constructor( | ||
private services: CoreStart, | ||
initialInput: LogStreamEmbeddableInput, | ||
parent?: IContainer | ||
) { | ||
super(initialInput, {}, parent); | ||
} | ||
|
||
public render(node: HTMLElement) { | ||
if (this.node) { | ||
ReactDOM.unmountComponentAtNode(this.node); | ||
} | ||
this.node = node; | ||
|
||
this.renderComponent(); | ||
} | ||
|
||
public reload() { | ||
this.renderComponent(); | ||
} | ||
|
||
public destroy() { | ||
super.destroy(); | ||
if (this.node) { | ||
ReactDOM.unmountComponentAtNode(this.node); | ||
} | ||
} | ||
|
||
private renderComponent() { | ||
if (!this.node) { | ||
return; | ||
} | ||
|
||
const startTimestamp = datemathToEpochMillis(this.input.timeRange.from); | ||
const endTimestamp = datemathToEpochMillis(this.input.timeRange.to); | ||
|
||
if (!startTimestamp || !endTimestamp) { | ||
return; | ||
} | ||
|
||
ReactDOM.render( | ||
<I18nProvider> | ||
<EuiThemeProvider> | ||
<KibanaContextProvider services={this.services}> | ||
<div style={{ width: '100%' }}> | ||
<LazyLogStreamWrapper | ||
startTimestamp={startTimestamp} | ||
endTimestamp={endTimestamp} | ||
height="100%" | ||
query={this.input.query} | ||
/> | ||
</div> | ||
</KibanaContextProvider> | ||
</EuiThemeProvider> | ||
</I18nProvider>, | ||
this.node | ||
); | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
x-pack/plugins/infra/public/components/log_stream/log_stream_embeddable_factory.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
* 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 { CoreStart } from 'kibana/public'; | ||
import { | ||
EmbeddableFactoryDefinition, | ||
IContainer, | ||
} from '../../../../../../src/plugins/embeddable/public'; | ||
import { | ||
LogStreamEmbeddable, | ||
LOG_STREAM_EMBEDDABLE, | ||
LogStreamEmbeddableInput, | ||
} from './log_stream_embeddable'; | ||
|
||
export class LogStreamEmbeddableFactoryDefinition | ||
implements EmbeddableFactoryDefinition<LogStreamEmbeddableInput> { | ||
public readonly type = LOG_STREAM_EMBEDDABLE; | ||
|
||
constructor(private getCoreServices: () => Promise<CoreStart>) {} | ||
|
||
public async isEditable() { | ||
const { application } = await this.getCoreServices(); | ||
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); | ||
} | ||
|
||
public getDisplayName() { | ||
return 'Log stream'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters