mirror of https://github.com/apache/superset.git
fix(dashboard): copy permalink to dashboard chart (#19772)
* fix(dashboard): copy permalink to dashboard chart * lint * address comments
This commit is contained in:
parent
a6f46013d9
commit
e061955fd0
|
@ -57,11 +57,11 @@ class URLShortLinkButton extends React.Component {
|
||||||
if (this.props.dashboardId) {
|
if (this.props.dashboardId) {
|
||||||
getFilterValue(this.props.dashboardId, nativeFiltersKey)
|
getFilterValue(this.props.dashboardId, nativeFiltersKey)
|
||||||
.then(filterState =>
|
.then(filterState =>
|
||||||
getDashboardPermalink(
|
getDashboardPermalink({
|
||||||
String(this.props.dashboardId),
|
dashboardId: this.props.dashboardId,
|
||||||
filterState,
|
filterState,
|
||||||
this.props.anchorLinkId,
|
hash: this.props.anchorLinkId,
|
||||||
)
|
})
|
||||||
.then(this.onShortUrlSuccess)
|
.then(this.onShortUrlSuccess)
|
||||||
.catch(this.props.addDangerToast),
|
.catch(this.props.addDangerToast),
|
||||||
)
|
)
|
||||||
|
|
|
@ -213,6 +213,8 @@ class SliceHeaderControls extends React.PureComponent<
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const {
|
const {
|
||||||
|
componentId,
|
||||||
|
dashboardId,
|
||||||
slice,
|
slice,
|
||||||
isFullSize,
|
isFullSize,
|
||||||
cachedDttm = [],
|
cachedDttm = [],
|
||||||
|
@ -221,7 +223,6 @@ class SliceHeaderControls extends React.PureComponent<
|
||||||
addDangerToast = () => {},
|
addDangerToast = () => {},
|
||||||
supersetCanShare = false,
|
supersetCanShare = false,
|
||||||
isCached = [],
|
isCached = [],
|
||||||
formData,
|
|
||||||
} = this.props;
|
} = this.props;
|
||||||
const crossFilterItems = getChartMetadataRegistry().items;
|
const crossFilterItems = getChartMetadataRegistry().items;
|
||||||
const isTable = slice.viz_type === 'table';
|
const isTable = slice.viz_type === 'table';
|
||||||
|
@ -310,13 +311,14 @@ class SliceHeaderControls extends React.PureComponent<
|
||||||
|
|
||||||
{supersetCanShare && (
|
{supersetCanShare && (
|
||||||
<ShareMenuItems
|
<ShareMenuItems
|
||||||
|
dashboardId={dashboardId}
|
||||||
|
dashboardComponentId={componentId}
|
||||||
copyMenuItemTitle={t('Copy permalink to clipboard')}
|
copyMenuItemTitle={t('Copy permalink to clipboard')}
|
||||||
emailMenuItemTitle={t('Share permalink by email')}
|
emailMenuItemTitle={t('Share permalink by email')}
|
||||||
emailSubject={t('Superset chart')}
|
emailSubject={t('Superset chart')}
|
||||||
emailBody={t('Check out this chart: ')}
|
emailBody={t('Check out this chart: ')}
|
||||||
addSuccessToast={addSuccessToast}
|
addSuccessToast={addSuccessToast}
|
||||||
addDangerToast={addDangerToast}
|
addDangerToast={addDangerToast}
|
||||||
formData={formData}
|
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
|
|
@ -18,14 +18,10 @@
|
||||||
*/
|
*/
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import copyTextToClipboard from 'src/utils/copy';
|
import copyTextToClipboard from 'src/utils/copy';
|
||||||
import { t, logging, QueryFormData } from '@superset-ui/core';
|
import { t, logging } from '@superset-ui/core';
|
||||||
import { Menu } from 'src/components/Menu';
|
import { Menu } from 'src/components/Menu';
|
||||||
import {
|
import { getDashboardPermalink, getUrlParam } from 'src/utils/urlUtils';
|
||||||
getChartPermalink,
|
import { URL_PARAMS } from 'src/constants';
|
||||||
getDashboardPermalink,
|
|
||||||
getUrlParam,
|
|
||||||
} from 'src/utils/urlUtils';
|
|
||||||
import { RESERVED_DASHBOARD_URL_PARAMS, URL_PARAMS } from 'src/constants';
|
|
||||||
import { getFilterValue } from 'src/dashboard/components/nativeFilters/FilterBar/keyValue';
|
import { getFilterValue } from 'src/dashboard/components/nativeFilters/FilterBar/keyValue';
|
||||||
|
|
||||||
interface ShareMenuItemProps {
|
interface ShareMenuItemProps {
|
||||||
|
@ -36,8 +32,8 @@ interface ShareMenuItemProps {
|
||||||
emailBody: string;
|
emailBody: string;
|
||||||
addDangerToast: Function;
|
addDangerToast: Function;
|
||||||
addSuccessToast: Function;
|
addSuccessToast: Function;
|
||||||
dashboardId?: string;
|
dashboardId: string | number;
|
||||||
formData?: Pick<QueryFormData, 'slice_id' | 'datasource'>;
|
dashboardComponentId?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
const ShareMenuItems = (props: ShareMenuItemProps) => {
|
const ShareMenuItems = (props: ShareMenuItemProps) => {
|
||||||
|
@ -49,23 +45,21 @@ const ShareMenuItems = (props: ShareMenuItemProps) => {
|
||||||
addDangerToast,
|
addDangerToast,
|
||||||
addSuccessToast,
|
addSuccessToast,
|
||||||
dashboardId,
|
dashboardId,
|
||||||
formData,
|
dashboardComponentId,
|
||||||
...rest
|
...rest
|
||||||
} = props;
|
} = props;
|
||||||
|
|
||||||
async function generateUrl() {
|
async function generateUrl() {
|
||||||
// chart
|
|
||||||
if (formData) {
|
|
||||||
// we need to remove reserved dashboard url params
|
|
||||||
return getChartPermalink(formData, RESERVED_DASHBOARD_URL_PARAMS);
|
|
||||||
}
|
|
||||||
// dashboard
|
|
||||||
const nativeFiltersKey = getUrlParam(URL_PARAMS.nativeFiltersKey);
|
const nativeFiltersKey = getUrlParam(URL_PARAMS.nativeFiltersKey);
|
||||||
let filterState = {};
|
let filterState = {};
|
||||||
if (nativeFiltersKey && dashboardId) {
|
if (nativeFiltersKey && dashboardId) {
|
||||||
filterState = await getFilterValue(dashboardId, nativeFiltersKey);
|
filterState = await getFilterValue(dashboardId, nativeFiltersKey);
|
||||||
}
|
}
|
||||||
return getDashboardPermalink(String(dashboardId), filterState);
|
return getDashboardPermalink({
|
||||||
|
dashboardId,
|
||||||
|
filterState,
|
||||||
|
hash: dashboardComponentId,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async function onCopyLink() {
|
async function onCopyLink() {
|
||||||
|
|
|
@ -154,11 +154,15 @@ export function getChartPermalink(
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getDashboardPermalink(
|
export function getDashboardPermalink({
|
||||||
dashboardId: string,
|
dashboardId,
|
||||||
filterState: JsonObject,
|
filterState,
|
||||||
hash?: string,
|
hash, // the anchor part of the link which corresponds to the tab/chart id
|
||||||
) {
|
}: {
|
||||||
|
dashboardId: string | number;
|
||||||
|
filterState: JsonObject;
|
||||||
|
hash?: string;
|
||||||
|
}) {
|
||||||
// only encode filter box state if non-empty
|
// only encode filter box state if non-empty
|
||||||
return getPermalink(`/api/v1/dashboard/${dashboardId}/permalink`, {
|
return getPermalink(`/api/v1/dashboard/${dashboardId}/permalink`, {
|
||||||
filterState,
|
filterState,
|
||||||
|
|
Loading…
Reference in New Issue