All files / javascripts/explorev2 exploreUtils.js

92% Statements 23/25
76.92% Branches 20/26
100% Functions 1/1
91.67% Lines 22/24
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44  1x   18x 6x               6x 6x 6x       6x 6x 4x   6x 6x     6x 6x 6x 1x   6x 1x   6x 1x   6x     6x 6x    
/* eslint camelcase: 0 */
import URI from 'urijs';
 
export function getExploreUrl(form_data, endpointType = 'base', force = false, curUrl = null) {
  Iif (!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);
  Eif (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('__');
  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) {
    search.force = 'true';
  }
  if (endpointType === 'csv') {
    search.csv = 'true';
  }
  if (endpointType === 'standalone') {
    search.standalone = 'true';
  }
  Iif (endpointType === 'query') {
    search.query = 'true';
  }
  uri = uri.search(search).directory(directory);
  return uri.toString();
}