New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Dashboard Navigation] Add Links to Visualization library #170810
Changes from 6 commits
bc227bd
e0f60ed
ed143f9
89b806a
3c4ba63
40970bf
4ddfef2
7ac5512
9558736
e478165
991c416
f73100a
be38830
df35a2c
70c98e1
99df0f9
554f844
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,18 +7,20 @@ | |
*/ | ||
|
||
import React from 'react'; | ||
import { skip, take } 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 { tracksOverlays } from '@kbn/embeddable-plugin/public'; | ||
import { toMountPoint } from '@kbn/react-kibana-mount'; | ||
import { withSuspense } from '@kbn/shared-ux-utility'; | ||
|
||
import { LinksInput, LinksByReferenceInput, LinksEditorFlyoutReturn } from '../embeddable/types'; | ||
import { coreServices } from '../services/kibana_services'; | ||
import { runSaveToLibrary } from '../content_management/save_to_library'; | ||
import { OverlayRef } from '@kbn/core-mount-utils-browser'; | ||
import { Link, LinksLayoutType } from '../../common/content_management'; | ||
import { runSaveToLibrary } from '../content_management/save_to_library'; | ||
import { LinksByReferenceInput, LinksEditorFlyoutReturn, LinksInput } from '../embeddable/types'; | ||
import { getLinksAttributeService } from '../services/attribute_service'; | ||
import { coreServices } from '../services/kibana_services'; | ||
|
||
const LazyLinksEditor = React.lazy(() => import('../components/editor/links_editor')); | ||
|
||
|
@@ -40,7 +42,8 @@ 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; | ||
const overlayTracker = | ||
parentDashboard && tracksOverlays(parentDashboard) ? parentDashboard : undefined; | ||
|
||
if (!initialLinks) { | ||
/** | ||
|
@@ -55,6 +58,22 @@ export async function openEditorFlyout( | |
} | ||
|
||
return new Promise((resolve, reject) => { | ||
const closeEditorFlyout = (editorFlyout: OverlayRef) => { | ||
if (overlayTracker) { | ||
overlayTracker.clearOverlays(); | ||
} else { | ||
editorFlyout.close(); | ||
} | ||
}; | ||
Comment on lines
+61
to
+67
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can no longer assume that the |
||
|
||
/** | ||
* Close the flyout whenever the app changes - this handles cases for when the flyout is open outside of the | ||
* Dashboard app (`overlayTracker` is not available) | ||
*/ | ||
coreServices.application.currentAppId$.pipe(skip(1), take(1)).subscribe(() => { | ||
if (!overlayTracker) editorFlyout.close(); | ||
}); | ||
|
||
const onSaveToLibrary = async (newLinks: Link[], newLayout: LinksLayoutType) => { | ||
const newAttributes = { | ||
...attributes, | ||
|
@@ -74,7 +93,7 @@ export async function openEditorFlyout( | |
attributes: newAttributes, | ||
}); | ||
parentDashboard?.reload(); | ||
if (overlayTracker) overlayTracker.clearOverlays(); | ||
closeEditorFlyout(editorFlyout); | ||
}; | ||
|
||
const onAddToDashboard = (newLinks: Link[], newLayout: LinksLayoutType) => { | ||
|
@@ -94,12 +113,12 @@ export async function openEditorFlyout( | |
attributes: newAttributes, | ||
}); | ||
parentDashboard?.reload(); | ||
if (overlayTracker) overlayTracker.clearOverlays(); | ||
closeEditorFlyout(editorFlyout); | ||
}; | ||
|
||
const onCancel = () => { | ||
reject(); | ||
if (overlayTracker) overlayTracker.clearOverlays(); | ||
closeEditorFlyout(editorFlyout); | ||
}; | ||
|
||
const editorFlyout = coreServices.overlays.openFlyout( | ||
|
@@ -125,6 +144,8 @@ export async function openEditorFlyout( | |
} | ||
); | ||
|
||
if (overlayTracker) overlayTracker.openOverlay(editorFlyout); | ||
if (overlayTracker) { | ||
overlayTracker.openOverlay(editorFlyout); | ||
} | ||
}); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -128,8 +128,6 @@ export class LinksFactoryDefinition | |
initialInput: LinksInput, | ||
parent?: DashboardContainer | ||
): Promise<LinksEditorFlyoutReturn> { | ||
if (!parent) return { newInput: {} }; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similar to https://github.com/elastic/kibana/pull/170810/files#r1393019545, since the Link embeddable can now be edited outside of the Dashboard app, it is no longer considered invalid for a Link embeddable to not have a parent. Note that this early return was actually unnecessary in the first place, because we already treat the parent as potentially undefined in the rest of the code - so, it's safe to remove. |
||
|
||
const { openEditorFlyout } = await import('../editor/open_editor_flyout'); | ||
|
||
const { newInput, attributes } = await openEditorFlyout( | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we are relying on the embeddable factory
create
method for the link embeddable, we need to hide the visualization alias item from the dropdown.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good workaround. I'm thinking that as part of the Embeddable refactor, we should introduce a separate registry for creation buttons in the Dashboard top nav. That would make this more explicit and unified.