-
Notifications
You must be signed in to change notification settings - Fork 14.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b97a827
commit 10773f9
Showing
11 changed files
with
151 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../docs/_build/html/ |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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'; | ||
} | ||
if (endpointType === 'csv') { | ||
search.csv = 'true'; | ||
} | ||
if (endpointType === 'standalone') { | ||
search.standalone = '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 === 'query') { | ||
search.query = 'true'; | ||
} | ||
uri = uri.search(search).directory(directory); | ||
return uri.toString(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import { it, describe } from 'mocha'; | ||
import { expect } from 'chai'; | ||
import URI from 'urijs'; | ||
import { getExploreUrl } from '../../../javascripts/explorev2/exploreUtils.js'; | ||
|
||
describe('utils', () => { | ||
const formData = { | ||
datasource: '1__table', | ||
}; | ||
const sFormData = JSON.stringify(formData); | ||
function compareURI(uri1, uri2) { | ||
expect(uri1.toString()).to.equal(uri2.toString()); | ||
} | ||
|
||
it('getExploreUrl generates proper base url', () => { | ||
// This assertion is to show clearly the value of location.href | ||
// in the context of unit tests. | ||
expect(location.href).to.equal('about:blank'); | ||
|
||
compareURI( | ||
URI(getExploreUrl(formData, 'base', false, 'http://superset.com')), | ||
URI('/superset/explore/table/1/').search({ form_data: sFormData }) | ||
); | ||
}); | ||
it('getExploreUrl generates proper json url', () => { | ||
compareURI( | ||
URI(getExploreUrl(formData, 'json', false, 'superset.com')), | ||
URI('/superset/explore_json/table/1/').search({ form_data: sFormData }) | ||
); | ||
}); | ||
it('getExploreUrl generates proper json forced url', () => { | ||
compareURI( | ||
URI(getExploreUrl(formData, 'json', true, 'superset.com')), | ||
URI('/superset/explore_json/table/1/') | ||
.search({ form_data: sFormData, force: 'true' }) | ||
); | ||
}); | ||
it('getExploreUrl generates proper csv URL', () => { | ||
compareURI( | ||
URI(getExploreUrl(formData, 'csv', false, 'superset.com')), | ||
URI('/superset/explore_json/table/1/') | ||
.search({ form_data: sFormData, csv: 'true' }) | ||
); | ||
}); | ||
it('getExploreUrl generates proper standalone URL', () => { | ||
compareURI( | ||
URI(getExploreUrl(formData, 'standalone', false, 'superset.com')), | ||
URI('/superset/explore/table/1/') | ||
.search({ form_data: sFormData, standalone: 'true' }) | ||
); | ||
}); | ||
it('getExploreUrl preserves main URLs params', () => { | ||
compareURI( | ||
URI(getExploreUrl(formData, 'json', false, 'superset.com?foo=bar')), | ||
URI('/superset/explore_json/table/1/') | ||
.search({ foo: 'bar', form_data: sFormData }) | ||
); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters