mirror of
https://github.com/apache/superset.git
synced 2026-04-24 18:44:53 +00:00
chore: migrate /sql_json and /results to apiv1 (#22809)
This commit is contained in:
@@ -17,6 +17,7 @@
|
||||
* under the License.
|
||||
*/
|
||||
import shortid from 'shortid';
|
||||
import rison from 'rison';
|
||||
import { SupersetClient, t } from '@superset-ui/core';
|
||||
import invert from 'lodash/invert';
|
||||
import mapKeys from 'lodash/mapKeys';
|
||||
@@ -305,8 +306,13 @@ export function fetchQueryResults(query, displayLimit) {
|
||||
return function (dispatch) {
|
||||
dispatch(requestQueryResults(query));
|
||||
|
||||
const queryParams = rison.encode({
|
||||
key: query.resultsKey,
|
||||
rows: displayLimit || null,
|
||||
});
|
||||
|
||||
return SupersetClient.get({
|
||||
endpoint: `/superset/results/${query.resultsKey}/?rows=${displayLimit}`,
|
||||
endpoint: `/api/v1/sqllab/results/?q=${queryParams}`,
|
||||
parseMethod: 'json-bigint',
|
||||
})
|
||||
.then(({ json }) => dispatch(querySuccess(query, json)))
|
||||
@@ -347,7 +353,7 @@ export function runQuery(query) {
|
||||
|
||||
const search = window.location.search || '';
|
||||
return SupersetClient.post({
|
||||
endpoint: `/superset/sql_json/${search}`,
|
||||
endpoint: `/api/v1/sqllab/execute/${search}`,
|
||||
body: JSON.stringify(postPayload),
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
parseMethod: 'json-bigint',
|
||||
@@ -359,7 +365,11 @@ export function runQuery(query) {
|
||||
})
|
||||
.catch(response =>
|
||||
getClientErrorObject(response).then(error => {
|
||||
let message = error.error || error.statusText || t('Unknown error');
|
||||
let message =
|
||||
error.error ||
|
||||
error.message ||
|
||||
error.statusText ||
|
||||
t('Unknown error');
|
||||
if (message.includes('CSRF token')) {
|
||||
message = t(COMMON_ERR_MESSAGES.SESSION_TIMED_OUT);
|
||||
}
|
||||
|
||||
@@ -55,13 +55,13 @@ describe('async actions', () => {
|
||||
|
||||
afterEach(fetchMock.resetHistory);
|
||||
|
||||
const fetchQueryEndpoint = 'glob:*/superset/results/*';
|
||||
const fetchQueryEndpoint = 'glob:*/api/v1/sqllab/results/*';
|
||||
fetchMock.get(
|
||||
fetchQueryEndpoint,
|
||||
JSON.stringify({ data: mockBigNumber, query: { sqlEditorId: 'dfsadfs' } }),
|
||||
);
|
||||
|
||||
const runQueryEndpoint = 'glob:*/superset/sql_json/';
|
||||
const runQueryEndpoint = 'glob:*/api/v1/sqllab/execute/';
|
||||
fetchMock.post(runQueryEndpoint, `{ "data": ${mockBigNumber} }`);
|
||||
|
||||
describe('saveQuery', () => {
|
||||
@@ -280,7 +280,8 @@ describe('async actions', () => {
|
||||
};
|
||||
|
||||
it('makes the fetch request', async () => {
|
||||
const runQueryEndpointWithParams = 'glob:*/superset/sql_json/?foo=bar';
|
||||
const runQueryEndpointWithParams =
|
||||
'glob:*/api/v1/sqllab/execute/?foo=bar';
|
||||
fetchMock.post(
|
||||
runQueryEndpointWithParams,
|
||||
`{ "data": ${mockBigNumber} }`,
|
||||
|
||||
@@ -55,7 +55,7 @@ const MOCKED_SQL_EDITOR_HEIGHT = 500;
|
||||
|
||||
fetchMock.get('glob:*/api/v1/database/*', { result: [] });
|
||||
fetchMock.get('glob:*/superset/tables/*', { options: [] });
|
||||
fetchMock.post('glob:*/sql_json/*', { result: [] });
|
||||
fetchMock.post('glob:*/sqllab/execute/*', { result: [] });
|
||||
|
||||
const middlewares = [thunk];
|
||||
const mockStore = configureStore(middlewares);
|
||||
|
||||
@@ -688,6 +688,7 @@ export const query = {
|
||||
sql: 'SELECT * FROM something',
|
||||
description: 'test description',
|
||||
schema: 'test schema',
|
||||
resultsKey: 'test',
|
||||
};
|
||||
|
||||
export const queryId = 'clientId2353';
|
||||
|
||||
Reference in New Issue
Block a user