From 8a4a08d5fc737cdbf6f7a483fe0d04d1c9f9c511 Mon Sep 17 00:00:00 2001 From: maltoze Date: Fri, 18 Jun 2021 13:26:11 +0800 Subject: [PATCH 1/2] fix: passing url params in sqllab --- superset-frontend/src/SqlLab/actions/sqlLab.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/superset-frontend/src/SqlLab/actions/sqlLab.js b/superset-frontend/src/SqlLab/actions/sqlLab.js index 18d2141bf36f1..3258c239c744f 100644 --- a/superset-frontend/src/SqlLab/actions/sqlLab.js +++ b/superset-frontend/src/SqlLab/actions/sqlLab.js @@ -329,7 +329,7 @@ export function runQuery(query) { }; return SupersetClient.post({ - endpoint: '/superset/sql_json/', + endpoint: `/superset/sql_json/${window.location.search}`, body: JSON.stringify(postPayload), headers: { 'Content-Type': 'application/json' }, parseMethod: 'text', From 4a55452c22649f3ce6323417b32b19c35bc5b27f Mon Sep 17 00:00:00 2001 From: Ville Brofeldt Date: Tue, 15 Feb 2022 12:25:50 +0200 Subject: [PATCH 2/2] avoid undefined serach and add test --- .../src/SqlLab/actions/sqlLab.js | 3 +- .../src/SqlLab/actions/sqlLab.test.js | 30 +++++++++++++++++-- 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/superset-frontend/src/SqlLab/actions/sqlLab.js b/superset-frontend/src/SqlLab/actions/sqlLab.js index 68af806c7cfd2..f89a6a8535df7 100644 --- a/superset-frontend/src/SqlLab/actions/sqlLab.js +++ b/superset-frontend/src/SqlLab/actions/sqlLab.js @@ -332,8 +332,9 @@ export function runQuery(query) { expand_data: true, }; + const search = window.location.search || ''; return SupersetClient.post({ - endpoint: `/superset/sql_json/${window.location.search}`, + endpoint: `/superset/sql_json/${search}`, body: JSON.stringify(postPayload), headers: { 'Content-Type': 'application/json' }, parseMethod: 'text', diff --git a/superset-frontend/src/SqlLab/actions/sqlLab.test.js b/superset-frontend/src/SqlLab/actions/sqlLab.test.js index 49b523a683b83..7e1326336f351 100644 --- a/superset-frontend/src/SqlLab/actions/sqlLab.test.js +++ b/superset-frontend/src/SqlLab/actions/sqlLab.test.js @@ -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', () => { @@ -188,7 +188,7 @@ describe('async actions', () => { }); }); - describe('runQuery', () => { + describe('runQuery without query params', () => { const makeRequest = () => { const request = actions.runQuery(query); return request(dispatch); @@ -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(() => {