fix: navigate to SQL Lab due to router api updates (#34569)

(cherry picked from commit 53e9cf6d17)
This commit is contained in:
JUST.in DO IT
2025-08-06 07:54:10 -07:00
committed by Michael S. Molina
parent ab886db246
commit 2696d3e800
2 changed files with 5 additions and 4 deletions

View File

@@ -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',
);
});

View File

@@ -133,11 +133,11 @@ const ViewQuery: FC<ViewQueryProps> = 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],