Skip to content
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

fix(dashboard): copy permalink to dashboard chart #19772

Merged
merged 3 commits into from
Apr 19, 2022
Merged
Show file tree
Hide file tree
Changes from 2 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
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,8 @@ class SliceHeaderControls extends React.PureComponent<

render() {
const {
componentId,
dashboardId,
slice,
isFullSize,
cachedDttm = [],
Expand All @@ -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';
Expand Down Expand Up @@ -310,13 +311,14 @@ class SliceHeaderControls extends React.PureComponent<

{supersetCanShare && (
<ShareMenuItems
dashboardId={dashboardId}
hash={componentId}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
hash={componentId}
dashboardComponentId={componentId}

Can we push down the concept of hash to only when we interact with the URL? It took me a while to realize what it really means.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a good idea, I like it 👍

copyMenuItemTitle={t('Copy permalink to clipboard')}
emailMenuItemTitle={t('Share permalink by email')}
emailSubject={t('Superset chart')}
emailBody={t('Check out this chart: ')}
addSuccessToast={addSuccessToast}
addDangerToast={addDangerToast}
formData={formData}
/>
)}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -36,8 +32,8 @@ interface ShareMenuItemProps {
emailBody: string;
addDangerToast: Function;
addSuccessToast: Function;
dashboardId?: string;
formData?: Pick<QueryFormData, 'slice_id' | 'datasource'>;
dashboardId: string | number;
hash?: string;
}

const ShareMenuItems = (props: ShareMenuItemProps) => {
Expand All @@ -49,23 +45,17 @@ const ShareMenuItems = (props: ShareMenuItemProps) => {
addDangerToast,
addSuccessToast,
dashboardId,
formData,
hash,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm trying to understand what hash means and how it is used but couldn't wrap my head around it very easily. Can it be named to something more unique so it's more searchable?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would have personally gone with anchor, but

  1. the previous implementation used the term hash
  2. I found references to hash elsewhere, too: https://www.w3schools.com/jsref/prop_anchor_hash.asp

So I went with hash. Since it's already in the schema, I think it might be a good idea to leave it like that, but I'm happy to change it if you feel even remotely strongly about this.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's okay to keep it as long as it is pushed downward to when the URL is actually used. Or we can add some comments.

...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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be nice if we make this more explicit:

Suggested change
return getDashboardPermalink(String(dashboardId), filterState, hash);
return getDashboardPermalink({
dashboardId, # need to relax the type restriction in `getDashboardPermalink` as well
filterState,
hash: dashboardComponentId
});

}

async function onCopyLink() {
Expand Down