mirror of
https://github.com/elastic/kibana.git
synced 2025-04-19 23:39:42 -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 { createBrowserHistory } from 'history';
|
||||
|
||||
import datemath from '@elastic/datemath';
|
||||
|
||||
import { UrlStateProvider } from '@kbn/ml-url-state';
|
||||
import { Router } from '@kbn/shared-ux-router';
|
||||
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 { DataSourceContextProvider } from '../hooks/use_data_source';
|
||||
import { ReloadContextProvider } from '../hooks/use_reload';
|
||||
import { FilterQueryContextProvider } from '../hooks/use_filters_query';
|
||||
import type { AiopsPluginStartDeps } from '../types';
|
||||
|
||||
import { LogRateAnalysisDocumentCountChartData } from '../components/log_rate_analysis/log_rate_analysis_content/log_rate_analysis_document_count_chart_data';
|
||||
import { LogRateAnalysisContent } from '../components/log_rate_analysis/log_rate_analysis_content/log_rate_analysis_content';
|
||||
import { LogRateAnalysisForEmbeddable } from '../components/log_rate_analysis/log_rate_analysis_for_embeddable';
|
||||
|
||||
/**
|
||||
* Only used to initialize internally
|
||||
|
@ -124,16 +122,6 @@ const LogRateAnalysisEmbeddableWrapperWithDeps: FC<LogRateAnalysisPropsWithDeps>
|
|||
|
||||
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
|
||||
// a change, we unmount and remount the complete inner component. This makes
|
||||
// sure the component is reinitialized correctly when the options of the
|
||||
|
@ -165,19 +153,20 @@ const LogRateAnalysisEmbeddableWrapperWithDeps: FC<LogRateAnalysisPropsWithDeps>
|
|||
<Router history={history}>
|
||||
<ReloadContextProvider reload$={resultObservable$}>
|
||||
<AiopsAppContext.Provider value={aiopsAppContextValue}>
|
||||
<UrlStateProvider>
|
||||
<DataSourceContextProvider
|
||||
dataViews={pluginStart.data.dataViews}
|
||||
dataViewId={dataViewId}
|
||||
>
|
||||
<LogRateAnalysisReduxProvider>
|
||||
<DatePickerContextProvider {...datePickerDeps}>
|
||||
<LogRateAnalysisDocumentCountChartData timeRange={timeRangeParsed} />
|
||||
<LogRateAnalysisContent />
|
||||
</DatePickerContextProvider>
|
||||
</LogRateAnalysisReduxProvider>
|
||||
</DataSourceContextProvider>
|
||||
</UrlStateProvider>
|
||||
<DatePickerContextProvider {...datePickerDeps}>
|
||||
<UrlStateProvider>
|
||||
<DataSourceContextProvider
|
||||
dataViews={pluginStart.data.dataViews}
|
||||
dataViewId={dataViewId}
|
||||
>
|
||||
<FilterQueryContextProvider timeRange={timeRange}>
|
||||
<LogRateAnalysisReduxProvider>
|
||||
<LogRateAnalysisForEmbeddable timeRange={timeRange} />
|
||||
</LogRateAnalysisReduxProvider>
|
||||
</FilterQueryContextProvider>
|
||||
</DataSourceContextProvider>
|
||||
</UrlStateProvider>
|
||||
</DatePickerContextProvider>
|
||||
</AiopsAppContext.Provider>
|
||||
</ReloadContextProvider>
|
||||
</Router>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue