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(explore): remove unnecessary parameters from the explore url #17123

Merged
merged 2 commits into from
Oct 18, 2021
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -230,7 +230,7 @@ export default class Chart extends React.Component {
});
};

getChartUrl = () => getExploreLongUrl(this.props.formData);
getChartUrl = () => getExploreLongUrl(this.props.formData, null, false);

exportCSV(isFullCSV = false) {
this.props.logEvent(LOG_ACTIONS_EXPORT_CSV_DASHBOARD_CHART, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,3 +90,26 @@ test('Get url when endpointType:results and allowOverflow:false', () => {
'/superset/explore_json/?same=any-string&form_data=%7B%22datasource%22%3A%22datasource%22%2C%22viz_type%22%3A%22viz_type%22%7D',
);
});

test('Get url from a dashboard', () => {
const formData = {
...createParams().formData,
// these params should get filtered out
extra_form_data: {
filters: {
col: 'foo',
op: 'IN',
val: ['bar'],
},
},
dataMask: {
'NATIVE_FILTER-bqEoUsEPe': {
id: 'NATIVE_FILTER-bqEoUsEPe',
lots: 'of other stuff here too',
},
},
};
expect(getExploreLongUrl(formData, null, false)).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',
);
});
9 changes: 8 additions & 1 deletion superset-frontend/src/explore/exploreUtils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/

import { useCallback, useEffect } from 'react';
import { omit } from 'lodash';
/* eslint camelcase: 0 */
import URI from 'urijs';
import {
Expand Down Expand Up @@ -103,13 +104,19 @@ 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(formData);
search.form_data = safeStringify(trimmedFormData);
if (endpointType === URL_PARAMS.standalone.name) {
search.standalone = DashboardStandaloneMode.HIDE_NAV;
}
Expand Down