Skip to content

feat(dashboard): "embed code" option on dashboard share tab #33163

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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 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
3 changes: 3 additions & 0 deletions superset-frontend/src/assets/stylesheets/superset.less
Original file line number Diff line number Diff line change
Expand Up @@ -550,3 +550,6 @@ hr {
background-image: url(http://github.com/'../images/icons/error_solid_small_red.svg') !important;
background-position: -2px center !important;
}
div.ant-dropdown-menu-submenu.ant-dropdown-menu-submenu-popup.ant-dropdown-menu {
z-index: 200 !important;
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import {
VizType,
BinaryQueryObjectFilterClause,
QueryFormData,
useTheme,
} from '@superset-ui/core';
import { useSelector } from 'react-redux';
import { Menu } from 'src/components/Menu';
Expand Down Expand Up @@ -329,6 +330,8 @@ const SliceHeaderControls = (
? t('Exit fullscreen')
: t('Enter fullscreen');

const theme = useTheme();

// @z-index-below-dashboard-header (100) - 1 = 99 for !isFullSize and 101 for isFullSize
const dropdownOverlayStyle = {
zIndex: isFullSize ? 101 : 99,
Expand Down Expand Up @@ -448,6 +451,8 @@ const SliceHeaderControls = (
addSuccessToast={addSuccessToast}
addDangerToast={addDangerToast}
title={t('Share')}
latestQueryFormData={props.formData}
maxWidth={`${theme.gridUnit * 100}px`}
/>
)}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import copyTextToClipboard from 'src/utils/copy';
import { t, logging } from '@superset-ui/core';
import { Menu } from 'src/components/Menu';
import { getDashboardPermalink } from 'src/utils/urlUtils';
import EmbedCodeContent from 'src/explore/components/EmbedCodeContent';
import ModalTrigger from 'src/components/ModalTrigger';
import { MenuKeys, RootState } from 'src/dashboard/types';
import { shallowEqual, useSelector } from 'react-redux';

Expand All @@ -34,6 +36,8 @@ interface ShareMenuItemProps extends ComponentProps<typeof Menu.SubMenu> {
addSuccessToast: Function;
dashboardId: string | number;
dashboardComponentId?: string;
latestQueryFormData?: object;
maxWidth?: string;
copyMenuItemRef?: RefObject<any>;
shareByEmailMenuItemRef?: RefObject<any>;
selectedKeys?: string[];
Expand All @@ -52,10 +56,15 @@ const ShareMenuItems = (props: ShareMenuItemProps) => {
addSuccessToast,
dashboardId,
dashboardComponentId,
latestQueryFormData,
maxWidth,
title,
disabled,
...rest
} = props;
const sliceExists =
latestQueryFormData && Object.keys(latestQueryFormData).length > 0;

const { dataMask, activeTabs } = useSelector(
(state: RootState) => ({
dataMask: state.dataMask,
Expand Down Expand Up @@ -109,6 +118,27 @@ const ShareMenuItems = (props: ShareMenuItemProps) => {
<Menu.Item key={MenuKeys.ShareByEmail} onClick={() => onShareByEmail()}>
{emailMenuItemTitle}
</Menu.Item>
{sliceExists && (
<Menu.Item key="embed_code">
<div onClick={e => e.stopPropagation()} role="button" tabIndex={0}>
<ModalTrigger
triggerNode={
<span data-test="embed-code-button">{t('Embed code')}</span>
}
modalTitle={t('Embed code')}
modalBody={
<EmbedCodeContent
formData={latestQueryFormData}
addDangerToast={addDangerToast}
/>
}
maxWidth={maxWidth}
destroyOnClose
responsive
/>
</div>
</Menu.Item>
)}
</Menu.SubMenu>
);
};
Expand Down