mirror of
https://github.com/apache/superset.git
synced 2026-04-18 23:55:00 +00:00
URL Params macro (#2537)
This commit is contained in:
committed by
GitHub
parent
b97a8275d4
commit
10773f96a7
@@ -1,26 +1,43 @@
|
||||
/* eslint camelcase: 0 */
|
||||
export function getExploreUrl(form_data, endpoint = 'base', force = false) {
|
||||
import URI from 'urijs';
|
||||
|
||||
export function getExploreUrl(form_data, endpointType = 'base', force = false, curUrl = null) {
|
||||
if (!form_data.datasource) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
// The search params from the window.location are carried through,
|
||||
// but can be specified with curUrl (used for unit tests to spoof
|
||||
// the window.location).
|
||||
let uri = URI(window.location.search);
|
||||
if (curUrl) {
|
||||
uri = URI(URI(curUrl).search());
|
||||
}
|
||||
|
||||
// Building the directory part of the URI
|
||||
let directory = '/superset/explore/';
|
||||
if (['json', 'csv', 'query'].indexOf(endpointType) >= 0) {
|
||||
directory = '/superset/explore_json/';
|
||||
}
|
||||
const [datasource_id, datasource_type] = form_data.datasource.split('__');
|
||||
let params = `${datasource_type}/${datasource_id}/`;
|
||||
params += '?form_data=' + encodeURIComponent(JSON.stringify(form_data));
|
||||
directory += `${datasource_type}/${datasource_id}/`;
|
||||
|
||||
// Building the querystring (search) part of the URI
|
||||
const search = uri.search(true);
|
||||
search.form_data = JSON.stringify(form_data);
|
||||
if (force) {
|
||||
params += '&force=true';
|
||||
search.force = 'true';
|
||||
}
|
||||
switch (endpoint) {
|
||||
case 'base':
|
||||
return `/superset/explore/${params}`;
|
||||
case 'json':
|
||||
return `/superset/explore_json/${params}`;
|
||||
case 'csv':
|
||||
return `/superset/explore_json/${params}&csv=true`;
|
||||
case 'standalone':
|
||||
return `/superset/explore/${params}&standalone=true`;
|
||||
case 'query':
|
||||
return `/superset/explore_json/${params}&query=true`;
|
||||
default:
|
||||
return `/superset/explore/${params}`;
|
||||
if (endpointType === 'csv') {
|
||||
search.csv = 'true';
|
||||
}
|
||||
if (endpointType === 'standalone') {
|
||||
search.standalone = 'true';
|
||||
}
|
||||
if (endpointType === 'query') {
|
||||
search.query = 'true';
|
||||
}
|
||||
uri = uri.search(search).directory(directory);
|
||||
return uri.toString();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user