From 3919433e2103ff1a450ef9d391e7d5da3a9c34d4 Mon Sep 17 00:00:00 2001 From: "Eyo O. Eyo" <7893459+eokoneyo@users.noreply.github.com> Date: Thu, 19 Dec 2024 12:48:35 +0000 Subject: [PATCH] [8.16] Fix share modal copy embed code (#204584) (#204705) # Backport This will backport the following commits from `main` to `8.16`: - [Fix share modal copy embed code (#204584)](https://github.com/elastic/kibana/pull/204584) ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) ","sha":"effd84dc41c702b0a82631ee5777fed7f14dfb61","branchLabelMapping":{"^v9.0.0$":"main","^v8.18.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","v9.0.0","Team:SharedUX","backport:prev-major","v8.18.0"],"number":204584,"url":"https://github.com/elastic/kibana/pull/204584","mergeCommit":{"message":"Fix share modal copy embed code (#204584)\n\n## Summary\r\n\r\nCloses https://github.com/elastic/kibana/issues/204312\r\n\r\nThis PR removes an unnecessary function, that causes an infinite render\r\nloop for visualisations.\r\n\r\n\r\n## After\r\n\r\n\r\nhttps://github.com/user-attachments/assets/259d238b-c1cf-4d74-bfca-1a6440d0f5cd\r\n\r\n## How to test\r\n- From the left side nav, click the `Visualize Library` menu item,\r\nattempt to create a legacy visualisation, any one of choice and attempt\r\nsharing said created visualisation clicking the copy embed code should\r\nnot result in any error but rather copy the embed code with the visual\r\nfeedback.\r\n\r\n","sha":"effd84dc41c702b0a82631ee5777fed7f14dfb61"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","labelRegex":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/204584","number":204584,"mergeCommit":{"message":"Fix share modal copy embed code (#204584)\n\n## Summary\r\n\r\nCloses https://github.com/elastic/kibana/issues/204312\r\n\r\nThis PR removes an unnecessary function, that causes an infinite render\r\nloop for visualisations.\r\n\r\n\r\n## After\r\n\r\n\r\nhttps://github.com/user-attachments/assets/259d238b-c1cf-4d74-bfca-1a6440d0f5cd\r\n\r\n## How to test\r\n- From the left side nav, click the `Visualize Library` menu item,\r\nattempt to create a legacy visualisation, any one of choice and attempt\r\nsharing said created visualisation clicking the copy embed code should\r\nnot result in any error but rather copy the embed code with the visual\r\nfeedback.\r\n\r\n","sha":"effd84dc41c702b0a82631ee5777fed7f14dfb61"}},{"branch":"8.x","label":"v8.18.0","labelRegex":"^v8.18.0$","isSourceBranch":false,"url":"https://github.com/elastic/kibana/pull/204623","number":204623,"state":"MERGED","mergeCommit":{"sha":"f77fc58383202e136095d7a6ab011b95bd53b540","message":"[8.x] Fix share modal copy embed code (#204584) (#204623)\n\n# Backport\r\n\r\nThis will backport the following commits from `main` to `8.x`:\r\n- [Fix share modal copy embed code\r\n(#204584)](https://github.com/elastic/kibana/pull/204584)\r\n\r\n\r\n\r\n### Questions ?\r\nPlease refer to the [Backport tool\r\ndocumentation](https://github.com/sqren/backport)\r\n\r\n\",\"sha\":\"effd84dc41c702b0a82631ee5777fed7f14dfb61\",\"branchLabelMapping\":{\"^v9.0.0$\":\"main\",\"^v8.18.0$\":\"8.x\",\"^v(\\\\d+).(\\\\d+).\\\\d+$\":\"$1.$2\"}},\"sourcePullRequest\":{\"labels\":[\"release_note:skip\",\"v9.0.0\",\"Team:SharedUX\",\"backport:prev-major\"],\"title\":\"Fix\r\nshare modal copy embed\r\ncode\",\"number\":204584,\"url\":\"https://github.com/elastic/kibana/pull/204584\",\"mergeCommit\":{\"message\":\"Fix\r\nshare modal copy embed code (#204584)\\n\\n## Summary\\r\\n\\r\\nCloses\r\nhttps://github.com/elastic/kibana/issues/204312\\r\\n\\r\\nThis PR removes\r\nan unnecessary function, that causes an infinite render\\r\\nloop for\r\nvisualisations.\\r\\n\\r\\n\\r\\n##\r\nAfter\\r\\n\\r\\n\\r\\nhttps://github.com/user-attachments/assets/259d238b-c1cf-4d74-bfca-1a6440d0f5cd\\r\\n\\r\\n##\r\nHow to test\\r\\n- From the left side nav, click the `Visualize Library`\r\nmenu item,\\r\\nattempt to create a legacy visualisation, any one of\r\nchoice and attempt\\r\\nsharing said created visualisation clicking the\r\ncopy embed code should\\r\\nnot result in any error but rather copy the\r\nembed code with the visual\\r\\nfeedback.\\r\\n\\r\\n\",\"sha\":\"effd84dc41c702b0a82631ee5777fed7f14dfb61\"}},\"sourceBranch\":\"main\",\"suggestedTargetBranches\":[],\"targetPullRequestStates\":[{\"branch\":\"main\",\"label\":\"v9.0.0\",\"branchLabelMappingKey\":\"^v9.0.0$\",\"isSourceBranch\":true,\"state\":\"MERGED\",\"url\":\"https://github.com/elastic/kibana/pull/204584\",\"number\":204584,\"mergeCommit\":{\"message\":\"Fix\r\nshare modal copy embed code (#204584)\\n\\n## Summary\\r\\n\\r\\nCloses\r\nhttps://github.com/elastic/kibana/issues/204312\\r\\n\\r\\nThis PR removes\r\nan unnecessary function, that causes an infinite render\\r\\nloop for\r\nvisualisations.\\r\\n\\r\\n\\r\\n##\r\nAfter\\r\\n\\r\\n\\r\\nhttps://github.com/user-attachments/assets/259d238b-c1cf-4d74-bfca-1a6440d0f5cd\\r\\n\\r\\n##\r\nHow to test\\r\\n- From the left side nav, click the `Visualize Library`\r\nmenu item,\\r\\nattempt to create a legacy visualisation, any one of\r\nchoice and attempt\\r\\nsharing said created visualisation clicking the\r\ncopy embed code should\\r\\nnot result in any error but rather copy the\r\nembed code with the visual\\r\\nfeedback.\\r\\n\\r\\n\",\"sha\":\"effd84dc41c702b0a82631ee5777fed7f14dfb61\"}}]}]\r\nBACKPORT-->\r\n\r\nCo-authored-by: Eyo O. Eyo <7893459+eokoneyo@users.noreply.github.com>"}},{"url":"https://github.com/elastic/kibana/pull/204622","number":204622,"branch":"8.17","state":"OPEN"}]}] BACKPORT--> --------- Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com> --- .../tabs/embed/embed_content.test.tsx | 8 +---- .../components/tabs/embed/embed_content.tsx | 9 +---- .../public/components/tabs/embed/index.tsx | 36 ++----------------- 3 files changed, 4 insertions(+), 49 deletions(-) diff --git a/src/plugins/share/public/components/tabs/embed/embed_content.test.tsx b/src/plugins/share/public/components/tabs/embed/embed_content.test.tsx index be3d8c941b8ea..ee4a67bed4c81 100644 --- a/src/plugins/share/public/components/tabs/embed/embed_content.test.tsx +++ b/src/plugins/share/public/components/tabs/embed/embed_content.test.tsx @@ -17,13 +17,7 @@ describe('Share modal embed content tab', () => { let component: ReactWrapper; beforeEach(() => { - component = mountWithIntl( - jest.fn()} - shareableUrl="/home#/" - /> - ); + component = mountWithIntl(); }); it('works for simple url', async () => { diff --git a/src/plugins/share/public/components/tabs/embed/embed_content.tsx b/src/plugins/share/public/components/tabs/embed/embed_content.tsx index 557a499a38021..e26705cbd305b 100644 --- a/src/plugins/share/public/components/tabs/embed/embed_content.tsx +++ b/src/plugins/share/public/components/tabs/embed/embed_content.tsx @@ -32,9 +32,7 @@ type EmbedProps = Pick< | 'shareableUrl' | 'embedUrlParamExtensions' | 'objectType' -> & { - setIsNotSaved: () => void; -}; +>; interface UrlParams { [extensionName: string]: { @@ -52,7 +50,6 @@ export const EmbedContent = ({ shareableUrlForSavedObject, shareableUrl, objectType, - setIsNotSaved, }: EmbedProps) => { const isMounted = useMountedState(); const [urlParams, setUrlParams] = useState(undefined); @@ -63,10 +60,6 @@ export const EmbedContent = ({ const [anonymousAccessParameters] = useState(null); const [usePublicUrl] = useState(false); - useEffect(() => { - if (objectType !== 'dashboard') setIsNotSaved(); - }, [url, setIsNotSaved, objectType]); - const makeUrlEmbeddable = useCallback((tempUrl: string): string => { const embedParam = '?embed=true'; const urlHasQueryString = tempUrl.indexOf('?') !== -1; diff --git a/src/plugins/share/public/components/tabs/embed/index.tsx b/src/plugins/share/public/components/tabs/embed/index.tsx index 3c66b48f21c8c..fb7ce7bfae7bf 100644 --- a/src/plugins/share/public/components/tabs/embed/index.tsx +++ b/src/plugins/share/public/components/tabs/embed/index.tsx @@ -8,46 +8,17 @@ */ import { i18n } from '@kbn/i18n'; -import React, { useCallback } from 'react'; +import React from 'react'; import { type IModalTabDeclaration } from '@kbn/shared-ux-tabbed-modal'; import { EmbedContent } from './embed_content'; import { useShareTabsContext } from '../../context'; -const EMBED_TAB_ACTIONS = { - SET_EMBED_URL: 'SET_EMBED_URL', - SET_IS_NOT_SAVED: 'SET_IS_NOT_SAVED', -}; - type IEmbedTab = IModalTabDeclaration<{ url: string; isNotSaved: boolean }>; -const embedTabReducer: IEmbedTab['reducer'] = (state = { url: '', isNotSaved: false }, action) => { - switch (action.type) { - case EMBED_TAB_ACTIONS.SET_IS_NOT_SAVED: - return { - ...state, - isNotSaved: action.payload, - }; - case EMBED_TAB_ACTIONS.SET_IS_NOT_SAVED: - return { - ...state, - isNotSaved: action.payload, - }; - default: - return state; - } -}; - const EmbedTabContent: NonNullable = ({ state, dispatch }) => { - const { embedUrlParamExtensions, shareableUrlForSavedObject, shareableUrl, objectType, isDirty } = + const { embedUrlParamExtensions, shareableUrlForSavedObject, shareableUrl, objectType } = useShareTabsContext()!; - const setIsNotSaved = useCallback(() => { - dispatch({ - type: EMBED_TAB_ACTIONS.SET_IS_NOT_SAVED, - payload: objectType === 'dashboard' ? isDirty : false, - }); - }, [dispatch, objectType, isDirty]); - return ( = ({ state, dispatch }) shareableUrlForSavedObject, shareableUrl, objectType, - isNotSaved: state?.isNotSaved, - setIsNotSaved, }} /> ); @@ -67,6 +36,5 @@ export const embedTab: IEmbedTab = { name: i18n.translate('share.contextMenu.embedCodeTab', { defaultMessage: 'Embed', }), - reducer: embedTabReducer, content: EmbedTabContent, };