Skip to content

Commit

Permalink
Fix share modal copy embed code (elastic#204584)
Browse files Browse the repository at this point in the history
## Summary

Closes elastic#204312

This PR removes an unnecessary function, that causes an infinite render
loop for visualisations.


## After


https://github.com/user-attachments/assets/259d238b-c1cf-4d74-bfca-1a6440d0f5cd

## How to test
- 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.

<!--
### Checklist

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)

### Identify risks

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)
- [ ] ...


-->
  • Loading branch information
eokoneyo authored Dec 17, 2024
1 parent 02b65bd commit effd84d
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 45 deletions.
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,
};

0 comments on commit effd84d

Please sign in to comment.