feat: update saved query backend routing + add savedquery list (#10922)

* Update saved query backend routing + add savedquery list

* add spec fileg

* add FE flag for SIP_34_SAVED_QUERIES_UI
This commit is contained in:
Moriah Kreeger
2020-09-16 21:08:40 -07:00
committed by GitHub
parent cd77797802
commit 5623cd64ca
6 changed files with 116 additions and 5 deletions

View File

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

View File

@@ -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 = {

View File

@@ -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';
@@ -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>

View File

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

View File

@@ -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);

View File

@@ -21,8 +21,9 @@ from flask_appbuilder.models.sqla.interface import SQLAInterface
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
@@ -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