From b3061808463cf6b52b0b115f474465aaa0baf94c Mon Sep 17 00:00:00 2001 From: Ola Pawlus Date: Wed, 30 Jul 2025 14:11:39 +0200 Subject: [PATCH 1/8] [ML] Rewrite Log rate analysis flyout to load asynchronously --- .../embeddable_log_rate_analysis_factory.tsx | 45 +++--- ...resolve_log_rate_analysis_config_input.tsx | 138 ++++++++---------- .../create_log_rate_analysis_actions.tsx | 74 +++++----- 3 files changed, 129 insertions(+), 128 deletions(-) diff --git a/x-pack/platform/plugins/shared/aiops/public/embeddables/log_rate_analysis/embeddable_log_rate_analysis_factory.tsx b/x-pack/platform/plugins/shared/aiops/public/embeddables/log_rate_analysis/embeddable_log_rate_analysis_factory.tsx index 2da4f7198c71a..1fdc2bac31ea3 100644 --- a/x-pack/platform/plugins/shared/aiops/public/embeddables/log_rate_analysis/embeddable_log_rate_analysis_factory.tsx +++ b/x-pack/platform/plugins/shared/aiops/public/embeddables/log_rate_analysis/embeddable_log_rate_analysis_factory.tsx @@ -13,6 +13,8 @@ import type { StartServicesAccessor } from '@kbn/core-lifecycle-browser'; import type { DataView } from '@kbn/data-views-plugin/common'; import type { EmbeddableFactory } from '@kbn/embeddable-plugin/public'; import { i18n } from '@kbn/i18n'; +import { openLazyFlyout } from '@kbn/presentation-util'; + import { type SerializedPanelState, apiHasExecutionContext, @@ -36,6 +38,7 @@ import type { AiopsPluginStart, AiopsPluginStartDeps } from '../../types'; import { initializeLogRateAnalysisControls } from './initialize_log_rate_analysis_analysis_controls'; import type { LogRateAnalysisEmbeddableApi, LogRateAnalysisEmbeddableState } from './types'; import { getDataviewReferences } from '../get_dataview_references'; +import { EmbeddableLogRateAnalysisUserInput } from './resolve_log_rate_analysis_config_input'; export type EmbeddableLogRateAnalysisType = typeof EMBEDDABLE_LOG_RATE_ANALYSIS_TYPE; @@ -130,26 +133,28 @@ export const getLogRateAnalysisEmbeddableFactory = ( }), isEditingEnabled: () => true, onEdit: async () => { - try { - const { resolveEmbeddableLogRateAnalysisUserInput } = await import( - './resolve_log_rate_analysis_config_input' - ); - - const result = await resolveEmbeddableLogRateAnalysisUserInput( - coreStart, - pluginStart, - parentApi, - uuid, - false, - logRateAnalysisControlsApi, - undefined, - serializeLogRateAnalysisChartState() - ); - - logRateAnalysisControlsApi.updateUserInput(result); - } catch (e) { - return Promise.reject(); - } + openLazyFlyout({ + core: coreStart, + parentApi, + flyoutProps: { + focusedPanelId: uuid, + }, + loadContent: async ({ closeFlyout }) => { + return ( + { + logRateAnalysisControlsApi.updateUserInput(result); + closeFlyout(); + }} + onCancel={closeFlyout} + initialState={serializeLogRateAnalysisChartState()} + /> + ); + }, + }); }, dataLoading$, blockingError$, diff --git a/x-pack/platform/plugins/shared/aiops/public/embeddables/log_rate_analysis/resolve_log_rate_analysis_config_input.tsx b/x-pack/platform/plugins/shared/aiops/public/embeddables/log_rate_analysis/resolve_log_rate_analysis_config_input.tsx index 8a9ec1dfc826d..6719d00f17494 100644 --- a/x-pack/platform/plugins/shared/aiops/public/embeddables/log_rate_analysis/resolve_log_rate_analysis_config_input.tsx +++ b/x-pack/platform/plugins/shared/aiops/public/embeddables/log_rate_analysis/resolve_log_rate_analysis_config_input.tsx @@ -5,90 +5,78 @@ * 2.0. */ -import type { CoreStart } from '@kbn/core/public'; -import { tracksOverlays } from '@kbn/presentation-util'; -import { toMountPoint } from '@kbn/react-kibana-mount'; import React from 'react'; import type { AiopsPluginStartDeps } from '../../types'; import { LogRateAnalysisEmbeddableInitializer } from './log_rate_analysis_embeddable_initializer'; import type { LogRateAnalysisComponentApi, LogRateAnalysisEmbeddableState } from './types'; -export async function resolveEmbeddableLogRateAnalysisUserInput( - coreStart: CoreStart, - pluginStart: AiopsPluginStartDeps, - parentApi: unknown, - focusedPanelId: string, - isNewPanel: boolean, - logRateAnalysisControlsApi: LogRateAnalysisComponentApi, - deletePanel?: () => void, - initialState?: LogRateAnalysisEmbeddableState -): Promise { - const { overlays } = coreStart; +export function EmbeddableLogRateAnalysisUserInput({ + pluginStart, + isNewPanel, + logRateAnalysisControlsApi, + deletePanel, + initialState, + onCancel, + onConfirm, +}: { + pluginStart: AiopsPluginStartDeps; + isNewPanel: boolean; + logRateAnalysisControlsApi: LogRateAnalysisComponentApi; + deletePanel?: () => void; + initialState?: LogRateAnalysisEmbeddableState; + onCancel: () => void; + onConfirm: (newUpdate: LogRateAnalysisEmbeddableState) => void; +}) { + const hasChanged = React.useRef(false); + // Detects if the flyout was closed via "X" (not Confirm or Cancel) to clean up the panel preview state + const hasConfirmed = React.useRef(false); + const hasCanceled = React.useRef(false); - const overlayTracker = tracksOverlays(parentApi) ? parentApi : undefined; - - let hasChanged = false; - return new Promise(async (resolve, reject) => { - try { - const cancelChanges = () => { - if (isNewPanel && deletePanel) { - deletePanel(); - } else if (hasChanged && logRateAnalysisControlsApi && initialState) { - // Reset to initialState in case user has changed the preview state - logRateAnalysisControlsApi.updateUserInput(initialState); - } - - flyoutSession.close(); - overlayTracker?.clearOverlays(); - }; + const cleanPreviewIfNotConfirmed = React.useCallback(() => { + if (isNewPanel && deletePanel) { + deletePanel(); + onCancel(); + } else if (hasChanged.current && logRateAnalysisControlsApi && initialState) { + logRateAnalysisControlsApi.updateUserInput(initialState); + onCancel(); + } + }, [isNewPanel, deletePanel, onCancel, logRateAnalysisControlsApi, initialState]); - const update = async (nextUpdate: LogRateAnalysisEmbeddableState) => { - resolve(nextUpdate); - flyoutSession.close(); - overlayTracker?.clearOverlays(); - }; + React.useEffect(() => { + return () => { + if (hasConfirmed.current || hasCanceled.current) { + return; + } + cleanPreviewIfNotConfirmed(); + }; + }, [cleanPreviewIfNotConfirmed]); - const preview = async (nextUpdate: LogRateAnalysisEmbeddableState) => { - if (logRateAnalysisControlsApi) { - logRateAnalysisControlsApi.updateUserInput(nextUpdate); - hasChanged = true; - } - }; + const cancelChanges = () => { + hasCanceled.current = true; + cleanPreviewIfNotConfirmed(); + }; - const flyoutSession = overlays.openFlyout( - toMountPoint( - , - coreStart - ), - { - ownFocus: true, - size: 's', - type: 'push', - paddingSize: 'm', - hideCloseButton: true, - 'data-test-subj': 'aiopsLogRateAnalysisEmbeddableInitializer', - 'aria-labelledby': 'logRateAnalysisConfig', - onClose: () => { - reject(); - flyoutSession.close(); - overlayTracker?.clearOverlays(); - }, - } - ); + const confirmChanges = (nextUpdate: LogRateAnalysisEmbeddableState) => { + hasConfirmed.current = true; + onConfirm(nextUpdate); + }; - if (tracksOverlays(parentApi)) { - parentApi.openOverlay(flyoutSession, { focusedPanelId }); - } - } catch (error) { - reject(error); + const preview = async (nextUpdate: LogRateAnalysisEmbeddableState) => { + if (logRateAnalysisControlsApi) { + logRateAnalysisControlsApi.updateUserInput(nextUpdate); + hasChanged.current = true; } - }); + }; + + return ( + + ); } diff --git a/x-pack/platform/plugins/shared/aiops/public/ui_actions/create_log_rate_analysis_actions.tsx b/x-pack/platform/plugins/shared/aiops/public/ui_actions/create_log_rate_analysis_actions.tsx index 162067036a156..4eb5ae0f981af 100644 --- a/x-pack/platform/plugins/shared/aiops/public/ui_actions/create_log_rate_analysis_actions.tsx +++ b/x-pack/platform/plugins/shared/aiops/public/ui_actions/create_log_rate_analysis_actions.tsx @@ -5,7 +5,9 @@ * 2.0. */ +import React from 'react'; import { i18n } from '@kbn/i18n'; +import { openLazyFlyout } from '@kbn/presentation-util'; import type { PresentationContainer } from '@kbn/presentation-containers'; import type { EmbeddableApiContext } from '@kbn/presentation-publishing'; import type { UiActionsActionDefinition } from '@kbn/ui-actions-plugin/public'; @@ -21,6 +23,7 @@ import type { import type { AiopsPluginStartDeps } from '../types'; import type { LogRateAnalysisActionContext } from './log_rate_analysis_action_context'; +import { EmbeddableLogRateAnalysisUserInput } from '../embeddables/log_rate_analysis/resolve_log_rate_analysis_config_input'; const parentApiIsCompatible = async ( parentApi: unknown @@ -49,43 +52,48 @@ export function createAddLogRateAnalysisEmbeddableAction( const presentationContainerParent = await parentApiIsCompatible(context.embeddable); if (!presentationContainerParent) throw new IncompatibleActionError(); - try { - const { resolveEmbeddableLogRateAnalysisUserInput } = await import( - '../embeddables/log_rate_analysis/resolve_log_rate_analysis_config_input' - ); + const initialState: LogRateAnalysisEmbeddableInitialState = { + dataViewId: undefined, + }; - const initialState: LogRateAnalysisEmbeddableInitialState = { - dataViewId: undefined, - }; + const embeddable = await presentationContainerParent.addNewPanel< + object, + LogRateAnalysisEmbeddableApi + >({ + panelType: EMBEDDABLE_LOG_RATE_ANALYSIS_TYPE, + serializedState: { rawState: initialState }, + }); - const embeddable = await presentationContainerParent.addNewPanel< - object, - LogRateAnalysisEmbeddableApi - >({ - panelType: EMBEDDABLE_LOG_RATE_ANALYSIS_TYPE, - serializedState: { rawState: initialState }, - }); - - if (!embeddable) { - return; - } + if (!embeddable) { + return; + } - const deletePanel = () => { - presentationContainerParent.removePanel(embeddable.uuid); - }; + const deletePanel = () => { + presentationContainerParent.removePanel(embeddable.uuid); + }; - resolveEmbeddableLogRateAnalysisUserInput( - coreStart, - pluginStart, - context.embeddable, - embeddable.uuid, - true, - embeddable, - deletePanel - ); - } catch (e) { - return Promise.reject(); - } + openLazyFlyout({ + core: coreStart, + parentApi: context.embeddable, + flyoutProps: { + focusedPanelId: context.embeddable.uuid, + }, + loadContent: async ({ closeFlyout }) => { + return ( + { + embeddable.updateUserInput(updatedState); + closeFlyout(); + }} + onCancel={closeFlyout} + /> + ); + }, + }); }, }; } From a6099ad0d2c30769d45942c01e29eb75529b4f34 Mon Sep 17 00:00:00 2001 From: Ola Pawlus Date: Wed, 30 Jul 2025 14:36:49 +0200 Subject: [PATCH 2/8] refactor --- .../resolve_log_rate_analysis_config_input.tsx | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/x-pack/platform/plugins/shared/aiops/public/embeddables/log_rate_analysis/resolve_log_rate_analysis_config_input.tsx b/x-pack/platform/plugins/shared/aiops/public/embeddables/log_rate_analysis/resolve_log_rate_analysis_config_input.tsx index 6719d00f17494..ce7cbc61de919 100644 --- a/x-pack/platform/plugins/shared/aiops/public/embeddables/log_rate_analysis/resolve_log_rate_analysis_config_input.tsx +++ b/x-pack/platform/plugins/shared/aiops/public/embeddables/log_rate_analysis/resolve_log_rate_analysis_config_input.tsx @@ -14,18 +14,18 @@ export function EmbeddableLogRateAnalysisUserInput({ pluginStart, isNewPanel, logRateAnalysisControlsApi, - deletePanel, - initialState, onCancel, onConfirm, + deletePanel, + initialState, }: { pluginStart: AiopsPluginStartDeps; isNewPanel: boolean; logRateAnalysisControlsApi: LogRateAnalysisComponentApi; - deletePanel?: () => void; - initialState?: LogRateAnalysisEmbeddableState; onCancel: () => void; onConfirm: (newUpdate: LogRateAnalysisEmbeddableState) => void; + deletePanel?: () => void; + initialState?: LogRateAnalysisEmbeddableState; }) { const hasChanged = React.useRef(false); // Detects if the flyout was closed via "X" (not Confirm or Cancel) to clean up the panel preview state From 16d2ef30b5bf7ebea0a9f66295997691113d3e24 Mon Sep 17 00:00:00 2001 From: Ola Pawlus Date: Wed, 30 Jul 2025 16:33:56 +0200 Subject: [PATCH 3/8] renaming the file --- .../log_rate_analysis/embeddable_log_rate_analysis_factory.tsx | 2 +- ...ysis_config_input.tsx => log_rate_analysis_config_input.tsx} | 0 .../public/ui_actions/create_log_rate_analysis_actions.tsx | 2 +- 3 files changed, 2 insertions(+), 2 deletions(-) rename x-pack/platform/plugins/shared/aiops/public/embeddables/log_rate_analysis/{resolve_log_rate_analysis_config_input.tsx => log_rate_analysis_config_input.tsx} (100%) diff --git a/x-pack/platform/plugins/shared/aiops/public/embeddables/log_rate_analysis/embeddable_log_rate_analysis_factory.tsx b/x-pack/platform/plugins/shared/aiops/public/embeddables/log_rate_analysis/embeddable_log_rate_analysis_factory.tsx index 1fdc2bac31ea3..6d952294e43bb 100644 --- a/x-pack/platform/plugins/shared/aiops/public/embeddables/log_rate_analysis/embeddable_log_rate_analysis_factory.tsx +++ b/x-pack/platform/plugins/shared/aiops/public/embeddables/log_rate_analysis/embeddable_log_rate_analysis_factory.tsx @@ -38,7 +38,7 @@ import type { AiopsPluginStart, AiopsPluginStartDeps } from '../../types'; import { initializeLogRateAnalysisControls } from './initialize_log_rate_analysis_analysis_controls'; import type { LogRateAnalysisEmbeddableApi, LogRateAnalysisEmbeddableState } from './types'; import { getDataviewReferences } from '../get_dataview_references'; -import { EmbeddableLogRateAnalysisUserInput } from './resolve_log_rate_analysis_config_input'; +import { EmbeddableLogRateAnalysisUserInput } from './log_rate_analysis_config_input'; export type EmbeddableLogRateAnalysisType = typeof EMBEDDABLE_LOG_RATE_ANALYSIS_TYPE; diff --git a/x-pack/platform/plugins/shared/aiops/public/embeddables/log_rate_analysis/resolve_log_rate_analysis_config_input.tsx b/x-pack/platform/plugins/shared/aiops/public/embeddables/log_rate_analysis/log_rate_analysis_config_input.tsx similarity index 100% rename from x-pack/platform/plugins/shared/aiops/public/embeddables/log_rate_analysis/resolve_log_rate_analysis_config_input.tsx rename to x-pack/platform/plugins/shared/aiops/public/embeddables/log_rate_analysis/log_rate_analysis_config_input.tsx diff --git a/x-pack/platform/plugins/shared/aiops/public/ui_actions/create_log_rate_analysis_actions.tsx b/x-pack/platform/plugins/shared/aiops/public/ui_actions/create_log_rate_analysis_actions.tsx index 4eb5ae0f981af..fce0ee6a92243 100644 --- a/x-pack/platform/plugins/shared/aiops/public/ui_actions/create_log_rate_analysis_actions.tsx +++ b/x-pack/platform/plugins/shared/aiops/public/ui_actions/create_log_rate_analysis_actions.tsx @@ -23,7 +23,7 @@ import type { import type { AiopsPluginStartDeps } from '../types'; import type { LogRateAnalysisActionContext } from './log_rate_analysis_action_context'; -import { EmbeddableLogRateAnalysisUserInput } from '../embeddables/log_rate_analysis/resolve_log_rate_analysis_config_input'; +import { EmbeddableLogRateAnalysisUserInput } from '../embeddables/log_rate_analysis/log_rate_analysis_config_input'; const parentApiIsCompatible = async ( parentApi: unknown From ac5711a48cbcefa3c8e60d409727f5b8895e88b6 Mon Sep 17 00:00:00 2001 From: Ola Pawlus Date: Wed, 30 Jul 2025 16:48:43 +0200 Subject: [PATCH 4/8] flyout configuration to hide x button --- .../embeddable_log_rate_analysis_factory.tsx | 1 + .../log_rate_analysis_config_input.tsx | 26 ++----------------- .../create_log_rate_analysis_actions.tsx | 1 + 3 files changed, 4 insertions(+), 24 deletions(-) diff --git a/x-pack/platform/plugins/shared/aiops/public/embeddables/log_rate_analysis/embeddable_log_rate_analysis_factory.tsx b/x-pack/platform/plugins/shared/aiops/public/embeddables/log_rate_analysis/embeddable_log_rate_analysis_factory.tsx index 6d952294e43bb..03815e08b7e90 100644 --- a/x-pack/platform/plugins/shared/aiops/public/embeddables/log_rate_analysis/embeddable_log_rate_analysis_factory.tsx +++ b/x-pack/platform/plugins/shared/aiops/public/embeddables/log_rate_analysis/embeddable_log_rate_analysis_factory.tsx @@ -137,6 +137,7 @@ export const getLogRateAnalysisEmbeddableFactory = ( core: coreStart, parentApi, flyoutProps: { + hideCloseButton: true, focusedPanelId: uuid, }, loadContent: async ({ closeFlyout }) => { diff --git a/x-pack/platform/plugins/shared/aiops/public/embeddables/log_rate_analysis/log_rate_analysis_config_input.tsx b/x-pack/platform/plugins/shared/aiops/public/embeddables/log_rate_analysis/log_rate_analysis_config_input.tsx index ce7cbc61de919..4cae3d2e93972 100644 --- a/x-pack/platform/plugins/shared/aiops/public/embeddables/log_rate_analysis/log_rate_analysis_config_input.tsx +++ b/x-pack/platform/plugins/shared/aiops/public/embeddables/log_rate_analysis/log_rate_analysis_config_input.tsx @@ -28,11 +28,8 @@ export function EmbeddableLogRateAnalysisUserInput({ initialState?: LogRateAnalysisEmbeddableState; }) { const hasChanged = React.useRef(false); - // Detects if the flyout was closed via "X" (not Confirm or Cancel) to clean up the panel preview state - const hasConfirmed = React.useRef(false); - const hasCanceled = React.useRef(false); - const cleanPreviewIfNotConfirmed = React.useCallback(() => { + const cancelChanges = () => { if (isNewPanel && deletePanel) { deletePanel(); onCancel(); @@ -40,25 +37,6 @@ export function EmbeddableLogRateAnalysisUserInput({ logRateAnalysisControlsApi.updateUserInput(initialState); onCancel(); } - }, [isNewPanel, deletePanel, onCancel, logRateAnalysisControlsApi, initialState]); - - React.useEffect(() => { - return () => { - if (hasConfirmed.current || hasCanceled.current) { - return; - } - cleanPreviewIfNotConfirmed(); - }; - }, [cleanPreviewIfNotConfirmed]); - - const cancelChanges = () => { - hasCanceled.current = true; - cleanPreviewIfNotConfirmed(); - }; - - const confirmChanges = (nextUpdate: LogRateAnalysisEmbeddableState) => { - hasConfirmed.current = true; - onConfirm(nextUpdate); }; const preview = async (nextUpdate: LogRateAnalysisEmbeddableState) => { @@ -73,7 +51,7 @@ export function EmbeddableLogRateAnalysisUserInput({ dataViews={pluginStart.data.dataViews} IndexPatternSelect={pluginStart.unifiedSearch.ui.IndexPatternSelect} initialInput={initialState} - onCreate={confirmChanges} + onCreate={onConfirm} onCancel={cancelChanges} onPreview={preview} isNewPanel={isNewPanel} diff --git a/x-pack/platform/plugins/shared/aiops/public/ui_actions/create_log_rate_analysis_actions.tsx b/x-pack/platform/plugins/shared/aiops/public/ui_actions/create_log_rate_analysis_actions.tsx index fce0ee6a92243..09ffada80326d 100644 --- a/x-pack/platform/plugins/shared/aiops/public/ui_actions/create_log_rate_analysis_actions.tsx +++ b/x-pack/platform/plugins/shared/aiops/public/ui_actions/create_log_rate_analysis_actions.tsx @@ -76,6 +76,7 @@ export function createAddLogRateAnalysisEmbeddableAction( core: coreStart, parentApi: context.embeddable, flyoutProps: { + hideCloseButton: true, focusedPanelId: context.embeddable.uuid, }, loadContent: async ({ closeFlyout }) => { From d4bcfe98369add7873fb34c14c9b983870925c32 Mon Sep 17 00:00:00 2001 From: Ola Pawlus Date: Thu, 31 Jul 2025 10:08:02 +0200 Subject: [PATCH 5/8] changes after cr --- .../log_rate_analysis/embeddable_log_rate_analysis_factory.tsx | 2 ++ .../public/ui_actions/create_log_rate_analysis_actions.tsx | 2 ++ 2 files changed, 4 insertions(+) diff --git a/x-pack/platform/plugins/shared/aiops/public/embeddables/log_rate_analysis/embeddable_log_rate_analysis_factory.tsx b/x-pack/platform/plugins/shared/aiops/public/embeddables/log_rate_analysis/embeddable_log_rate_analysis_factory.tsx index 03815e08b7e90..88378a4c21781 100644 --- a/x-pack/platform/plugins/shared/aiops/public/embeddables/log_rate_analysis/embeddable_log_rate_analysis_factory.tsx +++ b/x-pack/platform/plugins/shared/aiops/public/embeddables/log_rate_analysis/embeddable_log_rate_analysis_factory.tsx @@ -139,6 +139,8 @@ export const getLogRateAnalysisEmbeddableFactory = ( flyoutProps: { hideCloseButton: true, focusedPanelId: uuid, + 'data-test-subj': 'aiopsLogRateAnalysisEmbeddableInitializer', + 'aria-labelledby': 'logRateAnalysisConfig', }, loadContent: async ({ closeFlyout }) => { return ( diff --git a/x-pack/platform/plugins/shared/aiops/public/ui_actions/create_log_rate_analysis_actions.tsx b/x-pack/platform/plugins/shared/aiops/public/ui_actions/create_log_rate_analysis_actions.tsx index 09ffada80326d..d0be1a67c6296 100644 --- a/x-pack/platform/plugins/shared/aiops/public/ui_actions/create_log_rate_analysis_actions.tsx +++ b/x-pack/platform/plugins/shared/aiops/public/ui_actions/create_log_rate_analysis_actions.tsx @@ -78,6 +78,8 @@ export function createAddLogRateAnalysisEmbeddableAction( flyoutProps: { hideCloseButton: true, focusedPanelId: context.embeddable.uuid, + 'data-test-subj': 'aiopsLogRateAnalysisEmbeddableInitializer', + 'aria-labelledby': 'logRateAnalysisConfig', }, loadContent: async ({ closeFlyout }) => { return ( From 24775796389fb6384faca3a215f1bb0d7f468b4b Mon Sep 17 00:00:00 2001 From: Ola Pawlus Date: Thu, 31 Jul 2025 10:14:39 +0200 Subject: [PATCH 6/8] refactor after cr --- .../create_log_rate_analysis_actions.tsx | 39 +++++++++---------- 1 file changed, 19 insertions(+), 20 deletions(-) diff --git a/x-pack/platform/plugins/shared/aiops/public/ui_actions/create_log_rate_analysis_actions.tsx b/x-pack/platform/plugins/shared/aiops/public/ui_actions/create_log_rate_analysis_actions.tsx index d0be1a67c6296..da36ef2946cd6 100644 --- a/x-pack/platform/plugins/shared/aiops/public/ui_actions/create_log_rate_analysis_actions.tsx +++ b/x-pack/platform/plugins/shared/aiops/public/ui_actions/create_log_rate_analysis_actions.tsx @@ -52,26 +52,6 @@ export function createAddLogRateAnalysisEmbeddableAction( const presentationContainerParent = await parentApiIsCompatible(context.embeddable); if (!presentationContainerParent) throw new IncompatibleActionError(); - const initialState: LogRateAnalysisEmbeddableInitialState = { - dataViewId: undefined, - }; - - const embeddable = await presentationContainerParent.addNewPanel< - object, - LogRateAnalysisEmbeddableApi - >({ - panelType: EMBEDDABLE_LOG_RATE_ANALYSIS_TYPE, - serializedState: { rawState: initialState }, - }); - - if (!embeddable) { - return; - } - - const deletePanel = () => { - presentationContainerParent.removePanel(embeddable.uuid); - }; - openLazyFlyout({ core: coreStart, parentApi: context.embeddable, @@ -82,6 +62,25 @@ export function createAddLogRateAnalysisEmbeddableAction( 'aria-labelledby': 'logRateAnalysisConfig', }, loadContent: async ({ closeFlyout }) => { + const initialState: LogRateAnalysisEmbeddableInitialState = { + dataViewId: undefined, + }; + + const embeddable = await presentationContainerParent.addNewPanel< + object, + LogRateAnalysisEmbeddableApi + >({ + panelType: EMBEDDABLE_LOG_RATE_ANALYSIS_TYPE, + serializedState: { rawState: initialState }, + }); + + if (!embeddable) { + return; + } + + const deletePanel = () => { + presentationContainerParent.removePanel(embeddable.uuid); + }; return ( Date: Thu, 31 Jul 2025 11:59:26 +0200 Subject: [PATCH 7/8] uuid bug --- .../public/ui_actions/create_log_rate_analysis_actions.tsx | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/x-pack/platform/plugins/shared/aiops/public/ui_actions/create_log_rate_analysis_actions.tsx b/x-pack/platform/plugins/shared/aiops/public/ui_actions/create_log_rate_analysis_actions.tsx index da36ef2946cd6..b8d2265fadc4e 100644 --- a/x-pack/platform/plugins/shared/aiops/public/ui_actions/create_log_rate_analysis_actions.tsx +++ b/x-pack/platform/plugins/shared/aiops/public/ui_actions/create_log_rate_analysis_actions.tsx @@ -16,6 +16,7 @@ import type { CoreStart } from '@kbn/core-lifecycle-browser'; import { EMBEDDABLE_LOG_RATE_ANALYSIS_TYPE } from '@kbn/aiops-log-rate-analysis/constants'; import { AIOPS_EMBEDDABLE_GROUPING } from '@kbn/aiops-common/constants'; +import { v4 } from 'uuid'; import type { LogRateAnalysisEmbeddableApi, LogRateAnalysisEmbeddableInitialState, @@ -52,12 +53,14 @@ export function createAddLogRateAnalysisEmbeddableAction( const presentationContainerParent = await parentApiIsCompatible(context.embeddable); if (!presentationContainerParent) throw new IncompatibleActionError(); + const uuid = v4(); + openLazyFlyout({ core: coreStart, parentApi: context.embeddable, flyoutProps: { hideCloseButton: true, - focusedPanelId: context.embeddable.uuid, + focusedPanelId: uuid, 'data-test-subj': 'aiopsLogRateAnalysisEmbeddableInitializer', 'aria-labelledby': 'logRateAnalysisConfig', }, @@ -72,6 +75,7 @@ export function createAddLogRateAnalysisEmbeddableAction( >({ panelType: EMBEDDABLE_LOG_RATE_ANALYSIS_TYPE, serializedState: { rawState: initialState }, + maybePanelId: uuid, }); if (!embeddable) { From 9ecbb53a7b83ad7256b488f223815cd3c6b6083e Mon Sep 17 00:00:00 2001 From: mbondyra Date: Thu, 31 Jul 2025 12:16:59 +0200 Subject: [PATCH 8/8] some corrections --- .../embeddable_log_rate_analysis_factory.tsx | 9 ++++--- .../log_rate_analysis_config_input.tsx | 27 +++++-------------- ...g_rate_analysis_embeddable_initializer.tsx | 2 +- .../create_log_rate_analysis_actions.tsx | 9 +++---- 4 files changed, 17 insertions(+), 30 deletions(-) diff --git a/x-pack/platform/plugins/shared/aiops/public/embeddables/log_rate_analysis/embeddable_log_rate_analysis_factory.tsx b/x-pack/platform/plugins/shared/aiops/public/embeddables/log_rate_analysis/embeddable_log_rate_analysis_factory.tsx index 88378a4c21781..1ddae8a5a55f1 100644 --- a/x-pack/platform/plugins/shared/aiops/public/embeddables/log_rate_analysis/embeddable_log_rate_analysis_factory.tsx +++ b/x-pack/platform/plugins/shared/aiops/public/embeddables/log_rate_analysis/embeddable_log_rate_analysis_factory.tsx @@ -143,17 +143,20 @@ export const getLogRateAnalysisEmbeddableFactory = ( 'aria-labelledby': 'logRateAnalysisConfig', }, loadContent: async ({ closeFlyout }) => { + const initState = serializeLogRateAnalysisChartState(); return ( { logRateAnalysisControlsApi.updateUserInput(result); closeFlyout(); }} - onCancel={closeFlyout} - initialState={serializeLogRateAnalysisChartState()} + onCancel={() => { + logRateAnalysisControlsApi.updateUserInput(initState); + closeFlyout(); + }} + initialState={initState} /> ); }, diff --git a/x-pack/platform/plugins/shared/aiops/public/embeddables/log_rate_analysis/log_rate_analysis_config_input.tsx b/x-pack/platform/plugins/shared/aiops/public/embeddables/log_rate_analysis/log_rate_analysis_config_input.tsx index 4cae3d2e93972..b59024b8b10b6 100644 --- a/x-pack/platform/plugins/shared/aiops/public/embeddables/log_rate_analysis/log_rate_analysis_config_input.tsx +++ b/x-pack/platform/plugins/shared/aiops/public/embeddables/log_rate_analysis/log_rate_analysis_config_input.tsx @@ -12,37 +12,22 @@ import type { LogRateAnalysisComponentApi, LogRateAnalysisEmbeddableState } from export function EmbeddableLogRateAnalysisUserInput({ pluginStart, - isNewPanel, logRateAnalysisControlsApi, onCancel, onConfirm, - deletePanel, initialState, + isNewPanel, }: { pluginStart: AiopsPluginStartDeps; - isNewPanel: boolean; logRateAnalysisControlsApi: LogRateAnalysisComponentApi; onCancel: () => void; onConfirm: (newUpdate: LogRateAnalysisEmbeddableState) => void; - deletePanel?: () => void; initialState?: LogRateAnalysisEmbeddableState; + isNewPanel?: boolean; }) { - const hasChanged = React.useRef(false); - - const cancelChanges = () => { - if (isNewPanel && deletePanel) { - deletePanel(); - onCancel(); - } else if (hasChanged.current && logRateAnalysisControlsApi && initialState) { - logRateAnalysisControlsApi.updateUserInput(initialState); - onCancel(); - } - }; - - const preview = async (nextUpdate: LogRateAnalysisEmbeddableState) => { + const handlePreview = async (nextUpdate: LogRateAnalysisEmbeddableState) => { if (logRateAnalysisControlsApi) { logRateAnalysisControlsApi.updateUserInput(nextUpdate); - hasChanged.current = true; } }; @@ -52,9 +37,9 @@ export function EmbeddableLogRateAnalysisUserInput({ IndexPatternSelect={pluginStart.unifiedSearch.ui.IndexPatternSelect} initialInput={initialState} onCreate={onConfirm} - onCancel={cancelChanges} - onPreview={preview} - isNewPanel={isNewPanel} + onCancel={onCancel} + onPreview={handlePreview} + isNewPanel={Boolean(isNewPanel)} /> ); } diff --git a/x-pack/platform/plugins/shared/aiops/public/embeddables/log_rate_analysis/log_rate_analysis_embeddable_initializer.tsx b/x-pack/platform/plugins/shared/aiops/public/embeddables/log_rate_analysis/log_rate_analysis_embeddable_initializer.tsx index 329c202780bdc..ca3592da3bcb0 100644 --- a/x-pack/platform/plugins/shared/aiops/public/embeddables/log_rate_analysis/log_rate_analysis_embeddable_initializer.tsx +++ b/x-pack/platform/plugins/shared/aiops/public/embeddables/log_rate_analysis/log_rate_analysis_embeddable_initializer.tsx @@ -141,7 +141,7 @@ export const LogRateAnalysisEmbeddableInitializer: FC< }} > -

+

{isNewPanel ? i18n.translate('xpack.aiops.embeddableLogRateAnalysis.config.title.new', { defaultMessage: 'Create log rate analysis', diff --git a/x-pack/platform/plugins/shared/aiops/public/ui_actions/create_log_rate_analysis_actions.tsx b/x-pack/platform/plugins/shared/aiops/public/ui_actions/create_log_rate_analysis_actions.tsx index b8d2265fadc4e..f11b33c99564c 100644 --- a/x-pack/platform/plugins/shared/aiops/public/ui_actions/create_log_rate_analysis_actions.tsx +++ b/x-pack/platform/plugins/shared/aiops/public/ui_actions/create_log_rate_analysis_actions.tsx @@ -82,20 +82,19 @@ export function createAddLogRateAnalysisEmbeddableAction( return; } - const deletePanel = () => { - presentationContainerParent.removePanel(embeddable.uuid); - }; return ( { embeddable.updateUserInput(updatedState); closeFlyout(); }} - onCancel={closeFlyout} + onCancel={() => { + presentationContainerParent.removePanel(embeddable.uuid); + closeFlyout(); + }} /> ); },