From 2696d3e8004db8e5a3e83a96a3b2cb0b60de327c Mon Sep 17 00:00:00 2001 From: "JUST.in DO IT" Date: Wed, 6 Aug 2025 07:54:10 -0700 Subject: [PATCH] fix: navigate to SQL Lab due to router api updates (#34569) (cherry picked from commit 53e9cf6d174b9e511b17d927fed5b75e2bfeacaf) --- .../src/explore/components/controls/ViewQuery.test.tsx | 5 +++-- .../src/explore/components/controls/ViewQuery.tsx | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/superset-frontend/src/explore/components/controls/ViewQuery.test.tsx b/superset-frontend/src/explore/components/controls/ViewQuery.test.tsx index 9a18020c342..cba66d5cfbc 100644 --- a/superset-frontend/src/explore/components/controls/ViewQuery.test.tsx +++ b/superset-frontend/src/explore/components/controls/ViewQuery.test.tsx @@ -132,7 +132,8 @@ test('navigates to SQL Lab when View in SQL Lab button is clicked', () => { const viewInSQLLabButton = screen.getByText('View in SQL Lab'); fireEvent.click(viewInSQLLabButton); - expect(mockHistoryPush).toHaveBeenCalledWith('/sqllab', { + expect(mockHistoryPush).toHaveBeenCalledWith({ + pathname: '/sqllab', state: { requestedQuery: { datasourceKey: mockProps.datasource, @@ -152,7 +153,7 @@ test('opens SQL Lab in a new tab when View in SQL Lab button is clicked with met const { datasource, sql } = mockProps; expect(window.open).toHaveBeenCalledWith( - `/sqllab?datasourceKey=${datasource}&sql=${sql}`, + `/sqllab?datasourceKey=${datasource}&sql=${encodeURIComponent(sql)}`, '_blank', ); }); diff --git a/superset-frontend/src/explore/components/controls/ViewQuery.tsx b/superset-frontend/src/explore/components/controls/ViewQuery.tsx index 804ca879975..bc39051ecfa 100644 --- a/superset-frontend/src/explore/components/controls/ViewQuery.tsx +++ b/superset-frontend/src/explore/components/controls/ViewQuery.tsx @@ -133,11 +133,11 @@ const ViewQuery: FC = props => { if (domEvent.metaKey || domEvent.ctrlKey) { domEvent.preventDefault(); window.open( - `/sqllab?datasourceKey=${datasource}&sql=${currentSQL}`, + `/sqllab?datasourceKey=${datasource}&sql=${encodeURIComponent(currentSQL)}`, '_blank', ); } else { - history.push('/sqllab', { state: { requestedQuery } }); + history.push({ pathname: '/sqllab', state: { requestedQuery } }); } }, [history, datasource, currentSQL],