Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: setup react page with submenu for datasources listview #10642

Merged
merged 9 commits into from
Aug 20, 2020
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,10 @@
* under the License.
*/
import React from 'react';
import { mount } from 'enzyme';
import thunk from 'redux-thunk';
import configureStore from 'redux-mock-store';
import fetchMock from 'fetch-mock';
import { supersetTheme, ThemeProvider } from '@superset-ui/style';
import { styledMount as mount } from 'spec/helpers/theming';

import DatasetList from 'src/views/CRUD/dataset/DatasetList';
import ListView from 'src/components/ListView';
Expand All @@ -30,7 +29,7 @@ import IndeterminateCheckbox from 'src/components/IndeterminateCheckbox';
import waitForComponentToPaint from 'spec/helpers/waitForComponentToPaint';
import { act } from 'react-dom/test-utils';

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

Expand Down Expand Up @@ -69,8 +68,6 @@ fetchMock.get(databaseEndpoint, {
async function mountAndWait(props) {
const mounted = mount(<DatasetList {...props} />, {
context: { store },
wrappingComponent: ThemeProvider,
wrappingComponentProps: { theme: supersetTheme },
});
await waitForComponentToPaint(mounted);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/**
* 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 DatasourceList from 'src/views/CRUD/datasource/DatasourceList';
import SubMenu from 'src/components/Menu/SubMenu';

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

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

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

it('renders a SubMenu', () => {
expect(wrapper.find(SubMenu)).toExist();
});
});
6 changes: 5 additions & 1 deletion superset-frontend/src/views/CRUD/dataset/DatasetList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,11 @@ const DatasetList: FunctionComponent<DatasetListProps> = ({
label: t('Datasets'),
url: '/tablemodelview/list/',
},
{ name: 'Databases', label: t('Databases'), url: '/databaseview/list/' },
{
name: 'Datasources',
label: t('Datasources'),
url: '/databaseview/list/',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I vote for moving to /database/list/. The "view" suffix is a FAB artifact from what the ModelView class was class.

},
{
name: 'Saved Queries',
label: t('Saved Queries'),
Expand Down
63 changes: 63 additions & 0 deletions superset-frontend/src/views/CRUD/datasource/DatasourceList.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/**
* 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 { t } from '@superset-ui/translation';
import React from 'react';

import withToasts from 'src/messageToasts/enhancers/withToasts';
import SubMenu, { SubMenuProps } from 'src/components/Menu/SubMenu';

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

function DatasourceList({
addDangerToast,
addSuccessToast,
}: DatasourceListProps) {
const menuData: SubMenuProps = {
activeChild: 'Datasources',
name: t('Data'),
children: [
{
name: 'Datasets',
label: t('Datasets'),
url: '/tablemodelview/list/',
},
{
name: 'Datasources',
label: t('Datasources'),
url: '/databaseview/list/',
},
{
name: 'Saved Queries',
label: t('Saved Queries'),
url: '/sqllab/my_queries/',
},
],
};

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

export default withToasts(DatasourceList);
6 changes: 6 additions & 0 deletions superset-frontend/src/welcome/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ 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/dataset/DatasetList';
import DatasourceList from 'src/views/CRUD/datasource/DatasourceList';

import messageToastReducer from '../messageToasts/reducers';
import { initEnhancer } from '../reduxUtils';
Expand Down Expand Up @@ -85,6 +86,11 @@ const App = () => (
<DatasetList user={user} />
</ErrorBoundary>
</Route>
<Route path="/databaseview/list/">
<ErrorBoundary>
<DatasourceList user={user} />
</ErrorBoundary>
</Route>
</Switch>
<ToastPresenter />
</QueryParamProvider>
Expand Down
1 change: 1 addition & 0 deletions superset/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,7 @@ def _try_json_readsha( # pylint: disable=unused-argument
"SIP_38_VIZ_REARCHITECTURE": False,
"TAGGING_SYSTEM": False,
"SQLLAB_BACKEND_PERSISTENCE": False,
"SIP_34_DATASOURCE_UI": False,
}

# This is merely a default.
Expand Down
16 changes: 15 additions & 1 deletion superset/views/database/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@
from typing import TYPE_CHECKING

from flask import flash, g, redirect
from flask_appbuilder import SimpleFormView
from flask_appbuilder import expose, SimpleFormView
from flask_appbuilder.models.sqla.interface import SQLAInterface
from flask_appbuilder.security.decorators import has_access
from flask_babel import lazy_gettext as _
from werkzeug.wrappers import Response
from wtforms.fields import StringField
Expand All @@ -31,7 +32,9 @@
from superset.connectors.sqla.models import SqlaTable
from superset.constants import RouteMethod
from superset.exceptions import CertificateException
from superset.extensions import feature_flag_manager
from superset.sql_parse import Table
from superset.typing import FlaskResponse
from superset.utils import core as utils
from superset.views.base import DeleteMixin, SupersetModelView, YamlExportMixin

Expand Down Expand Up @@ -93,6 +96,17 @@ class DatabaseView(
def _delete(self, pk: int) -> None:
DeleteMixin._delete(self, pk)

@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_DATASOURCE_UI")
):
return super().list()

return super().render_app_template()


class CsvToDatabaseView(SimpleFormView):
form = CsvToDatabaseForm
Expand Down