Skip to content

Commit

Permalink
Use dashboard's overlay tracker
Browse files Browse the repository at this point in the history
  • Loading branch information
Heenawter committed Sep 28, 2023
1 parent 72f0c4d commit f4608e0
Showing 1 changed file with 6 additions and 19 deletions.
25 changes: 6 additions & 19 deletions src/plugins/links/public/editor/open_editor_flyout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,11 @@
*/

import React from 'react';
import { Subject } from 'rxjs';
import { skip, take, takeUntil } from 'rxjs/operators';

import { withSuspense } from '@kbn/shared-ux-utility';
import { toMountPoint } from '@kbn/react-kibana-mount';
import { EuiLoadingSpinner, EuiPanel } from '@elastic/eui';
import { tracksOverlays } from '@kbn/embeddable-plugin/public';
import { DashboardContainer } from '@kbn/dashboard-plugin/public/dashboard_container';

import { LinksInput, LinksByReferenceInput, LinksEditorFlyoutReturn } from '../embeddable/types';
Expand Down Expand Up @@ -41,6 +40,7 @@ export async function openEditorFlyout(
const { attributes } = await attributeService.unwrapAttributes(initialInput);
const isByReference = attributeService.inputIsRefType(initialInput);
const initialLinks = attributes?.links;
const overlayTracker = tracksOverlays(parentDashboard) ? parentDashboard : undefined;

if (!initialLinks) {
/**
Expand All @@ -55,8 +55,6 @@ export async function openEditorFlyout(
}

return new Promise((resolve, reject) => {
const closed$ = new Subject<true>();

const onSaveToLibrary = async (newLinks: Link[], newLayout: LinksLayoutType) => {
const newAttributes = {
...attributes,
Expand All @@ -76,7 +74,7 @@ export async function openEditorFlyout(
attributes: newAttributes,
});
parentDashboard?.reload();
editorFlyout.close();
if (overlayTracker) overlayTracker.clearOverlays();
};

const onAddToDashboard = (newLinks: Link[], newLayout: LinksLayoutType) => {
Expand All @@ -96,23 +94,14 @@ export async function openEditorFlyout(
attributes: newAttributes,
});
parentDashboard?.reload();
editorFlyout.close();
if (overlayTracker) overlayTracker.clearOverlays();
};

const onCancel = () => {
reject();
editorFlyout.close();
if (overlayTracker) overlayTracker.clearOverlays();
};

// Close the flyout whenever the breadcrumbs change - i.e. when the dashboard's title changes, or when
// the user navigates away from the given dashboard (to the listing page **or** to another app), etc.
coreServices.chrome
.getBreadcrumbs$()
.pipe(takeUntil(closed$), skip(1), take(1))
.subscribe(() => {
editorFlyout.close();
});

const editorFlyout = coreServices.overlays.openFlyout(
toMountPoint(
<LinksEditor
Expand All @@ -136,8 +125,6 @@ export async function openEditorFlyout(
}
);

editorFlyout.onClose.then(() => {
closed$.next(true);
});
if (overlayTracker) overlayTracker.openOverlay(editorFlyout);
});
}

0 comments on commit f4608e0

Please sign in to comment.