Skip to content

Commit

Permalink
feat: update saved query backend routing + add savedquery list (apach…
Browse files Browse the repository at this point in the history
…e#10922)

* Update saved query backend routing + add savedquery list

* add spec fileg

* add FE flag for SIP_34_SAVED_QUERIES_UI
  • Loading branch information
riahk authored and auxten committed Nov 20, 2020
1 parent 3adec64 commit e833f9f
Show file tree
Hide file tree
Showing 6 changed files with 116 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/**
* 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 React from 'react';
import thunk from 'redux-thunk';
import configureStore from 'redux-mock-store';
import { styledMount as mount } from 'spec/helpers/theming';
import SavedQueryList from 'src/views/CRUD/data/savedquery/SavedQueryList';
import SubMenu from 'src/components/Menu/SubMenu';
import waitForComponentToPaint from 'spec/helpers/waitForComponentToPaint';

// store needed for withToasts(DatabaseList)
const mockStore = configureStore([thunk]);
const store = mockStore({});

describe('SavedQueryList', () => {
const wrapper = mount(<SavedQueryList />, { context: { store } });

beforeAll(async () => {
await waitForComponentToPaint(wrapper);
});

it('renders', () => {
expect(wrapper.find(SavedQueryList)).toExist();
});

it('renders a SubMenu', () => {
expect(wrapper.find(SubMenu)).toExist();
});
});
1 change: 1 addition & 0 deletions superset-frontend/src/featureFlags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export enum FeatureFlag {
SHARE_QUERIES_VIA_KV_STORE = 'SHARE_QUERIES_VIA_KV_STORE',
SQLLAB_BACKEND_PERSISTENCE = 'SQLLAB_BACKEND_PERSISTENCE',
THUMBNAILS = 'THUMBNAILS',
SIP_34_SAVED_QUERIES_UI = 'SIP_34_SAVED_QUERIES_UI',
}

export type FeatureFlagMap = {
Expand Down
10 changes: 8 additions & 2 deletions superset-frontend/src/views/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ import FlashProvider from 'src/components/FlashProvider';
import DashboardList from 'src/views/CRUD/dashboard/DashboardList';
import ChartList from 'src/views/CRUD/chart/ChartList';
import DatasetList from 'src/views/CRUD/data/dataset/DatasetList';
import DatasourceList from 'src/views/CRUD/data/database/DatabaseList';
import DatabaseList from 'src/views/CRUD/data/database/DatabaseList';
import SavedQueryList from 'src/views/CRUD/data/savedquery/SavedQueryList';

import messageToastReducer from '../messageToasts/reducers';
import { initEnhancer } from '../reduxUtils';
Expand Down Expand Up @@ -88,7 +89,12 @@ const App = () => (
</Route>
<Route path="/databaseview/list/">
<ErrorBoundary>
<DatasourceList user={user} />
<DatabaseList user={user} />
</ErrorBoundary>
</Route>
<Route path="/savedqueryview/list/">
<ErrorBoundary>
<SavedQueryList user={user} />
</ErrorBoundary>
</Route>
</Switch>
Expand Down
5 changes: 3 additions & 2 deletions superset-frontend/src/views/CRUD/data/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
* under the License.
*/
import { t } from '@superset-ui/core';
import { isFeatureEnabled, FeatureFlag } from 'src/featureFlags';

export const commonMenuData = {
name: t('Data'),
Expand All @@ -36,8 +37,8 @@ export const commonMenuData = {
{
name: 'Saved Queries',
label: t('Saved Queries'),
url: '/sqllab/my_queries/',
usesRouter: false,
url: '/savedqueryview/list/',
usesRouter: isFeatureEnabled(FeatureFlag.SIP_34_SAVED_QUERIES_UI),
},
],
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/**
* 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 React from 'react';
import withToasts from 'src/messageToasts/enhancers/withToasts';
import SubMenu, { SubMenuProps } from 'src/components/Menu/SubMenu';
import { commonMenuData } from 'src/views/CRUD/data/common';

interface SavedQueryListProps {
addDangerToast: (msg: string) => void;
addSuccessToast: (msg: string) => void;
}

function SavedQueryList({
addDangerToast,
addSuccessToast,
}: SavedQueryListProps) {
const menuData: SubMenuProps = {
activeChild: 'Saved Queries',
...commonMenuData,
};

return (
<>
<SubMenu {...menuData} />
</>
);
}

export default withToasts(SavedQueryList);
14 changes: 13 additions & 1 deletion superset/views/sql_lab.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@
from flask_appbuilder.security.decorators import has_access, has_access_api
from flask_babel import lazy_gettext as _

from superset import db
from superset import app, db
from superset.constants import RouteMethod
from superset.extensions import feature_flag_manager
from superset.models.sql_lab import Query, SavedQuery, TableSchema, TabState
from superset.typing import FlaskResponse
from superset.utils import core as utils
Expand Down Expand Up @@ -75,6 +76,17 @@ class SavedQueryView(
"changed_on": _("Changed on"),
}

@expose("/list/")
@has_access
def list(self) -> FlaskResponse:
if not (
app.config["ENABLE_REACT_CRUD_VIEWS"]
and feature_flag_manager.is_feature_enabled("SIP_34_SAVED_QUERIES_UI")
):
return super().list()

return super().render_app_template()

def pre_add(self, item: "SavedQueryView") -> None:
item.user = g.user

Expand Down

0 comments on commit e833f9f

Please sign in to comment.