michael-s-molina commented on code in PR #25151:
URL: https://github.com/apache/superset/pull/25151#discussion_r1313394096


##########
superset-frontend/src/SqlLab/components/App/index.jsx:
##########
@@ -186,7 +186,14 @@ class App extends React.PureComponent {
   render() {
     const { queries, queriesLastUpdate } = this.props;
     if (this.state.hash && this.state.hash === '#search') {
-      return window.location.replace('/superset/sqllab/history/');
+      return (
+        <Redirect
+          to={{
+            pathname: '/superset/sqllab/history/',

Review Comment:
   ```suggestion
               pathname: '/sqllab/history/',
   ```



##########
superset-frontend/src/pages/SavedQueryList/index.tsx:
##########
@@ -187,11 +185,11 @@ function SavedQueryList({
 
   subMenuButtons.push({
     name: (
-      <>
+      <Link to="/sqllab?new=true">
         <i className="fa fa-plus" /> {t('Query')}
-      </>
+      </Link>
     ),
-    onClick: openNewQuery,
+    onClick: () => {},

Review Comment:
   Do we need to set the `onClick` to a no-op or can we omit this?



##########
superset/models/core.py:
##########
@@ -492,6 +492,8 @@ def _get_sqla_engine(
                     source = utils.QuerySource.DASHBOARD
                 elif "/explore/" in request.referrer:
                     source = utils.QuerySource.CHART
+                elif "/sqllab/" in request.referrer:
+                    source = utils.QuerySource.SQL_LAB
                 elif "/superset/sqllab" in request.referrer:

Review Comment:
   Do we need to preserve the old `/superset/sqllab`?



##########
superset-frontend/src/pages/SqlLab/SqlLab.test.tsx:
##########
@@ -0,0 +1,99 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+import fetchMock from 'fetch-mock';
+import React from 'react';
+import { omit } from 'lodash';
+import {
+  render,
+  act,
+  waitFor,
+  defaultStore as store,
+  createStore,
+} from 'spec/helpers/testing-library';
+import reducers from 'spec/helpers/reducerIndex';
+import { api } from 'src/hooks/apiResources/queryApi';
+import { DEFAULT_COMMON_BOOTSTRAP_DATA } from 'src/constants';
+import getInitialState from 'src/SqlLab/reducers/getInitialState';
+
+import SqlLab from '.';
+
+const fakeApiResult = {
+  result: {
+    common: DEFAULT_COMMON_BOOTSTRAP_DATA,
+    tab_state_ids: [],
+    databases: [],
+    queries: {},
+    user: {
+      userId: 1,
+      username: 'some name',
+      isActive: true,
+      isAnonymous: false,
+      firstName: 'first name',
+      lastName: 'last name',
+      permissions: {},
+      roles: {},
+    },
+  },
+};
+
+const expectedResult = fakeApiResult.result;
+const sqlLabInitialStateApiRoute = `glob:*/api/v1/sqllab/`;
+
+afterEach(() => {
+  fetchMock.reset();
+  act(() => {
+    store.dispatch(api.util.resetApiState());
+  });
+});
+
+beforeEach(() => {
+  fetchMock.get(sqlLabInitialStateApiRoute, fakeApiResult);
+});
+
+jest.mock('src/SqlLab/components/App', () => () => (
+  <div data-test="mock-sqllab-app" />
+));
+
+it('is valid', () => {

Review Comment:
   ```suggestion
   test('is valid', () => {
   ```



##########
tests/integration_tests/sqllab_tests.py:
##########
@@ -259,15 +259,15 @@ def test_sql_json_has_access(self):
     def test_sqllab_has_access(self):
         for username in ("admin", "gamma_sqllab"):
             self.login(username)
-            for endpoint in ("/superset/sqllab/", "/superset/sqllab/history/"):
+            for endpoint in ("/sqllab/", "/superset/sqllab/history/"):
                 resp = self.client.get(endpoint)
                 self.assertEqual(200, resp.status_code)
 
             self.logout()
 
     def test_sqllab_no_access(self):
         self.login("gamma")
-        for endpoint in ("/superset/sqllab/", "/superset/sqllab/history/"):
+        for endpoint in ("/sqllab/", "/superset/sqllab/history/"):

Review Comment:
   Can we move the history to `/sqllab/history` given that is under SPA? 



##########
tests/integration_tests/core_tests.py:
##########
@@ -1161,6 +1159,20 @@ def test_redirect_new_profile(self):
         resp = self.client.get("/superset/profile/")
         assert resp.status_code == 302
 
+    def test_redirect_new_sqllab(self):

Review Comment:
   Nice!



##########
superset-frontend/src/pages/SqlLab/SqlLab.test.tsx:
##########
@@ -0,0 +1,99 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+import fetchMock from 'fetch-mock';
+import React from 'react';
+import { omit } from 'lodash';
+import {
+  render,
+  act,
+  waitFor,
+  defaultStore as store,
+  createStore,
+} from 'spec/helpers/testing-library';
+import reducers from 'spec/helpers/reducerIndex';
+import { api } from 'src/hooks/apiResources/queryApi';
+import { DEFAULT_COMMON_BOOTSTRAP_DATA } from 'src/constants';
+import getInitialState from 'src/SqlLab/reducers/getInitialState';
+
+import SqlLab from '.';
+
+const fakeApiResult = {
+  result: {
+    common: DEFAULT_COMMON_BOOTSTRAP_DATA,
+    tab_state_ids: [],
+    databases: [],
+    queries: {},
+    user: {
+      userId: 1,
+      username: 'some name',
+      isActive: true,
+      isAnonymous: false,
+      firstName: 'first name',
+      lastName: 'last name',
+      permissions: {},
+      roles: {},
+    },
+  },
+};
+
+const expectedResult = fakeApiResult.result;
+const sqlLabInitialStateApiRoute = `glob:*/api/v1/sqllab/`;
+
+afterEach(() => {
+  fetchMock.reset();
+  act(() => {
+    store.dispatch(api.util.resetApiState());
+  });
+});
+
+beforeEach(() => {
+  fetchMock.get(sqlLabInitialStateApiRoute, fakeApiResult);
+});
+
+jest.mock('src/SqlLab/components/App', () => () => (
+  <div data-test="mock-sqllab-app" />
+));
+
+it('is valid', () => {
+  expect(React.isValidElement(<SqlLab />)).toBe(true);
+});
+
+it('fetches initial data and renders', async () => {

Review Comment:
   ```suggestion
   test('fetches initial data and renders', async () => {
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to