Skip to content

Commit

Permalink
small changes to dashboard->explore code (#17145)
Browse files Browse the repository at this point in the history
  • Loading branch information
suddjian committed Oct 22, 2021
1 parent bedb8f4 commit a63a01f
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
import { getExploreLongUrl } from '.';
import { getExploreLongUrl, getExploreUrlFromDashboard } from '.';

const createParams = () => ({
formData: {
Expand Down Expand Up @@ -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',
);
});
17 changes: 10 additions & 7 deletions superset-frontend/src/explore/exploreUtils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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
Expand Down

0 comments on commit a63a01f

Please sign in to comment.