[TSVB][AggBased] Transfer panel title and description to the converted Lens panels (#154713)

## Summary

Closes https://github.com/elastic/kibana/issues/153913

There are 2 ways to convert a legacy visualizations to Lens
1. Go to the legacy editor and click the Visualize in Lens top nav
button
2. Open the panel menu on the dashboard level and click Convert to Lens

On the first case the panel title and description was not passed to the
converted panel
On the second case the panel title was passed but not the description

This PR fixes all the aforementioned scenarios


![2](https://user-images.githubusercontent.com/17003240/230878612-a0ace371-5f17-419e-bad0-37ea7e571c91.gif)

### Checklist
- [ ] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios

---------

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
Stratoula Kalafateli 2023-04-13 15:21:00 +03:00 committed by GitHub
parent 10f2015d17
commit 07a7e765f6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 22 additions and 6 deletions

View file

@ -87,6 +87,7 @@ export class EditInLensAction implements Action<EditInLensContext> {
searchFilters,
searchQuery,
isEmbeddable: true,
description: vis.description || embeddable.getOutput().description,
};
if (navigateToLensConfig) {
if (this.currentAppId) {

View file

@ -120,6 +120,8 @@ export interface VisInstance {
savedVis: VisSavedObject;
savedSearch?: SavedSearch;
embeddableHandler: VisualizeEmbeddableContract;
panelTitle?: string;
panelDescription?: string;
}
export type SavedVisInstance = VisInstance;

View file

@ -312,6 +312,10 @@ export const getTopNavConfig = (
embeddableId,
vizEditorOriginatingAppUrl: getVizEditorOriginatingAppUrl(history),
originatingApp,
title: visInstance?.panelTitle || vis.title,
visTypeTitle: vis.type.title,
description: visInstance?.panelDescription || vis.description,
isEmbeddable: Boolean(originatingApp),
};
if (navigateToLensConfig) {
hideLensBadge();

View file

@ -168,6 +168,8 @@ describe('getVisualizationInstanceInput', () => {
test('should create new instances of savedVis, vis and embeddableHandler', async () => {
const input = {
id: 'test-id',
description: 'description',
title: 'title',
savedVis: {
title: '',
description: '',
@ -194,7 +196,7 @@ describe('getVisualizationInstanceInput', () => {
},
},
} as unknown as VisualizeInput;
const { savedVis, savedSearch, vis, embeddableHandler } =
const { savedVis, savedSearch, vis, embeddableHandler, panelDescription, panelTitle } =
await getVisualizationInstanceFromInput(mockServices, input);
expect(getSavedVisualization).toHaveBeenCalled();
@ -212,5 +214,7 @@ describe('getVisualizationInstanceInput', () => {
expect(savedVis.uiStateJSON).toBe(JSON.stringify(input.savedVis?.uiState));
expect(embeddableHandler).toBeDefined();
expect(savedSearch).toBeUndefined();
expect(panelDescription).toBe('description');
expect(panelTitle).toBe('title');
});
});

View file

@ -119,6 +119,8 @@ export const getVisualizationInstanceFromInput = async (
savedVis,
embeddableHandler,
savedSearch,
panelTitle: input?.title ?? '',
panelDescription: input?.description ?? '',
};
};

View file

@ -646,9 +646,7 @@ export const LensTopNavMenu = ({
{
newTitle:
title ||
(initialContext &&
'isEmbeddable' in initialContext &&
initialContext.isEmbeddable
(contextFromEmbeddable
? i18n.translate('xpack.lens.app.convertedLabel', {
defaultMessage: '{title} (converted)',
values: {
@ -661,6 +659,7 @@ export const LensTopNavMenu = ({
newCopyOnSave: false,
isTitleDuplicateConfirmed: false,
returnToOrigin: true,
newDescription: contextFromEmbeddable ? initialContext.description : '',
},
{
saveToLibrary:

View file

@ -244,6 +244,7 @@ export type VisualizeEditorContext<T extends Configuration = Configuration> = {
searchQuery?: Query;
searchFilters?: Filter[];
title?: string;
description?: string;
visTypeTitle?: string;
isEmbeddable?: boolean;
} & NavigateToLensContext<T>;

View file

@ -57,6 +57,8 @@ export default function ({ getPageObjects, getService }: FtrProviderContext) {
const embeddableCount = await canvas.getEmbeddableCount();
expect(embeddableCount).to.eql(originalEmbeddableCount);
});
const titles = await dashboard.getPanelTitles();
expect(titles[0]).to.be('My TSVB to Lens viz 1 (converted)');
await panelActions.removePanel();
});
@ -85,13 +87,14 @@ export default function ({ getPageObjects, getService }: FtrProviderContext) {
const embeddableCount = await canvas.getEmbeddableCount();
expect(embeddableCount).to.eql(originalEmbeddableCount);
});
const panel = await testSubjects.find(`embeddablePanelHeading-`);
const panel = await testSubjects.find(`embeddablePanelHeading-MyTSVBtoLensviz2(converted)`);
const descendants = await testSubjects.findAllDescendant(
'embeddablePanelNotification-ACTION_LIBRARY_NOTIFICATION',
panel
);
expect(descendants.length).to.equal(0);
const titles = await dashboard.getPanelTitles();
expect(titles[0]).to.be('My TSVB to Lens viz 2 (converted)');
await panelActions.removePanel();
});