-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[embeddable rebuild] log stream react embeddable (#184247)
PR migrates log stream embeddable from the legacy class based system. ### test instructions 1. Run kibana on a system with o11y data and log streams 2. Create a new dashboard, click "Add panel" => "Log stream" 3. Verify panel behavior has not changed with legacy embeddable 4. Click panel context menu and select "Settings" 5. Set custom title, description and time range. Verify behavior has not changed with legacy embeddable 6. Import dashboard with log stream panel. Verify behavior has not changed with legacy embeddable --------- Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
- Loading branch information
1 parent
257ef7f
commit 1a0b93a
Showing
8 changed files
with
203 additions
and
197 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
9 changes: 9 additions & 0 deletions
9
x-pack/plugins/observability_solution/infra/public/components/log_stream/constants.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,9 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
export const LOG_STREAM_EMBEDDABLE = 'LOG_STREAM_EMBEDDABLE'; | ||
export const ADD_LOG_STREAM_ACTION_ID = 'ADD_SEARCH_ACTION_ID'; |
133 changes: 0 additions & 133 deletions
133
...ugins/observability_solution/infra/public/components/log_stream/log_stream_embeddable.tsx
This file was deleted.
Oops, something went wrong.
57 changes: 0 additions & 57 deletions
57
...bservability_solution/infra/public/components/log_stream/log_stream_embeddable_factory.ts
This file was deleted.
Oops, something went wrong.
123 changes: 123 additions & 0 deletions
123
...observability_solution/infra/public/components/log_stream/log_stream_react_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,123 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import React, { FC, PropsWithChildren, useEffect, useMemo, useState } from 'react'; | ||
import { ReactEmbeddableFactory } from '@kbn/embeddable-plugin/public'; | ||
import { | ||
initializeTimeRange, | ||
initializeTitles, | ||
useFetchContext, | ||
} from '@kbn/presentation-publishing'; | ||
import { LogStream } from '@kbn/logs-shared-plugin/public'; | ||
import { AppMountParameters, CoreStart } from '@kbn/core/public'; | ||
import { EuiThemeProvider } from '@kbn/kibana-react-plugin/common'; | ||
import { Query } from '@kbn/es-query'; | ||
import { KibanaRenderContextProvider } from '@kbn/react-kibana-context-render'; | ||
import type { LogStreamApi, LogStreamSerializedState, Services } from './types'; | ||
import { datemathToEpochMillis } from '../../utils/datemath'; | ||
import { LOG_STREAM_EMBEDDABLE } from './constants'; | ||
import { useKibanaContextForPluginProvider } from '../../hooks/use_kibana'; | ||
import { InfraClientStartDeps, InfraClientStartExports } from '../../types'; | ||
|
||
export function getLogStreamEmbeddableFactory(services: Services) { | ||
const factory: ReactEmbeddableFactory<LogStreamSerializedState, LogStreamApi> = { | ||
type: LOG_STREAM_EMBEDDABLE, | ||
deserializeState: (state) => state.rawState, | ||
buildEmbeddable: async (state, buildApi) => { | ||
const timeRangeContext = initializeTimeRange(state); | ||
const { titlesApi, titleComparators, serializeTitles } = initializeTitles(state); | ||
|
||
const api = buildApi( | ||
{ | ||
...timeRangeContext.api, | ||
...titlesApi, | ||
serializeState: () => { | ||
return { | ||
rawState: { | ||
...timeRangeContext.serialize(), | ||
...serializeTitles(), | ||
}, | ||
}; | ||
}, | ||
}, | ||
{ | ||
...timeRangeContext.comparators, | ||
...titleComparators, | ||
} | ||
); | ||
|
||
return { | ||
api, | ||
Component: () => { | ||
const { filters, query, timeRange } = useFetchContext(api); | ||
const { startTimestamp, endTimestamp } = useMemo(() => { | ||
return { | ||
startTimestamp: timeRange ? datemathToEpochMillis(timeRange.from) : undefined, | ||
endTimestamp: timeRange ? datemathToEpochMillis(timeRange.to, 'up') : undefined, | ||
}; | ||
}, [timeRange]); | ||
|
||
const [darkMode, setDarkMode] = useState(false); | ||
useEffect(() => { | ||
const subscription = services.coreStart.theme.theme$.subscribe((theme) => { | ||
setDarkMode(theme.darkMode); | ||
}); | ||
return () => subscription.unsubscribe(); | ||
}, []); | ||
|
||
return !startTimestamp || !endTimestamp ? null : ( | ||
<LogStreamEmbeddableProviders | ||
core={services.coreStart} | ||
plugins={services.pluginDeps} | ||
pluginStart={services.pluginStart} | ||
theme$={services.coreStart.theme.theme$} | ||
> | ||
<EuiThemeProvider darkMode={darkMode}> | ||
<div style={{ width: '100%' }}> | ||
<LogStream | ||
logView={{ type: 'log-view-reference', logViewId: 'default' }} | ||
startTimestamp={startTimestamp} | ||
endTimestamp={endTimestamp} | ||
height="100%" | ||
query={query as Query | undefined} | ||
filters={filters} | ||
/> | ||
</div> | ||
</EuiThemeProvider> | ||
</LogStreamEmbeddableProviders> | ||
); | ||
}, | ||
}; | ||
}, | ||
}; | ||
return factory; | ||
} | ||
|
||
export interface LogStreamEmbeddableProvidersProps { | ||
core: CoreStart; | ||
pluginStart: InfraClientStartExports; | ||
plugins: InfraClientStartDeps; | ||
theme$: AppMountParameters['theme$']; | ||
} | ||
|
||
export const LogStreamEmbeddableProviders: FC< | ||
PropsWithChildren<LogStreamEmbeddableProvidersProps> | ||
> = ({ children, core, pluginStart, plugins }) => { | ||
const KibanaContextProviderForPlugin = useKibanaContextForPluginProvider( | ||
core, | ||
plugins, | ||
pluginStart | ||
); | ||
|
||
return ( | ||
<KibanaRenderContextProvider {...core}> | ||
<KibanaContextProviderForPlugin services={{ ...core, ...plugins, ...pluginStart }}> | ||
{children} | ||
</KibanaContextProviderForPlugin> | ||
</KibanaRenderContextProvider> | ||
); | ||
}; |
21 changes: 21 additions & 0 deletions
21
x-pack/plugins/observability_solution/infra/public/components/log_stream/types.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,21 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { CoreStart } from '@kbn/core/public'; | ||
import { DefaultEmbeddableApi } from '@kbn/embeddable-plugin/public'; | ||
import { SerializedTimeRange, SerializedTitles } from '@kbn/presentation-publishing'; | ||
import { InfraClientStartDeps, InfraClientStartExports } from '../../types'; | ||
|
||
export type LogStreamSerializedState = SerializedTitles & SerializedTimeRange; | ||
|
||
export type LogStreamApi = DefaultEmbeddableApi<LogStreamSerializedState>; | ||
|
||
export interface Services { | ||
coreStart: CoreStart; | ||
pluginDeps: InfraClientStartDeps; | ||
pluginStart: InfraClientStartExports; | ||
} |
Oops, something went wrong.