You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by jl...@apache.org on 2025/01/22 00:05:01 UTC
(superset) 02/02: fix(sqllab): unable to update saved queries (#31639)
This is an automated email from the ASF dual-hosted git repository.
jli pushed a commit to branch 4.1
in repository https://gitbox.apache.org/repos/asf/superset.git
commit 41246c7c1ff779d1c41fc7fede18785d5fb44c13
Author: Damian Pendrak <dp...@gmail.com>
AuthorDate: Thu Jan 9 11:16:08 2025 +0100
fix(sqllab): unable to update saved queries (#31639)
(cherry picked from commit 3a6fdf8bdf1f6ed9500dd4768867085652649982)
---
superset-frontend/src/SqlLab/actions/sqlLab.js | 1 +
.../src/SqlLab/actions/sqlLab.test.js | 109 +++++++++++++++++++++
2 files changed, 110 insertions(+)
diff --git a/superset-frontend/src/SqlLab/actions/sqlLab.js b/superset-frontend/src/SqlLab/actions/sqlLab.js
index 568dbb9b1f..e7cb6e0419 100644
--- a/superset-frontend/src/SqlLab/actions/sqlLab.js
+++ b/superset-frontend/src/SqlLab/actions/sqlLab.js
@@ -1206,6 +1206,7 @@ export function popSavedQuery(saveQueryId) {
schema: queryEditorProps.schema,
sql: queryEditorProps.sql,
templateParams: queryEditorProps.templateParams,
+ remoteId: queryEditorProps.remoteId,
};
return dispatch(addQueryEditor(tmpAdaptedProps));
})
diff --git a/superset-frontend/src/SqlLab/actions/sqlLab.test.js b/superset-frontend/src/SqlLab/actions/sqlLab.test.js
index 142c6768d1..7591abfaea 100644
--- a/superset-frontend/src/SqlLab/actions/sqlLab.test.js
+++ b/superset-frontend/src/SqlLab/actions/sqlLab.test.js
@@ -30,6 +30,9 @@ import {
initialState,
queryId,
} from 'src/SqlLab/fixtures';
+import { SupersetClient } from '@superset-ui/core';
+import { ADD_TOAST } from 'src/components/MessageToasts/actions';
+import { ToastType } from '../../components/MessageToasts/types';
const middlewares = [thunk];
const mockStore = configureMockStore(middlewares);
@@ -453,6 +456,112 @@ describe('async actions', () => {
});
});
+ describe('popSavedQuery', () => {
+ const supersetClientGetSpy = jest.spyOn(SupersetClient, 'get');
+ const store = mockStore({});
+
+ const mockSavedQueryApiResponse = {
+ catalog: null,
+ changed_by: {
+ first_name: 'Superset',
+ id: 1,
+ last_name: 'Admin',
+ },
+ changed_on: '2024-12-28T20:06:14.246743',
+ changed_on_delta_humanized: '8 days ago',
+ created_by: {
+ first_name: 'Superset',
+ id: 1,
+ last_name: 'Admin',
+ },
+ database: {
+ database_name: 'examples',
+ id: 2,
+ },
+ description: '',
+ id: 1,
+ label: 'Query 1',
+ schema: 'public',
+ sql: 'SELECT * FROM channels',
+ sql_tables: [
+ {
+ catalog: null,
+ schema: null,
+ table: 'channels',
+ },
+ ],
+ template_parameters: null,
+ };
+
+ const makeRequest = id => {
+ const request = actions.popSavedQuery(id);
+ const { dispatch } = store;
+
+ return request(dispatch, () => initialState);
+ };
+
+ beforeEach(() => {
+ supersetClientGetSpy.mockClear();
+ store.clearActions();
+ });
+
+ afterAll(() => {
+ supersetClientGetSpy.mockRestore();
+ });
+
+ it('calls API endpint with correct params', async () => {
+ supersetClientGetSpy.mockResolvedValue({
+ json: { result: mockSavedQueryApiResponse },
+ });
+
+ await makeRequest(123);
+
+ expect(supersetClientGetSpy).toHaveBeenCalledWith({
+ endpoint: '/api/v1/saved_query/123',
+ });
+ });
+
+ it('dispatches addQueryEditor with correct params on successful API call', async () => {
+ supersetClientGetSpy.mockResolvedValue({
+ json: { result: mockSavedQueryApiResponse },
+ });
+
+ const expectedParams = {
+ name: 'Query 1',
+ dbId: 2,
+ catalog: null,
+ schema: 'public',
+ sql: 'SELECT * FROM channels',
+ templateParams: null,
+ remoteId: 1,
+ };
+
+ await makeRequest(1);
+
+ const addQueryEditorAction = store
+ .getActions()
+ .find(action => action.type === actions.ADD_QUERY_EDITOR);
+
+ expect(addQueryEditorAction).toBeTruthy();
+ expect(addQueryEditorAction?.queryEditor).toEqual(
+ expect.objectContaining(expectedParams),
+ );
+ });
+
+ it('should dispatch addDangerToast on API error', async () => {
+ supersetClientGetSpy.mockResolvedValue(new Error());
+
+ await makeRequest(1);
+
+ const addToastAction = store
+ .getActions()
+ .find(action => action.type === ADD_TOAST);
+
+ expect(addToastAction).toBeTruthy();
+ expect(addToastAction?.payload?.toastType).toBe(ToastType.Danger);
+ });
+ });
+
describe('addQueryEditor', () => {
it('creates new query editor', () => {
expect.assertions(1);