From dc645c92aafb48e16b2cb366557e734ce9310d2e Mon Sep 17 00:00:00 2001 From: Nathan Reese Date: Tue, 18 Feb 2025 09:17:42 -0700 Subject: [PATCH] [visualize] fix unsaved state when adding by-value visualize embeddable to dashboard (#211264) Follow up to https://github.com/elastic/kibana/pull/210125 [8.16](https://github.com/elastic/kibana/pull/211057) and [8.17](https://github.com/elastic/kibana/pull/211054) backports for https://github.com/elastic/kibana/pull/210125 were failing functional test https://github.com/elastic/kibana/blob/8.17/test/functional/apps/dashboard/group1/dashboard_unsaved_listing.ts#L142. The functional test adds a by-value and by-reference legacy visualization to a new dashboard. Upon saving the dashboard, the dashboard still showed unsaved changes. The reason this test did not fail main and other branches is that https://github.com/elastic/kibana/pull/208116 removed the "by-value" part of the test (since its no longer possible to add a by-value legacy visualization from within a dashboard). It is still possible to recreate the issue in main with the following steps 1) Click "Visualize Library" in left nav 2) Click "Create visualization" button. 3) Click "Legacy" tab 4) Click "Aggregation based" 5) Click "Area" 6) Click web logs sample data view 7) Click "Save" 8) Set title 9) Under "Add to dashboard", click "New", click save 10) save dashboard. Notice how dashboard still has unsaved changes. 8.16 and 8.17 required a [new commit](https://github.com/elastic/kibana/pull/211054/commits/1fd631c5a30046b5ab2f63948174ec29bac6fd84) to resolve the issue by updating the `linkedToLibrary` to ignore undefined values. This PR fixes the issue for the other branches that have already been merged. --------- Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com> Co-authored-by: Elastic Machine (cherry picked from commit 6789c946885fe0b6a2e57e056831f1ff25156f73) --- .../public/embeddable/visualize_embeddable.tsx | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/platform/plugins/shared/visualizations/public/embeddable/visualize_embeddable.tsx b/src/platform/plugins/shared/visualizations/public/embeddable/visualize_embeddable.tsx index 57c95cfc60700..e3f055ccd597a 100644 --- a/src/platform/plugins/shared/visualizations/public/embeddable/visualize_embeddable.tsx +++ b/src/platform/plugins/shared/visualizations/public/embeddable/visualize_embeddable.tsx @@ -308,7 +308,13 @@ export const getVisualizeEmbeddableFactory: (deps: { }, ], savedObjectProperties: getUnchangingComparator(), - linkedToLibrary: [linkedToLibrary$, (value) => linkedToLibrary$.next(value)], + linkedToLibrary: [ + linkedToLibrary$, + (value) => linkedToLibrary$.next(value), + (a, b) => { + return a === undefined || b === undefined ? true : a === b; + }, + ], } );