diff --git a/x-pack/plugins/aiops/public/components/log_rate_analysis/log_rate_analysis_for_embeddable.tsx b/x-pack/plugins/aiops/public/components/log_rate_analysis/log_rate_analysis_for_embeddable.tsx new file mode 100644 index 0000000000000..7357bc1a65ee5 --- /dev/null +++ b/x-pack/plugins/aiops/public/components/log_rate_analysis/log_rate_analysis_for_embeddable.tsx @@ -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 = ({ + 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 ( + <> + + + + ); +}; diff --git a/x-pack/plugins/aiops/public/shared_components/log_rate_analysis_embeddable_wrapper.tsx b/x-pack/plugins/aiops/public/shared_components/log_rate_analysis_embeddable_wrapper.tsx index 2d106ef117061..9f2a88e73461c 100644 --- a/x-pack/plugins/aiops/public/shared_components/log_rate_analysis_embeddable_wrapper.tsx +++ b/x-pack/plugins/aiops/public/shared_components/log_rate_analysis_embeddable_wrapper.tsx @@ -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 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 - - - - - - - - - - + + + + + + + + + + +