From 4bd59d89983a9af2db222fb457c8eec4b7082260 Mon Sep 17 00:00:00 2001 From: Ville Brofeldt Date: Tue, 19 Apr 2022 11:46:24 +0300 Subject: [PATCH 1/3] fix(dashboard): copy permalink to dashboard chart --- .../components/SliceHeaderControls/index.tsx | 6 +++-- .../components/menu/ShareMenuItems/index.tsx | 22 +++++-------------- 2 files changed, 10 insertions(+), 18 deletions(-) diff --git a/superset-frontend/src/dashboard/components/SliceHeaderControls/index.tsx b/superset-frontend/src/dashboard/components/SliceHeaderControls/index.tsx index 09d646853d24..331390b2c7a6 100644 --- a/superset-frontend/src/dashboard/components/SliceHeaderControls/index.tsx +++ b/superset-frontend/src/dashboard/components/SliceHeaderControls/index.tsx @@ -213,6 +213,8 @@ class SliceHeaderControls extends React.PureComponent< render() { const { + componentId, + dashboardId, slice, isFullSize, cachedDttm = [], @@ -221,7 +223,6 @@ class SliceHeaderControls extends React.PureComponent< addDangerToast = () => {}, supersetCanShare = false, isCached = [], - formData, } = this.props; const crossFilterItems = getChartMetadataRegistry().items; const isTable = slice.viz_type === 'table'; @@ -310,13 +311,14 @@ class SliceHeaderControls extends React.PureComponent< {supersetCanShare && ( )} diff --git a/superset-frontend/src/dashboard/components/menu/ShareMenuItems/index.tsx b/superset-frontend/src/dashboard/components/menu/ShareMenuItems/index.tsx index c70e47dc3d01..d91368233fdf 100644 --- a/superset-frontend/src/dashboard/components/menu/ShareMenuItems/index.tsx +++ b/superset-frontend/src/dashboard/components/menu/ShareMenuItems/index.tsx @@ -18,14 +18,10 @@ */ import React from 'react'; 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 { - getChartPermalink, - getDashboardPermalink, - getUrlParam, -} from 'src/utils/urlUtils'; -import { RESERVED_DASHBOARD_URL_PARAMS, URL_PARAMS } from 'src/constants'; +import { getDashboardPermalink, getUrlParam } from 'src/utils/urlUtils'; +import { URL_PARAMS } from 'src/constants'; import { getFilterValue } from 'src/dashboard/components/nativeFilters/FilterBar/keyValue'; interface ShareMenuItemProps { @@ -37,7 +33,7 @@ interface ShareMenuItemProps { addDangerToast: Function; addSuccessToast: Function; dashboardId?: string; - formData?: Pick; + hash?: string; } const ShareMenuItems = (props: ShareMenuItemProps) => { @@ -49,23 +45,17 @@ const ShareMenuItems = (props: ShareMenuItemProps) => { addDangerToast, addSuccessToast, dashboardId, - formData, + hash, ...rest } = props; 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); let filterState = {}; if (nativeFiltersKey && dashboardId) { filterState = await getFilterValue(dashboardId, nativeFiltersKey); } - return getDashboardPermalink(String(dashboardId), filterState); + return getDashboardPermalink(String(dashboardId), filterState, hash); } async function onCopyLink() { From 783d5905df52bfd9320e7afeb72e0ff3e12d3f57 Mon Sep 17 00:00:00 2001 From: Ville Brofeldt Date: Tue, 19 Apr 2022 13:21:34 +0300 Subject: [PATCH 2/3] lint --- .../src/dashboard/components/menu/ShareMenuItems/index.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/superset-frontend/src/dashboard/components/menu/ShareMenuItems/index.tsx b/superset-frontend/src/dashboard/components/menu/ShareMenuItems/index.tsx index d91368233fdf..950a8f47d793 100644 --- a/superset-frontend/src/dashboard/components/menu/ShareMenuItems/index.tsx +++ b/superset-frontend/src/dashboard/components/menu/ShareMenuItems/index.tsx @@ -32,7 +32,7 @@ interface ShareMenuItemProps { emailBody: string; addDangerToast: Function; addSuccessToast: Function; - dashboardId?: string; + dashboardId: string | number; hash?: string; } From c4862e2c028bb6e32032236d017329a18fbb979e Mon Sep 17 00:00:00 2001 From: Ville Brofeldt Date: Tue, 19 Apr 2022 21:05:15 +0300 Subject: [PATCH 3/3] address comments --- .../src/components/URLShortLinkButton/index.jsx | 8 ++++---- .../components/SliceHeaderControls/index.tsx | 2 +- .../components/menu/ShareMenuItems/index.tsx | 10 +++++++--- superset-frontend/src/utils/urlUtils.ts | 14 +++++++++----- 4 files changed, 21 insertions(+), 13 deletions(-) diff --git a/superset-frontend/src/components/URLShortLinkButton/index.jsx b/superset-frontend/src/components/URLShortLinkButton/index.jsx index 35795f81a11f..4a03e02d3ea5 100644 --- a/superset-frontend/src/components/URLShortLinkButton/index.jsx +++ b/superset-frontend/src/components/URLShortLinkButton/index.jsx @@ -57,11 +57,11 @@ class URLShortLinkButton extends React.Component { if (this.props.dashboardId) { getFilterValue(this.props.dashboardId, nativeFiltersKey) .then(filterState => - getDashboardPermalink( - String(this.props.dashboardId), + getDashboardPermalink({ + dashboardId: this.props.dashboardId, filterState, - this.props.anchorLinkId, - ) + hash: this.props.anchorLinkId, + }) .then(this.onShortUrlSuccess) .catch(this.props.addDangerToast), ) diff --git a/superset-frontend/src/dashboard/components/SliceHeaderControls/index.tsx b/superset-frontend/src/dashboard/components/SliceHeaderControls/index.tsx index 331390b2c7a6..86c73a09b6ec 100644 --- a/superset-frontend/src/dashboard/components/SliceHeaderControls/index.tsx +++ b/superset-frontend/src/dashboard/components/SliceHeaderControls/index.tsx @@ -312,7 +312,7 @@ class SliceHeaderControls extends React.PureComponent< {supersetCanShare && ( { @@ -45,7 +45,7 @@ const ShareMenuItems = (props: ShareMenuItemProps) => { addDangerToast, addSuccessToast, dashboardId, - hash, + dashboardComponentId, ...rest } = props; @@ -55,7 +55,11 @@ const ShareMenuItems = (props: ShareMenuItemProps) => { if (nativeFiltersKey && dashboardId) { filterState = await getFilterValue(dashboardId, nativeFiltersKey); } - return getDashboardPermalink(String(dashboardId), filterState, hash); + return getDashboardPermalink({ + dashboardId, + filterState, + hash: dashboardComponentId, + }); } async function onCopyLink() { diff --git a/superset-frontend/src/utils/urlUtils.ts b/superset-frontend/src/utils/urlUtils.ts index be857517e06d..bd570291f2cb 100644 --- a/superset-frontend/src/utils/urlUtils.ts +++ b/superset-frontend/src/utils/urlUtils.ts @@ -154,11 +154,15 @@ export function getChartPermalink( }); } -export function getDashboardPermalink( - dashboardId: string, - filterState: JsonObject, - hash?: string, -) { +export function getDashboardPermalink({ + dashboardId, + filterState, + 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 return getPermalink(`/api/v1/dashboard/${dashboardId}/permalink`, { filterState,