Skip to content

Commit

Permalink
Fix share modal copy embed code (elastic#204584)
Browse files Browse the repository at this point in the history
Closes elastic#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.

<!--

Check the PR satisfies following conditions.

Reviewers should verify this PR satisfies this list as well.

- [ ] Any text added follows [EUI's writing
guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses
sentence case text and includes [i18n
support](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md)
- [ ]
[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)
was added for features that require explanation or tutorials
- [ ] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios
- [ ] If a plugin configuration key changed, check if it needs to be
allowlisted in the cloud and added to the [docker
list](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker)
- [ ] This was checked for breaking HTTP API changes, and any breaking
changes have been approved by the breaking-change committee. The
`release_note:breaking` label should be applied in these situations.
- [ ] [Flaky Test
Runner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1) was
used on any tests changed
- [ ] The PR description includes the appropriate Release Notes section,
and the correct `release_note:*` label is applied per the
[guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)

Does this PR introduce any risks? For example, consider risks like hard
to test bugs, performance regression, potential of data loss.

Describe the risk, its severity, and mitigation for each identified
risk. Invite stakeholders and evaluate how to proceed before merging.

- [ ] [See some risk
examples](https://github.com/elastic/kibana/blob/main/RISK_MATRIX.mdx)
- [ ] ...

-->

(cherry picked from commit effd84d)
  • Loading branch information
eokoneyo committed Dec 19, 2024
1 parent 16401c0 commit fdd5a34
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ describe('Share modal embed content tab', () => {
component = mountWithIntl(
<EmbedContent
objectType="dashboard"
setIsNotSaved={() => jest.fn()}
shareableUrl="/home#/"
/>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@ type EmbedProps = Pick<
| 'shareableUrl'
| 'embedUrlParamExtensions'
| 'objectType'
> & {
setIsNotSaved: () => void;
};
>;

interface UrlParams {
[extensionName: string]: {
Expand All @@ -52,7 +50,6 @@ export const EmbedContent = ({
shareableUrlForSavedObject,
shareableUrl,
objectType,
setIsNotSaved,
}: EmbedProps) => {
const isMounted = useMountedState();
const [urlParams, setUrlParams] = useState<UrlParams | undefined>(undefined);
Expand All @@ -63,10 +60,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
36 changes: 2 additions & 34 deletions src/plugins/share/public/components/tabs/embed/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,55 +8,24 @@
*/

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, 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 (
<EmbedContent
{...{
embedUrlParamExtensions,
shareableUrlForSavedObject,
shareableUrl,
objectType,
isNotSaved: state?.isNotSaved,
setIsNotSaved,
}}
/>
);
Expand All @@ -67,6 +36,5 @@ export const embedTab: IEmbedTab = {
name: i18n.translate('share.contextMenu.embedCodeTab', {
defaultMessage: 'Embed',
}),
reducer: embedTabReducer,
content: EmbedTabContent,
};

0 comments on commit fdd5a34

Please sign in to comment.