Skip to content
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

[8.11] [Dashboard Navigation] Fix reference extract method (#171360) #171561

Merged
merged 1 commit into from
Nov 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions src/plugins/links/common/persistable_state/references.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*/

import { Reference } from '@kbn/content-management-utils';
import { omit } from 'lodash';
import { DASHBOARD_LINK_TYPE, LinksAttributes } from '../content_management';

export function extractReferences({
Expand All @@ -22,23 +23,24 @@ export function extractReferences({

const { links } = attributes;
const extractedReferences: Reference[] = [];
links.forEach((link) => {

const newLinks = links.map((link) => {
if (link.type === DASHBOARD_LINK_TYPE && link.destination) {
const refName = `link_${link.id}_dashboard`;
link.destinationRefName = refName;
extractedReferences.push({
name: refName,
type: 'dashboard',
id: link.destination,
});
delete link.destination;
return { ...omit(link, 'destination'), destinationRefName: refName };
}
return link;
});

return {
attributes: {
...attributes,
links,
links: newLinks,
},
references: references.concat(extractedReferences),
};
Expand Down
39 changes: 27 additions & 12 deletions test/functional/apps/dashboard_elements/links/links_create_edit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,18 +78,33 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
await dashboard.clickDiscardChanges();
});

it('can create a new by-value links panel', async () => {
await dashboardAddPanel.clickEditorMenuButton();
await dashboardAddPanel.clickAddNewEmbeddableLink('links');
await dashboardLinks.setLayout('horizontal');
await createSomeLinks();
await dashboardLinks.toggleSaveByReference(false);
await dashboardLinks.clickPanelEditorSaveButton();
await testSubjects.exists('addObjectToDashboardSuccess');

expect(await testSubjects.existOrFail('links--component'));
expect(await dashboardLinks.getNumberOfLinksInPanel()).to.equal(4);
await dashboard.clickDiscardChanges();
describe('by-value links panel', async () => {
it('can create a new by-value links panel', async () => {
await dashboardAddPanel.clickEditorMenuButton();
await dashboardAddPanel.clickAddNewEmbeddableLink('links');
await dashboardLinks.setLayout('horizontal');
await createSomeLinks();
await dashboardLinks.toggleSaveByReference(false);
await dashboardLinks.clickPanelEditorSaveButton();
await testSubjects.exists('addObjectToDashboardSuccess');

expect(await testSubjects.existOrFail('links--component'));
expect(await dashboardLinks.getNumberOfLinksInPanel()).to.equal(4);
});

it('can save by-value links panel to the library', async () => {
/** Navigate away to test non-extensible input */
await dashboard.gotoDashboardLandingPage();
await dashboard.clickUnsavedChangesContinueEditing(DASHBOARD_NAME);

await dashboard.waitForRenderComplete();
await dashboardPanelActions.saveToLibrary('Some more links');
await testSubjects.existOrFail('addPanelToLibrarySuccess');
});

after(async () => {
await dashboard.clickDiscardChanges();
});
});
});

Expand Down
Loading