Skip to content

Commit

Permalink
refactor, test
Browse files Browse the repository at this point in the history
  • Loading branch information
suddjian committed Oct 15, 2021
1 parent 1fc5005 commit ee33688
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -230,18 +230,7 @@ export default class Chart extends React.Component {
});
};

getChartUrl = () => {
const filters = this.props.formData?.extra_form_data?.filters;
// remove formData params that we don't need in the explore url
// this should be superseded by some sort of "exploration context" system
const formData = {
...this.props.formData,
extra_form_data: { filters },
native_filters: undefined,
dataMask: undefined,
};
return getExploreLongUrl(formData, null, false);
};
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

0 comments on commit ee33688

Please sign in to comment.