From fdd5a341546451bac1aaf1e890e2fab9a517d9e0 Mon Sep 17 00:00:00 2001 From: "Eyo O. Eyo" <7893459+eokoneyo@users.noreply.github.com> Date: Tue, 17 Dec 2024 17:13:02 +0000 Subject: [PATCH] Fix share modal copy embed code (#204584) Closes https://github.com/elastic/kibana/issues/204312 This PR removes an unnecessary function, that causes an infinite render loop for visualisations. https://github.com/user-attachments/assets/259d238b-c1cf-4d74-bfca-1a6440d0f5cd - From the left side nav, click the `Visualize Library` menu item, attempt to create a legacy visualisation, any one of choice and attempt sharing said created visualisation clicking the copy embed code should not result in any error but rather copy the embed code with the visual feedback. (cherry picked from commit effd84dc41c702b0a82631ee5777fed7f14dfb61) --- .../tabs/embed/embed_content.test.tsx | 1 - .../components/tabs/embed/embed_content.tsx | 9 +---- .../public/components/tabs/embed/index.tsx | 36 ++----------------- 3 files changed, 3 insertions(+), 43 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..7315d37314947 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 @@ -20,7 +20,6 @@ describe('Share modal embed content tab', () => { component = mountWithIntl( jest.fn()} shareableUrl="/home#/" /> ); 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, };