Skip to content

Commit

Permalink
update with trackOverlay
Browse files Browse the repository at this point in the history
  • Loading branch information
alvarezmelissa87 committed May 14, 2024
1 parent ab2174e commit 7603fd4
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ export const getSingleMetricViewerEmbeddableFactory = (
const [coreStart, { data, share }, { mlApiServices }] = services;
const result = await resolveEmbeddableSingleMetricViewerUserInput(
coreStart,
parentApi,
uuid,
{ data, share },
mlApiServices,
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
*/

import React from 'react';
import { distinctUntilChanged, from, skip, takeUntil } from 'rxjs';
import type { CoreStart } from '@kbn/core/public';
import { toMountPoint } from '@kbn/react-kibana-mount';
import { KibanaContextProvider } from '@kbn/kibana-react-plugin/public';
import { tracksOverlays } from '@kbn/presentation-containers';
import type { DataPublicPluginStart } from '@kbn/data-plugin/public';
import type { SharePluginStart } from '@kbn/share-plugin/public';
import type { SingleMetricViewerEmbeddableUserInput, SingleMetricViewerEmbeddableInput } from '..';
Expand All @@ -18,18 +18,16 @@ import type { MlApiServices } from '../../application/services/ml_api_service';

export async function resolveEmbeddableSingleMetricViewerUserInput(
coreStart: CoreStart,
parentApi: unknown,
focusedPanelId: string,
services: { data: DataPublicPluginStart; share?: SharePluginStart },
mlApiServices: MlApiServices,
input?: Partial<SingleMetricViewerEmbeddableInput>
): Promise<SingleMetricViewerEmbeddableUserInput> {
const {
http,
overlays,
application: { currentLocation$ },
...startServices
} = coreStart;
const { http, overlays, ...startServices } = coreStart;
const { data, share } = services;
const timefilter = data.query.timefilter.timefilter;
const overlayTracker = tracksOverlays(parentApi) ? parentApi : undefined;

return new Promise(async (resolve, reject) => {
try {
Expand All @@ -51,10 +49,12 @@ export async function resolveEmbeddableSingleMetricViewerUserInput(
onCreate={(explicitInput) => {
flyoutSession.close();
resolve(explicitInput);
overlayTracker?.clearOverlays();
}}
onCancel={() => {
flyoutSession.close();
reject();
overlayTracker?.clearOverlays();
}}
/>
</KibanaContextProvider>,
Expand All @@ -71,11 +71,11 @@ export async function resolveEmbeddableSingleMetricViewerUserInput(
}
);
// Close the flyout when user navigates out of the current plugin
currentLocation$
.pipe(skip(1), takeUntil(from(flyoutSession.onClose)), distinctUntilChanged())
.subscribe(() => {
flyoutSession.close();
if (tracksOverlays(parentApi)) {
parentApi.openOverlay(flyoutSession, {
focusedPanelId,
});
}
} catch (error) {
reject(error);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ export function createAddSingleMetricViewerPanelAction(

const initialState = await resolveEmbeddableSingleMetricViewerUserInput(
coreStart,
context.embeddable,
context.embeddable.uuid,
{ data, share },
mlApiServices
);
Expand Down

0 comments on commit 7603fd4

Please sign in to comment.