Skip to content

Commit 5ab1e7e

Browse files
authored
feat(sqllab): SPA migration (apache#25151)
1 parent af661ce commit 5ab1e7e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+518
-361
lines changed

superset-frontend/cypress-base/cypress/e2e/sqllab/_skip.sourcePanel.index.test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import { selectResultsTab } from './sqllab.helper';
2020

2121
describe.skip('SqlLab datasource panel', () => {
2222
beforeEach(() => {
23-
cy.visit('/superset/sqllab');
23+
cy.visit('/sqllab');
2424
});
2525

2626
// TODO the test bellow is flaky, and has been disabled for the time being

superset-frontend/cypress-base/cypress/e2e/sqllab/query.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ function parseClockStr(node: JQuery) {
2525

2626
describe('SqlLab query panel', () => {
2727
beforeEach(() => {
28-
cy.visit('/superset/sqllab');
28+
cy.visit('/sqllab');
2929
});
3030

3131
it.skip('supports entering and running a query', () => {

superset-frontend/cypress-base/cypress/e2e/sqllab/sqllab.applitools.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
describe('SqlLab view', () => {
2121
beforeEach(() => {
22-
cy.visit('/superset/sqllab');
22+
cy.visit('/sqllab');
2323
});
2424

2525
it('should load the SqlLab', () => {

superset-frontend/cypress-base/cypress/e2e/sqllab/tabs.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
*/
1919
describe('SqlLab query tabs', () => {
2020
beforeEach(() => {
21-
cy.visit('/superset/sqllab');
21+
cy.visit('/sqllab');
2222
});
2323

2424
const tablistSelector = '[data-test="sql-editor-tabs"] > [role="tablist"]';

superset-frontend/package-lock.json

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

superset-frontend/spec/helpers/reducerIndex.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ import messageToasts from 'src/components/MessageToasts/reducers';
2929
import saveModal from 'src/explore/reducers/saveModalReducer';
3030
import explore from 'src/explore/reducers/exploreReducer';
3131
import sqlLab from 'src/SqlLab/reducers/sqlLab';
32-
import localStorageUsageInKilobytes from 'src/SqlLab/reducers/localStorageUsage';
3332
import reports from 'src/features/reports/ReportModal/reducer';
3433
import getBootstrapData from 'src/utils/getBootstrapData';
3534

@@ -59,7 +58,7 @@ export default {
5958
saveModal,
6059
explore,
6160
sqlLab,
62-
localStorageUsageInKilobytes,
61+
localStorageUsageInKilobytes: noopReducer(0),
6362
reports,
6463
common: noopReducer(common),
6564
user: noopReducer(user),

superset-frontend/src/SqlLab/App.jsx

-84
This file was deleted.

superset-frontend/src/SqlLab/components/AceEditorWrapper/useKeywords.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import { schemaApiUtil } from 'src/hooks/apiResources/schemas';
2828
import { tableApiUtil } from 'src/hooks/apiResources/tables';
2929
import { addTable } from 'src/SqlLab/actions/sqlLab';
3030
import { initialState } from 'src/SqlLab/fixtures';
31-
import { reducers } from 'src/SqlLab/reducers';
31+
import reducers from 'spec/helpers/reducerIndex';
3232
import {
3333
SCHEMA_AUTOCOMPLETE_SCORE,
3434
TABLE_AUTOCOMPLETE_SCORE,

superset-frontend/src/SqlLab/components/App/App.test.jsx

+4-1
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,13 @@
1717
* under the License.
1818
*/
1919
import React from 'react';
20+
import { combineReducers } from 'redux';
2021
import configureStore from 'redux-mock-store';
2122
import thunk from 'redux-thunk';
2223
import { render } from 'spec/helpers/testing-library';
2324

2425
import App from 'src/SqlLab/components/App';
25-
import sqlLabReducer from 'src/SqlLab/reducers/index';
26+
import reducers from 'spec/helpers/reducerIndex';
2627
import { LOCALSTORAGE_MAX_USAGE_KB } from 'src/SqlLab/constants';
2728
import { LOG_EVENT } from 'src/logger/actions';
2829
import {
@@ -37,6 +38,8 @@ jest.mock('src/SqlLab/components/QueryAutoRefresh', () => () => (
3738
<div data-test="mock-query-auto-refresh" />
3839
));
3940

41+
const sqlLabReducer = combineReducers(reducers);
42+
4043
describe('SqlLab App', () => {
4144
const middlewares = [thunk];
4245
const mockStore = configureStore(middlewares);

superset-frontend/src/SqlLab/components/App/index.jsx

+9-3
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ import React from 'react';
2020
import PropTypes from 'prop-types';
2121
import { bindActionCreators } from 'redux';
2222
import { connect } from 'react-redux';
23+
import { Redirect } from 'react-router-dom';
2324
import { css, styled, t } from '@superset-ui/core';
2425
import throttle from 'lodash/throttle';
25-
import ToastContainer from 'src/components/MessageToasts/ToastContainer';
2626
import {
2727
LOCALSTORAGE_MAX_USAGE_KB,
2828
LOCALSTORAGE_WARNING_THRESHOLD,
@@ -186,7 +186,14 @@ class App extends React.PureComponent {
186186
render() {
187187
const { queries, queriesLastUpdate } = this.props;
188188
if (this.state.hash && this.state.hash === '#search') {
189-
return window.location.replace('/superset/sqllab/history/');
189+
return (
190+
<Redirect
191+
to={{
192+
pathname: '/sqllab/history/',
193+
replace: true,
194+
}}
195+
/>
196+
);
190197
}
191198
return (
192199
<SqlLabStyles data-test="SqlLabApp" className="App SqlLab">
@@ -195,7 +202,6 @@ class App extends React.PureComponent {
195202
queriesLastUpdate={queriesLastUpdate}
196203
/>
197204
<TabbedSqlEditors />
198-
<ToastContainer />
199205
</SqlLabStyles>
200206
);
201207
}

superset-frontend/src/SqlLab/components/QueryTable/index.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ interface QueryTableProps {
6161
}
6262

6363
const openQuery = (id: number) => {
64-
const url = `/superset/sqllab?queryId=${id}`;
64+
const url = `/sqllab?queryId=${id}`;
6565
window.open(url);
6666
};
6767

superset-frontend/src/SqlLab/components/SqlEditor/SqlEditor.test.jsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import React from 'react';
2020
import { act } from 'react-dom/test-utils';
2121
import { fireEvent, render, waitFor } from 'spec/helpers/testing-library';
2222
import fetchMock from 'fetch-mock';
23-
import { reducers } from 'src/SqlLab/reducers';
23+
import reducers from 'spec/helpers/reducerIndex';
2424
import SqlEditor from 'src/SqlLab/components/SqlEditor';
2525
import { setupStore } from 'src/views/store';
2626
import {

superset-frontend/src/SqlLab/components/SqlEditorLeftBar/SqlEditorLeftBar.test.jsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import SqlEditorLeftBar from 'src/SqlLab/components/SqlEditorLeftBar';
2626
import { table, initialState, defaultQueryEditor } from 'src/SqlLab/fixtures';
2727
import { api } from 'src/hooks/apiResources/queryApi';
2828
import { setupStore } from 'src/views/store';
29-
import { reducers } from 'src/SqlLab/reducers';
29+
import reducers from 'spec/helpers/reducerIndex';
3030

3131
const mockedProps = {
3232
tables: [table],

superset-frontend/src/SqlLab/components/TabbedSqlEditors/TabbedSqlEditors.test.jsx

+4-10
Original file line numberDiff line numberDiff line change
@@ -110,23 +110,17 @@ describe('TabbedSqlEditors', () => {
110110
it('should handle id', async () => {
111111
uriStub.returns({ id: 1 });
112112
await mountWithAct();
113-
expect(window.history.replaceState.getCall(0).args[2]).toBe(
114-
'/superset/sqllab',
115-
);
113+
expect(window.history.replaceState.getCall(0).args[2]).toBe('/sqllab');
116114
});
117115
it('should handle savedQueryId', async () => {
118116
uriStub.returns({ savedQueryId: 1 });
119117
await mountWithAct();
120-
expect(window.history.replaceState.getCall(0).args[2]).toBe(
121-
'/superset/sqllab',
122-
);
118+
expect(window.history.replaceState.getCall(0).args[2]).toBe('/sqllab');
123119
});
124120
it('should handle sql', async () => {
125121
uriStub.returns({ sql: 1, dbid: 1 });
126122
await mountWithAct();
127-
expect(window.history.replaceState.getCall(0).args[2]).toBe(
128-
'/superset/sqllab',
129-
);
123+
expect(window.history.replaceState.getCall(0).args[2]).toBe('/sqllab');
130124
});
131125
it('should handle custom url params', async () => {
132126
uriStub.returns({
@@ -137,7 +131,7 @@ describe('TabbedSqlEditors', () => {
137131
});
138132
await mountWithAct();
139133
expect(window.history.replaceState.getCall(0).args[2]).toBe(
140-
'/superset/sqllab?custom_value=str&extra_attr1=true',
134+
'/sqllab?custom_value=str&extra_attr1=true',
141135
);
142136
});
143137
});

superset-frontend/src/SqlLab/components/TabbedSqlEditors/index.jsx

+4-1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import { detectOS } from 'src/utils/common';
2929
import * as Actions from 'src/SqlLab/actions/sqlLab';
3030
import { EmptyStateBig } from 'src/components/EmptyState';
3131
import getBootstrapData from 'src/utils/getBootstrapData';
32+
import { locationContext } from 'src/pages/SqlLab/LocationContext';
3233
import SqlEditor from '../SqlEditor';
3334
import SqlEditorTabHeader from '../SqlEditorTabHeader';
3435

@@ -75,7 +76,7 @@ const userOS = detectOS();
7576
class TabbedSqlEditors extends React.PureComponent {
7677
constructor(props) {
7778
super(props);
78-
const sqlLabUrl = '/superset/sqllab';
79+
const sqlLabUrl = '/sqllab';
7980
this.state = {
8081
sqlLabUrl,
8182
};
@@ -132,6 +133,7 @@ class TabbedSqlEditors extends React.PureComponent {
132133
new: isNewQuery,
133134
...urlParams
134135
} = {
136+
...this.context.requestedQuery,
135137
...bootstrapData.requested_query,
136138
...queryParameters,
137139
};
@@ -332,6 +334,7 @@ class TabbedSqlEditors extends React.PureComponent {
332334
}
333335
TabbedSqlEditors.propTypes = propTypes;
334336
TabbedSqlEditors.defaultProps = defaultProps;
337+
TabbedSqlEditors.contextType = locationContext;
335338

336339
function mapStateToProps({ sqlLab, common }) {
337340
return {

superset-frontend/src/SqlLab/index.tsx

-23
This file was deleted.

superset-frontend/src/SqlLab/reducers/common.js

-21
This file was deleted.

superset-frontend/src/SqlLab/reducers/localStorageUsage.js

-21
This file was deleted.

0 commit comments

Comments
 (0)