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.x] Fix share modal copy embed code (#204584) #204623

Merged
merged 1 commit into from
Dec 17, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,7 @@ describe('Share modal embed content tab', () => {

beforeEach(() => {
component = mountWithIntl(
<EmbedContent
isDirty={false}
objectType="dashboard"
setIsNotSaved={() => jest.fn()}
shareableUrl="/home#/"
/>
<EmbedContent isDirty={false} objectType="dashboard" shareableUrl="/home#/" />
);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ type EmbedProps = Pick<
| 'objectType'
| 'isDirty'
> & {
setIsNotSaved: () => void;
objectConfig?: ShareContextObjectTypeConfig;
};

Expand All @@ -55,7 +54,6 @@ export const EmbedContent = ({
shareableUrl,
objectType,
objectConfig = {},
setIsNotSaved,
isDirty,
}: EmbedProps) => {
const isMounted = useMountedState();
Expand All @@ -67,10 +65,6 @@ export const EmbedContent = ({
const [anonymousAccessParameters] = useState<AnonymousAccessState['accessURLParameters']>(null);
const [usePublicUrl] = useState<boolean>(false);

useEffect(() => {
if (objectType !== 'dashboard') setIsNotSaved();
}, [url, setIsNotSaved, objectType]);

const makeUrlEmbeddable = useCallback((tempUrl: string): string => {
const embedParam = '?embed=true';
const urlHasQueryString = tempUrl.indexOf('?') !== -1;
Expand Down
34 changes: 1 addition & 33 deletions src/plugins/share/public/components/tabs/embed/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,35 +8,13 @@
*/

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<IEmbedTab['content']> = ({ state, dispatch }) => {
const {
embedUrlParamExtensions,
Expand All @@ -47,13 +25,6 @@ const EmbedTabContent: NonNullable<IEmbedTab['content']> = ({ state, dispatch })
isDirty,
} = useShareTabsContext()!;

const setIsNotSaved = useCallback(() => {
dispatch({
type: EMBED_TAB_ACTIONS.SET_IS_NOT_SAVED,
payload: objectType === 'dashboard' ? isDirty : false,
});
}, [dispatch, objectType, isDirty]);

return (
<EmbedContent
{...{
Expand All @@ -62,8 +33,6 @@ const EmbedTabContent: NonNullable<IEmbedTab['content']> = ({ state, dispatch })
shareableUrl,
objectType,
objectConfig: objectTypeMeta?.config?.embed,
isNotSaved: state?.isNotSaved,
setIsNotSaved,
isDirty,
}}
/>
Expand All @@ -75,6 +44,5 @@ export const embedTab: IEmbedTab = {
name: i18n.translate('share.contextMenu.embedCodeTab', {
defaultMessage: 'Embed',
}),
reducer: embedTabReducer,
content: EmbedTabContent,
};
Loading