Skip to content

Commit

Permalink
[8.11] [Dashboard Navigation] Fix reference extract method (elastic#1…
Browse files Browse the repository at this point in the history
…71360) (elastic#171561)

# Backport

This will backport the following commits from `main` to `8.11`:
- [[Dashboard Navigation] Fix reference extract method
(elastic#171360)](elastic#171360)

<!--- Backport version: 8.9.7 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Hannah
Mudge","email":"[email protected]"},"sourceCommit":{"committedDate":"2023-11-20T16:40:07Z","message":"[Dashboard
Navigation] Fix reference extract method (elastic#171360)\n\nCloses
https://github.com/elastic/kibana/issues/164212\r\nCloses
https://github.com/elastic/kibana/issues/171328\r\n\r\n##
Summary\r\n\r\nIn `extractReferences`, the links in the `links` array
attribute is
[not\r\nextensible](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Errors/Cant_define_property_object_not_extensible)\r\n-
this means that we cannot add or delete properties from
each\r\nindividual link directly. Instead, I've had to create a clone of
each\r\ndashboard link via the spread operator so that we aren't
modifying the\r\noriginal link directly.\r\n\r\n**How to Test**\r\n1.
Create a by-value Links panel\r\n2. Refresh the dashboard\r\n3. Save the
Links panel to the library via the panel action\r\n4. The panel should
be saved successfully **and** the panel title should\r\nbe
updated.\r\n\r\n[**Flaky
Test\r\nRunner**](https://buildkite.com/elastic/kibana-flaky-test-suite-runner/builds/4024)\r\n\r\n\r\n![image](https://github.com/elastic/kibana/assets/8698078/b8949d44-697d-414a-9e98-14b0a6f67b31)\r\n\r\n###
Checklist\r\n\r\n- [x] [Unit or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common scenarios\r\n- [x] This was
checked for
[cross-browser\r\ncompatibility](https://www.elastic.co/support/matrix#matrix_browsers)\r\n\r\n###
For maintainers\r\n\r\n- [ ] This was checked for breaking API changes
and was
[labeled\r\nappropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)\r\n\r\n---------\r\n\r\nCo-authored-by:
kibanamachine
<[email protected]>","sha":"49b52fe76e480c24673c8e1573346fb279ea965f","branchLabelMapping":{"^v8.12.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["Feature:Dashboard","release_note:fix","Team:Presentation","loe:small","impact:high","backport:prev-minor","Project:Dashboard
Navigation","v8.12.0"],"number":171360,"url":"https://github.com/elastic/kibana/pull/171360","mergeCommit":{"message":"[Dashboard
Navigation] Fix reference extract method (elastic#171360)\n\nCloses
https://github.com/elastic/kibana/issues/164212\r\nCloses
https://github.com/elastic/kibana/issues/171328\r\n\r\n##
Summary\r\n\r\nIn `extractReferences`, the links in the `links` array
attribute is
[not\r\nextensible](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Errors/Cant_define_property_object_not_extensible)\r\n-
this means that we cannot add or delete properties from
each\r\nindividual link directly. Instead, I've had to create a clone of
each\r\ndashboard link via the spread operator so that we aren't
modifying the\r\noriginal link directly.\r\n\r\n**How to Test**\r\n1.
Create a by-value Links panel\r\n2. Refresh the dashboard\r\n3. Save the
Links panel to the library via the panel action\r\n4. The panel should
be saved successfully **and** the panel title should\r\nbe
updated.\r\n\r\n[**Flaky
Test\r\nRunner**](https://buildkite.com/elastic/kibana-flaky-test-suite-runner/builds/4024)\r\n\r\n\r\n![image](https://github.com/elastic/kibana/assets/8698078/b8949d44-697d-414a-9e98-14b0a6f67b31)\r\n\r\n###
Checklist\r\n\r\n- [x] [Unit or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common scenarios\r\n- [x] This was
checked for
[cross-browser\r\ncompatibility](https://www.elastic.co/support/matrix#matrix_browsers)\r\n\r\n###
For maintainers\r\n\r\n- [ ] This was checked for breaking API changes
and was
[labeled\r\nappropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)\r\n\r\n---------\r\n\r\nCo-authored-by:
kibanamachine
<[email protected]>","sha":"49b52fe76e480c24673c8e1573346fb279ea965f"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v8.12.0","labelRegex":"^v8.12.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/171360","number":171360,"mergeCommit":{"message":"[Dashboard
Navigation] Fix reference extract method (elastic#171360)\n\nCloses
https://github.com/elastic/kibana/issues/164212\r\nCloses
https://github.com/elastic/kibana/issues/171328\r\n\r\n##
Summary\r\n\r\nIn `extractReferences`, the links in the `links` array
attribute is
[not\r\nextensible](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Errors/Cant_define_property_object_not_extensible)\r\n-
this means that we cannot add or delete properties from
each\r\nindividual link directly. Instead, I've had to create a clone of
each\r\ndashboard link via the spread operator so that we aren't
modifying the\r\noriginal link directly.\r\n\r\n**How to Test**\r\n1.
Create a by-value Links panel\r\n2. Refresh the dashboard\r\n3. Save the
Links panel to the library via the panel action\r\n4. The panel should
be saved successfully **and** the panel title should\r\nbe
updated.\r\n\r\n[**Flaky
Test\r\nRunner**](https://buildkite.com/elastic/kibana-flaky-test-suite-runner/builds/4024)\r\n\r\n\r\n![image](https://github.com/elastic/kibana/assets/8698078/b8949d44-697d-414a-9e98-14b0a6f67b31)\r\n\r\n###
Checklist\r\n\r\n- [x] [Unit or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common scenarios\r\n- [x] This was
checked for
[cross-browser\r\ncompatibility](https://www.elastic.co/support/matrix#matrix_browsers)\r\n\r\n###
For maintainers\r\n\r\n- [ ] This was checked for breaking API changes
and was
[labeled\r\nappropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)\r\n\r\n---------\r\n\r\nCo-authored-by:
kibanamachine
<[email protected]>","sha":"49b52fe76e480c24673c8e1573346fb279ea965f"}}]}]
BACKPORT-->

Co-authored-by: Hannah Mudge <[email protected]>
  • Loading branch information
kibanamachine and Heenawter authored Nov 20, 2023
1 parent dbf0760 commit dc03884
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 16 deletions.
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

0 comments on commit dc03884

Please sign in to comment.