-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
[Lens][Dashboard] Adding Lens to Dashboard #53110
Changes from 18 commits
283ca5b
1842088
57bef33
75a3d26
449d5f4
e50a051
3411d59
a316315
452b4dc
494b855
12c3142
3a39424
d28733e
e44ce7a
e335b91
1bfec16
bbfcc34
8022cea
64e6ceb
fe9ab85
25010ff
f78bdc7
9e15430
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 |
---|---|---|
|
@@ -14,8 +14,8 @@ import 'uiExports/visResponseHandlers'; | |
import 'uiExports/savedObjectTypes'; | ||
|
||
import React from 'react'; | ||
import { I18nProvider, FormattedMessage } from '@kbn/i18n/react'; | ||
import { HashRouter, Switch, Route, RouteComponentProps } from 'react-router-dom'; | ||
import { FormattedMessage, I18nProvider } from '@kbn/i18n/react'; | ||
import { HashRouter, Route, RouteComponentProps, Switch } from 'react-router-dom'; | ||
import { render, unmountComponentAtNode } from 'react-dom'; | ||
import { CoreSetup, CoreStart, SavedObjectsClientContract } from 'src/core/public'; | ||
import { DataPublicPluginStart } from 'src/plugins/data/public'; | ||
|
@@ -41,6 +41,11 @@ import { | |
import { NOT_INTERNATIONALIZED_PRODUCT_NAME } from '../../common'; | ||
import { KibanaLegacySetup } from '../../../../../../src/plugins/kibana_legacy/public'; | ||
import { EditorFrameStart } from '../types'; | ||
import { | ||
getKibanaBasePathFromDashboardUrl, | ||
addEmbeddableToDashboardUrl, | ||
getDashboardUrlWithoutTime, | ||
} from './url_helper'; | ||
|
||
export interface LensPluginSetupDependencies { | ||
kibana_legacy: KibanaLegacySetup; | ||
|
@@ -94,8 +99,44 @@ export class AppPlugin { | |
}) | ||
); | ||
|
||
const redirectTo = ( | ||
routeProps: RouteComponentProps<{ id?: string }>, | ||
addToDashboardMode: boolean, | ||
id?: string | ||
) => { | ||
if (!id) { | ||
routeProps.history.push('/lens'); | ||
} else if (!addToDashboardMode) { | ||
routeProps.history.push(`/lens/edit/${id}`); | ||
} else if (addToDashboardMode && id) { | ||
routeProps.history.push(`/lens/edit/${id}`); | ||
const url = context.core.chrome.navLinks.get('kibana:dashboard'); | ||
if (!url) { | ||
return; | ||
} | ||
const lastDashboardAbsoluteUrl = url.url; | ||
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. This also seems like a bunch of detail that belongs to the dashboard module, not to Lens. Maybe something like this: const url = dashboardUrl.addEmbeddable(url.url, id, 'lens');
if (url) {
window.history.pushState({}, '', url);
} 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. This was the original intention, but then we figured the time range is not properly set. So for the hack with setting timerange to work, this won't be so clean. |
||
const lensUrl = `${getKibanaBasePathFromDashboardUrl( | ||
lastDashboardAbsoluteUrl | ||
)}/lens/edit/${id}`; | ||
const dashboardUrlWithoutTime = getDashboardUrlWithoutTime(lastDashboardAbsoluteUrl); | ||
if (lensUrl && dashboardUrlWithoutTime) { | ||
window.history.pushState({}, '', lensUrl); | ||
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. I think we generally avoid using pushState directly, and instead use a core service to do this, but I'm not sure. Might be worth looking into, anyway. 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. I don't think it exists in the new platform. I think the |
||
const dashboardParsedUrl = addEmbeddableToDashboardUrl( | ||
dashboardUrlWithoutTime, | ||
id, | ||
'lens' | ||
); | ||
if (dashboardParsedUrl) { | ||
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. If this returns null, we silently fail. Is that the right thing? It seems like a null here is a legit error that should be surfaced in some way. |
||
window.history.pushState({}, '', dashboardParsedUrl); | ||
} | ||
} | ||
} | ||
}; | ||
|
||
const renderEditor = (routeProps: RouteComponentProps<{ id?: string }>) => { | ||
trackUiEvent('loaded'); | ||
const addToDashboardMode = | ||
!!routeProps.location.search && routeProps.location.search.includes('addToDashboard'); | ||
return ( | ||
<App | ||
core={context.core} | ||
|
@@ -104,13 +145,8 @@ export class AppPlugin { | |
storage={new Storage(localStorage)} | ||
docId={routeProps.match.params.id} | ||
docStorage={new SavedObjectIndexStore(savedObjectsClient)} | ||
redirectTo={id => { | ||
if (!id) { | ||
routeProps.history.push('/lens'); | ||
} else { | ||
routeProps.history.push(`/lens/edit/${id}`); | ||
} | ||
}} | ||
redirectTo={id => redirectTo(routeProps, addToDashboardMode, id)} | ||
addToDashboardMode={addToDashboardMode} | ||
/> | ||
); | ||
}; | ||
|
@@ -119,6 +155,7 @@ export class AppPlugin { | |
trackUiEvent('loaded_404'); | ||
return <FormattedMessage id="xpack.lens.app404" defaultMessage="404 Not Found" />; | ||
} | ||
|
||
render( | ||
<I18nProvider> | ||
<HashRouter> | ||
|
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.
This is adding more dependencies on
context
, which is being deprecated. Is there a better way to do this?