-
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
[Dashboard][Lens] Add "convert to lens" action to dashboard #146363
Merged
VladLasitsa
merged 24 commits into
elastic:main
from
VladLasitsa:convert_to_lens_for_dashboard
Dec 13, 2022
Merged
Changes from 7 commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
7df2590
Add "convert to lens" action to dashboard
VladLasitsa 1b00b5e
Fix CI
VladLasitsa 0fca07e
Fix more tests
VladLasitsa f78d79b
Fix test
VladLasitsa 8676538
Some improvments
VladLasitsa fe7c5cd
Add functional tests
VladLasitsa efe7d80
Merge branch 'main' into convert_to_lens_for_dashboard
kibanamachine a2397db
Merge branch 'main' into convert_to_lens_for_dashboard
stratoula 15d3380
Fix notification
VladLasitsa 2e22b1e
Fix some comments
VladLasitsa c7fdc8e
[CI] Auto-commit changed files from 'node scripts/precommit_hook.js -…
kibanamachine b6f99e8
Fix some more nits
VladLasitsa 8a74239
Merge remote-tracking branch 'origin/convert_to_lens_for_dashboard' i…
VladLasitsa 0a6c890
Fix some tests
VladLasitsa cf4ac72
Merge branch 'main' into convert_to_lens_for_dashboard
kibanamachine 91020f0
Fix some new comments
VladLasitsa 54161f8
Some fixes
VladLasitsa a5447b4
Fix mocks
VladLasitsa 135b36d
Merge branch 'main' into convert_to_lens_for_dashboard
kibanamachine 1489189
Merge branch 'main' into convert_to_lens_for_dashboard
kibanamachine 9b35aa5
Fix small nits
VladLasitsa ed576bd
Merge remote-tracking branch 'upstream/main' into convert_to_lens_for…
VladLasitsa 1d260b1
fix test
VladLasitsa 705101f
Get correct title for replace action
VladLasitsa File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
125 changes: 125 additions & 0 deletions
125
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,125 @@ | ||
/* | ||
* 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 { 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 } 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 = 30; | ||
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 searchFilters = vis.data.searchSource?.getField('filter'); | ||
const searchQuery = vis.data.searchSource?.getField('query'); | ||
const updatedWithMeta = { | ||
...navigateToLensConfig, | ||
title: | ||
embeddable.getOutput().title || | ||
i18n.translate('visualizations.actions.editInLens.visulizationTitle', { | ||
defaultMessage: '{type} visualization', | ||
values: { | ||
type: vis.type.title, | ||
}, | ||
}), | ||
savedObjectId: vis.id, | ||
embeddableId: embeddable.id, | ||
originatingApp: this.currentAppId, | ||
searchFilters, | ||
searchQuery, | ||
}; | ||
if (navigateToLensConfig) { | ||
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
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Would it be better to use an
EuiIcon
component with thedot
glyph, rather than a pseudo element with a bullet symbol?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.
@MichaelMarcialis, Adding EuiIcon anyway will require styles for correct position. For me in that case using pseudo element is good solution. Could you please describe a reason why is better adding new element instead of using pseudo element?
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.
The only reason I asked was for the sake of consistency with other areas of Kibana that use the
dot
icon. That consistency would really only be in regard to size in this case, since the icon is a simple circle. That said, it's not a huge deal either way. If positioning anEuiIcon
instead of a pseudo element is more complex, I'm OK keeping as you have it.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.
@MichaelMarcialis, Could you please tell me where we have the same dot-notification idea in kibana?
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.
I believe this is the first use of a
dot
icon to draw attention to a menu button in Kibana, but we do utilize thedot
icon in a variety of other across Kibana as a means to visually offset or grab attention from users. Some that immediately jump to mind are 1) for indicating change/dirty state when making edits on some pages (like user profiles) and 2) for indicating incompatibility of quick functions in Lens.