diff --git a/superset-frontend/src/dashboard/components/gridComponents/Chart.jsx b/superset-frontend/src/dashboard/components/gridComponents/Chart.jsx index 8801cf3a21..0e7e7d6a96 100644 --- a/superset-frontend/src/dashboard/components/gridComponents/Chart.jsx +++ b/superset-frontend/src/dashboard/components/gridComponents/Chart.jsx @@ -22,7 +22,10 @@ import PropTypes from 'prop-types'; import { styled } from '@superset-ui/core'; import { isEqual } from 'lodash'; -import { exportChart, getExploreLongUrl } from 'src/explore/exploreUtils'; +import { + exportChart, + getExploreUrlFromDashboard, +} from 'src/explore/exploreUtils'; import ChartContainer from 'src/chart/ChartContainer'; import { LOG_ACTIONS_CHANGE_DASHBOARD_FILTER, @@ -230,7 +233,7 @@ export default class Chart extends React.Component { }); }; - getChartUrl = () => getExploreLongUrl(this.props.formData, null, false); + getChartUrl = () => getExploreUrlFromDashboard(this.props.formData); exportCSV(isFullCSV = false) { this.props.logEvent(LOG_ACTIONS_EXPORT_CSV_DASHBOARD_CHART, { diff --git a/superset-frontend/src/explore/exploreUtils/getExploreLongUrl.test.ts b/superset-frontend/src/explore/exploreUtils/getExploreLongUrl.test.ts index c8d78b9014..76b4dd91ee 100644 --- a/superset-frontend/src/explore/exploreUtils/getExploreLongUrl.test.ts +++ b/superset-frontend/src/explore/exploreUtils/getExploreLongUrl.test.ts @@ -16,7 +16,7 @@ * specific language governing permissions and limitations * under the License. */ -import { getExploreLongUrl } from '.'; +import { getExploreLongUrl, getExploreUrlFromDashboard } from '.'; const createParams = () => ({ formData: { @@ -108,8 +108,12 @@ test('Get url from a dashboard', () => { lots: 'of other stuff here too', }, }, + url_params: { + native_filters: '(blah)', + standalone: true, + }, }; - expect(getExploreLongUrl(formData, null, false)).toBe( + expect(getExploreUrlFromDashboard(formData)).toBe( '/superset/explore/?form_data=%7B%22datasource%22%3A%22datasource%22%2C%22viz_type%22%3A%22viz_type%22%2C%22extra_form_data%22%3A%7B%22filters%22%3A%7B%22col%22%3A%22foo%22%2C%22op%22%3A%22IN%22%2C%22val%22%3A%5B%22bar%22%5D%7D%7D%7D', ); }); diff --git a/superset-frontend/src/explore/exploreUtils/index.js b/superset-frontend/src/explore/exploreUtils/index.js index 87720a7e3e..902f2270f3 100644 --- a/superset-frontend/src/explore/exploreUtils/index.js +++ b/superset-frontend/src/explore/exploreUtils/index.js @@ -104,19 +104,13 @@ export function getExploreLongUrl( return null; } - // remove formData params that we don't need in the explore url. - // These are present when generating explore urls from the dashboard page. - // This should be superseded by some sort of "exploration context" system - // where form data and other context is referenced by id. - const trimmedFormData = omit(formData, ['dataMask', 'url_params']); - const uri = new URI('/'); const directory = getURIDirectory(endpointType); const search = uri.search(true); Object.keys(extraSearch).forEach(key => { search[key] = extraSearch[key]; }); - search.form_data = safeStringify(trimmedFormData); + search.form_data = safeStringify(formData); if (endpointType === URL_PARAMS.standalone.name) { search.standalone = DashboardStandaloneMode.HIDE_NAV; } @@ -133,6 +127,15 @@ export function getExploreLongUrl( return url; } +export function getExploreUrlFromDashboard(formData) { + // remove formData params that we don't need in the explore url. + // These are present when generating explore urls from the dashboard page. + // This should be superseded by some sort of "exploration context" system + // where form data and other context is referenced by id. + const trimmedFormData = omit(formData, ['dataMask', 'url_params']); + return getExploreLongUrl(trimmedFormData, null, false); +} + export function getChartDataUri({ path, qs, allowDomainSharding = false }) { // The search params from the window.location are carried through, // but can be specified with curUrl (used for unit tests to spoof