mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 09:19:04 -04:00
Pass on and use global search/filters to embeddable.
This commit is contained in:
parent
6bb2d66cfc
commit
2c24dbd116
2 changed files with 75 additions and 27 deletions
|
@ -0,0 +1,59 @@
|
||||||
|
/*
|
||||||
|
* 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, { useMemo, type FC } from 'react';
|
||||||
|
|
||||||
|
import datemath from '@elastic/datemath';
|
||||||
|
|
||||||
|
import type { TimeRange } from '@kbn/es-query';
|
||||||
|
|
||||||
|
import { createMergedEsQuery } from '../../application/utils/search_utils';
|
||||||
|
import { useAiopsAppContext } from '../../hooks/use_aiops_app_context';
|
||||||
|
import { useFilterQueryUpdates } from '../../hooks/use_filters_query';
|
||||||
|
import { useSearch } from '../../hooks/use_search';
|
||||||
|
import { useDataSource } from '../../hooks/use_data_source';
|
||||||
|
import { getDefaultLogRateAnalysisAppState } from '../../application/url_state/log_rate_analysis';
|
||||||
|
|
||||||
|
import { LogRateAnalysisDocumentCountChartData } from './log_rate_analysis_content/log_rate_analysis_document_count_chart_data';
|
||||||
|
import { LogRateAnalysisContent } from './log_rate_analysis_content/log_rate_analysis_content';
|
||||||
|
|
||||||
|
export interface LogRateAnalysisForEmbeddableProps {
|
||||||
|
timeRange: TimeRange;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const LogRateAnalysisForEmbeddable: FC<LogRateAnalysisForEmbeddableProps> = ({
|
||||||
|
timeRange,
|
||||||
|
}) => {
|
||||||
|
const { uiSettings } = useAiopsAppContext();
|
||||||
|
const { dataView } = useDataSource();
|
||||||
|
const { filters, query } = useFilterQueryUpdates();
|
||||||
|
const appState = getDefaultLogRateAnalysisAppState({
|
||||||
|
searchQuery: createMergedEsQuery(query, filters, dataView, uiSettings),
|
||||||
|
filters,
|
||||||
|
});
|
||||||
|
const { searchQuery } = useSearch({ dataView, savedSearch: null }, appState, true);
|
||||||
|
|
||||||
|
const timeRangeParsed = useMemo(() => {
|
||||||
|
if (timeRange) {
|
||||||
|
const min = datemath.parse(timeRange.from);
|
||||||
|
const max = datemath.parse(timeRange.to);
|
||||||
|
if (min && max) {
|
||||||
|
return { min, max };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, [timeRange]);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<LogRateAnalysisDocumentCountChartData
|
||||||
|
timeRange={timeRangeParsed}
|
||||||
|
esSearchQuery={searchQuery}
|
||||||
|
/>
|
||||||
|
<LogRateAnalysisContent esSearchQuery={searchQuery} />
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
};
|
|
@ -12,8 +12,6 @@ import type { Observable } from 'rxjs';
|
||||||
import { BehaviorSubject, combineLatest, distinctUntilChanged, map } from 'rxjs';
|
import { BehaviorSubject, combineLatest, distinctUntilChanged, map } from 'rxjs';
|
||||||
import { createBrowserHistory } from 'history';
|
import { createBrowserHistory } from 'history';
|
||||||
|
|
||||||
import datemath from '@elastic/datemath';
|
|
||||||
|
|
||||||
import { UrlStateProvider } from '@kbn/ml-url-state';
|
import { UrlStateProvider } from '@kbn/ml-url-state';
|
||||||
import { Router } from '@kbn/shared-ux-router';
|
import { Router } from '@kbn/shared-ux-router';
|
||||||
import { AIOPS_EMBEDDABLE_ORIGIN } from '@kbn/aiops-common/constants';
|
import { AIOPS_EMBEDDABLE_ORIGIN } from '@kbn/aiops-common/constants';
|
||||||
|
@ -27,10 +25,10 @@ import type { SignificantItem } from '@kbn/ml-agg-utils';
|
||||||
import { AiopsAppContext, type AiopsAppContextValue } from '../hooks/use_aiops_app_context';
|
import { AiopsAppContext, type AiopsAppContextValue } from '../hooks/use_aiops_app_context';
|
||||||
import { DataSourceContextProvider } from '../hooks/use_data_source';
|
import { DataSourceContextProvider } from '../hooks/use_data_source';
|
||||||
import { ReloadContextProvider } from '../hooks/use_reload';
|
import { ReloadContextProvider } from '../hooks/use_reload';
|
||||||
|
import { FilterQueryContextProvider } from '../hooks/use_filters_query';
|
||||||
import type { AiopsPluginStartDeps } from '../types';
|
import type { AiopsPluginStartDeps } from '../types';
|
||||||
|
|
||||||
import { LogRateAnalysisDocumentCountChartData } from '../components/log_rate_analysis/log_rate_analysis_content/log_rate_analysis_document_count_chart_data';
|
import { LogRateAnalysisForEmbeddable } from '../components/log_rate_analysis/log_rate_analysis_for_embeddable';
|
||||||
import { LogRateAnalysisContent } from '../components/log_rate_analysis/log_rate_analysis_content/log_rate_analysis_content';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Only used to initialize internally
|
* Only used to initialize internally
|
||||||
|
@ -124,16 +122,6 @@ const LogRateAnalysisEmbeddableWrapperWithDeps: FC<LogRateAnalysisPropsWithDeps>
|
||||||
|
|
||||||
const history = createBrowserHistory();
|
const history = createBrowserHistory();
|
||||||
|
|
||||||
const timeRangeParsed = useMemo(() => {
|
|
||||||
if (timeRange) {
|
|
||||||
const min = datemath.parse(timeRange.from);
|
|
||||||
const max = datemath.parse(timeRange.to);
|
|
||||||
if (min && max) {
|
|
||||||
return { min, max };
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}, [timeRange]);
|
|
||||||
|
|
||||||
// We use the following pattern to track changes of dataViewId, and if there's
|
// We use the following pattern to track changes of dataViewId, and if there's
|
||||||
// a change, we unmount and remount the complete inner component. This makes
|
// a change, we unmount and remount the complete inner component. This makes
|
||||||
// sure the component is reinitialized correctly when the options of the
|
// sure the component is reinitialized correctly when the options of the
|
||||||
|
@ -165,19 +153,20 @@ const LogRateAnalysisEmbeddableWrapperWithDeps: FC<LogRateAnalysisPropsWithDeps>
|
||||||
<Router history={history}>
|
<Router history={history}>
|
||||||
<ReloadContextProvider reload$={resultObservable$}>
|
<ReloadContextProvider reload$={resultObservable$}>
|
||||||
<AiopsAppContext.Provider value={aiopsAppContextValue}>
|
<AiopsAppContext.Provider value={aiopsAppContextValue}>
|
||||||
<UrlStateProvider>
|
<DatePickerContextProvider {...datePickerDeps}>
|
||||||
<DataSourceContextProvider
|
<UrlStateProvider>
|
||||||
dataViews={pluginStart.data.dataViews}
|
<DataSourceContextProvider
|
||||||
dataViewId={dataViewId}
|
dataViews={pluginStart.data.dataViews}
|
||||||
>
|
dataViewId={dataViewId}
|
||||||
<LogRateAnalysisReduxProvider>
|
>
|
||||||
<DatePickerContextProvider {...datePickerDeps}>
|
<FilterQueryContextProvider timeRange={timeRange}>
|
||||||
<LogRateAnalysisDocumentCountChartData timeRange={timeRangeParsed} />
|
<LogRateAnalysisReduxProvider>
|
||||||
<LogRateAnalysisContent />
|
<LogRateAnalysisForEmbeddable timeRange={timeRange} />
|
||||||
</DatePickerContextProvider>
|
</LogRateAnalysisReduxProvider>
|
||||||
</LogRateAnalysisReduxProvider>
|
</FilterQueryContextProvider>
|
||||||
</DataSourceContextProvider>
|
</DataSourceContextProvider>
|
||||||
</UrlStateProvider>
|
</UrlStateProvider>
|
||||||
|
</DatePickerContextProvider>
|
||||||
</AiopsAppContext.Provider>
|
</AiopsAppContext.Provider>
|
||||||
</ReloadContextProvider>
|
</ReloadContextProvider>
|
||||||
</Router>
|
</Router>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue