Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: passing url params in sqllab #15246

Merged
merged 3 commits into from
Feb 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion superset-frontend/src/SqlLab/actions/sqlLab.js
Original file line number Diff line number Diff line change
Expand Up @@ -332,8 +332,9 @@ export function runQuery(query) {
expand_data: true,
};

const search = window.location.search || '';
return SupersetClient.post({
endpoint: '/superset/sql_json/',
endpoint: `/superset/sql_json/${search}`,
body: JSON.stringify(postPayload),
headers: { 'Content-Type': 'application/json' },
parseMethod: 'text',
Expand Down
30 changes: 28 additions & 2 deletions superset-frontend/src/SqlLab/actions/sqlLab.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ describe('async actions', () => {
JSON.stringify({ data: mockBigNumber, query: { sqlEditorId: 'dfsadfs' } }),
);

const runQueryEndpoint = 'glob:*/superset/sql_json/*';
const runQueryEndpoint = 'glob:*/superset/sql_json/';
fetchMock.post(runQueryEndpoint, `{ "data": ${mockBigNumber} }`);

describe('saveQuery', () => {
Expand Down Expand Up @@ -188,7 +188,7 @@ describe('async actions', () => {
});
});

describe('runQuery', () => {
describe('runQuery without query params', () => {
const makeRequest = () => {
const request = actions.runQuery(query);
return request(dispatch);
Expand Down Expand Up @@ -250,6 +250,32 @@ describe('async actions', () => {
});
});

describe('runQuery with query params', () => {
const { location } = window;

beforeAll(() => {
delete window.location;
window.location = new URL('http://localhost/sqllab/?foo=bar');
});

afterAll(() => {
delete window.location;
window.location = location;
});

const makeRequest = () => {
const request = actions.runQuery(query);
return request(dispatch);
};

it('makes the fetch request', () =>
makeRequest().then(() => {
expect(
fetchMock.calls('glob:*/superset/sql_json/?foo=bar'),
).toHaveLength(1);
}));
});

describe('reRunQuery', () => {
let stub;
beforeEach(() => {
Expand Down