-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Dashboard][Lens] Add "convert to lens" action to dashboard (#146363)
## Summary Closes #147032 Completes part of: #144605 Added `convert to lens` action for panel in dashboards. If legacy visualization can be converted, the notification 'dot' will shown on context menu. <img width="828" alt="Снимок экрана 2022-12-02 в 10 50 58" src="https://user-images.githubusercontent.com/16915480/205253599-3f3f102e-8fdc-497c-9e81-a9e1a146687c.png"> New action looks like this: <img width="781" alt="Снимок экрана 2022-12-02 в 10 52 42" src="https://user-images.githubusercontent.com/16915480/205253909-79d65fd8-81d8-4cce-a61a-234d3996cf84.png"> After clicking by that action user will be navigate to lens page and see the following, where user can replace legacy visualization to lens on dashboard: <img width="1347" alt="Снимок экрана 2022-12-02 в 10 53 23" src="https://user-images.githubusercontent.com/16915480/205254013-6e26b54d-6b92-4da5-be64-01b2876ea847.png"> On save user also can replace panel on dashboard: <img width="506" alt="Снимок экрана 2022-12-02 в 10 55 22" src="https://user-images.githubusercontent.com/16915480/205254409-163ebf51-c075-4c9a-a070-cebc7001636d.png"> Co-authored-by: Kibana Machine <[email protected]> Co-authored-by: Stratoula Kalafateli <[email protected]>
- Loading branch information
1 parent
0aa6e1c
commit a068b2e
Showing
42 changed files
with
694 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
129 changes: 129 additions & 0 deletions
129
src/plugins/visualizations/public/actions/edit_in_lens_action.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import React from 'react'; | ||
import { take } from 'rxjs/operators'; | ||
import { EuiFlexGroup, EuiFlexItem, EuiBadge } from '@elastic/eui'; | ||
import { METRIC_TYPE } from '@kbn/analytics'; | ||
import { reactToUiComponent } from '@kbn/kibana-react-plugin/public'; | ||
import { ActionExecutionContext } from '@kbn/ui-actions-plugin/public'; | ||
import { TimefilterContract } from '@kbn/data-plugin/public'; | ||
import { i18n } from '@kbn/i18n'; | ||
import { IEmbeddable, ViewMode } from '@kbn/embeddable-plugin/public'; | ||
import { Action } from '@kbn/ui-actions-plugin/public'; | ||
import { VisualizeEmbeddable } from '../embeddable'; | ||
import { DASHBOARD_VISUALIZATION_PANEL_TRIGGER } from '../triggers'; | ||
import { getUiActions, getApplication, getEmbeddable, getUsageCollection } from '../services'; | ||
|
||
export const ACTION_EDIT_IN_LENS = 'ACTION_EDIT_IN_LENS'; | ||
|
||
export interface EditInLensContext { | ||
embeddable: IEmbeddable; | ||
} | ||
|
||
const displayName = i18n.translate('visualizations.actions.editInLens.displayName', { | ||
defaultMessage: 'Convert to Lens', | ||
}); | ||
|
||
const ReactMenuItem: React.FC = () => { | ||
return ( | ||
<EuiFlexGroup alignItems="center"> | ||
<EuiFlexItem>{displayName}</EuiFlexItem> | ||
<EuiFlexItem grow={false}> | ||
<EuiBadge color={'accent'}> | ||
{i18n.translate('visualizations.tonNavMenu.tryItBadgeText', { | ||
defaultMessage: 'Try it', | ||
})} | ||
</EuiBadge> | ||
</EuiFlexItem> | ||
</EuiFlexGroup> | ||
); | ||
}; | ||
|
||
const UiMenuItem = reactToUiComponent(ReactMenuItem); | ||
|
||
const isVisualizeEmbeddable = (embeddable: IEmbeddable): embeddable is VisualizeEmbeddable => { | ||
return 'getVis' in embeddable; | ||
}; | ||
|
||
export class EditInLensAction implements Action<EditInLensContext> { | ||
public id = ACTION_EDIT_IN_LENS; | ||
public readonly type = ACTION_EDIT_IN_LENS; | ||
public order = 49; | ||
public showNotification = true; | ||
public currentAppId: string | undefined; | ||
|
||
constructor(private readonly timefilter: TimefilterContract) {} | ||
|
||
async execute(context: ActionExecutionContext<EditInLensContext>): Promise<void> { | ||
const application = getApplication(); | ||
if (application?.currentAppId$) { | ||
application.currentAppId$ | ||
.pipe(take(1)) | ||
.subscribe((appId: string | undefined) => (this.currentAppId = appId)); | ||
application.currentAppId$.subscribe(() => { | ||
getEmbeddable().getStateTransfer().isTransferInProgress = false; | ||
}); | ||
} | ||
const { embeddable } = context; | ||
if (isVisualizeEmbeddable(embeddable)) { | ||
const vis = embeddable.getVis(); | ||
const navigateToLensConfig = await vis.type.navigateToLens?.(vis, this.timefilter); | ||
const parentSearchSource = vis.data.searchSource?.getParent(); | ||
const searchFilters = parentSearchSource?.getField('filter'); | ||
const searchQuery = parentSearchSource?.getField('query'); | ||
const title = vis.title || embeddable.getOutput().title; | ||
const updatedWithMeta = { | ||
...navigateToLensConfig, | ||
title, | ||
visTypeTitle: vis.type.title, | ||
embeddableId: embeddable.id, | ||
originatingApp: this.currentAppId, | ||
searchFilters, | ||
searchQuery, | ||
isEmbeddable: true, | ||
}; | ||
if (navigateToLensConfig) { | ||
if (this.currentAppId) { | ||
getUsageCollection().reportUiCounter( | ||
this.currentAppId, | ||
METRIC_TYPE.CLICK, | ||
ACTION_EDIT_IN_LENS | ||
); | ||
} | ||
getEmbeddable().getStateTransfer().isTransferInProgress = true; | ||
getUiActions().getTrigger(DASHBOARD_VISUALIZATION_PANEL_TRIGGER).exec(updatedWithMeta); | ||
} | ||
} | ||
} | ||
|
||
getDisplayName(context: ActionExecutionContext<EditInLensContext>): string { | ||
return displayName; | ||
} | ||
|
||
MenuItem = UiMenuItem; | ||
|
||
getIconType(context: ActionExecutionContext<EditInLensContext>): string | undefined { | ||
return 'merge'; | ||
} | ||
|
||
async isCompatible(context: ActionExecutionContext<EditInLensContext>) { | ||
const { embeddable } = context; | ||
if (!isVisualizeEmbeddable(embeddable)) { | ||
return false; | ||
} | ||
const vis = embeddable.getVis(); | ||
if (!vis) { | ||
return false; | ||
} | ||
const canNavigateToLens = | ||
embeddable.getExpressionVariables?.()?.canNavigateToLens ?? | ||
(await vis.type.navigateToLens?.(vis, this.timefilter)); | ||
return Boolean(canNavigateToLens && embeddable.getInput().viewMode === ViewMode.EDIT); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.