You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by su...@apache.org on 2021/04/26 17:02:06 UTC
[superset] branch dashboard-spa created (now 8f9c8bd)
This is an automated email from the ASF dual-hosted git repository.
suddjian pushed a change to branch dashboard-spa
in repository https://gitbox.apache.org/repos/asf/superset.git.
at 8f9c8bd chore(dashboard): Integrate dashboard app into the SPA bundle
This branch includes the following new commits:
new 8f9c8bd chore(dashboard): Integrate dashboard app into the SPA bundle
The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
[superset] 01/01: chore(dashboard): Integrate dashboard app into
the SPA bundle
Posted by su...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
suddjian pushed a commit to branch dashboard-spa
in repository https://gitbox.apache.org/repos/asf/superset.git
commit 8f9c8bda423b1ca3cf39bf37f2d3601b04448b79
Author: David Aaron Suddjian <aa...@gmail.com>
AuthorDate: Mon Apr 26 09:28:14 2021 -0700
chore(dashboard): Integrate dashboard app into the SPA bundle
---
superset-frontend/src/components/Menu/Menu.tsx | 13 +++--
superset-frontend/src/dashboard/App.jsx | 5 +-
.../src/dashboard/containers/DashboardPage.tsx | 27 +++--------
superset-frontend/src/dashboard/index.jsx | 1 -
.../src/utils/queryParamConfig.test.ts | 45 +++++++++++++++++
superset-frontend/src/utils/queryParamConfig.ts | 28 +++++++++++
superset-frontend/src/views/App.tsx | 56 ++++++++++++----------
superset-frontend/src/views/routes.tsx | 10 ++++
superset-frontend/src/views/store.ts | 42 ++++++++++++++--
superset-frontend/webpack.config.js | 2 +-
superset/views/base.py | 2 +-
superset/views/core.py | 9 ++--
12 files changed, 177 insertions(+), 63 deletions(-)
diff --git a/superset-frontend/src/components/Menu/Menu.tsx b/superset-frontend/src/components/Menu/Menu.tsx
index 04a2cd0..b21e26f 100644
--- a/superset-frontend/src/components/Menu/Menu.tsx
+++ b/superset-frontend/src/components/Menu/Menu.tsx
@@ -17,11 +17,15 @@
* under the License.
*/
import React, { useState } from 'react';
-import { t, styled } from '@superset-ui/core';
+import { Link } from 'react-router-dom';
import { Nav, Navbar, NavItem } from 'react-bootstrap';
-import NavDropdown from 'src/components/NavDropdown';
+import { useQueryParam } from 'use-query-params';
+import { t, styled } from '@superset-ui/core';
+
import { Menu as DropdownMenu } from 'src/common/components';
-import { Link } from 'react-router-dom';
+import NavDropdown from 'src/components/NavDropdown';
+import { TruthyParam } from 'src/utils/queryParamConfig';
+
import MenuObject, {
MenuObjectProps,
MenuObjectChildProps,
@@ -158,6 +162,9 @@ export function Menu({
isFrontendRoute = () => false,
}: MenuProps) {
const [dropdownOpen, setDropdownOpen] = useState(false);
+ const [standalone] = useQueryParam('standalone', TruthyParam);
+
+ if (standalone) return <></>;
return (
<StyledHeader className="top" id="main-menu">
diff --git a/superset-frontend/src/dashboard/App.jsx b/superset-frontend/src/dashboard/App.jsx
index 43d00f5..2194d26 100644
--- a/superset-frontend/src/dashboard/App.jsx
+++ b/superset-frontend/src/dashboard/App.jsx
@@ -38,10 +38,7 @@ const App = ({ store }) => {
<DndProvider backend={HTML5Backend}>
<ThemeProvider theme={theme}>
<DynamicPluginProvider>
- <DashboardPage
- store={store}
- dashboardIdOrSlug={dashboardIdOrSlug}
- />
+ <DashboardPage dashboardIdOrSlug={dashboardIdOrSlug} />
</DynamicPluginProvider>
</ThemeProvider>
</DndProvider>
diff --git a/superset-frontend/src/dashboard/containers/DashboardPage.tsx b/superset-frontend/src/dashboard/containers/DashboardPage.tsx
index 6e391e0..06aac3d 100644
--- a/superset-frontend/src/dashboard/containers/DashboardPage.tsx
+++ b/superset-frontend/src/dashboard/containers/DashboardPage.tsx
@@ -18,8 +18,8 @@
*/
import React, { useEffect, useState, FC } from 'react';
import { useDispatch } from 'react-redux';
+import { useParams } from 'react-router-dom';
import Loading from 'src/components/Loading';
-import ErrorBoundary from 'src/components/ErrorBoundary';
import {
useDashboard,
useDashboardCharts,
@@ -30,18 +30,13 @@ import { usePrevious } from 'src/common/hooks/usePrevious';
import { hydrateDashboard } from 'src/dashboard/actions/hydrate';
import DashboardContainer from 'src/dashboard/containers/Dashboard';
-interface DashboardRouteProps {
- dashboardIdOrSlug: string;
-}
-
-const DashboardPage: FC<DashboardRouteProps> = ({
- dashboardIdOrSlug, // eventually get from react router
-}) => {
+const DashboardPage: FC = () => {
const dispatch = useDispatch();
+ const { idOrSlug } = useParams<{ idOrSlug: string }>();
const [isLoaded, setLoaded] = useState(false);
- const dashboardResource = useDashboard(dashboardIdOrSlug);
- const chartsResource = useDashboardCharts(dashboardIdOrSlug);
- const datasetsResource = useDashboardDatasets(dashboardIdOrSlug);
+ const dashboardResource = useDashboard(idOrSlug);
+ const chartsResource = useDashboardCharts(idOrSlug);
+ const datasetsResource = useDashboardDatasets(idOrSlug);
const isLoading = [dashboardResource, chartsResource, datasetsResource].some(
resource => resource.status === ResourceStatus.LOADING,
);
@@ -79,12 +74,4 @@ const DashboardPage: FC<DashboardRouteProps> = ({
return <DashboardContainer />;
};
-const DashboardPageWithErrorBoundary = ({
- dashboardIdOrSlug,
-}: DashboardRouteProps) => (
- <ErrorBoundary>
- <DashboardPage dashboardIdOrSlug={dashboardIdOrSlug} />
- </ErrorBoundary>
-);
-
-export default DashboardPageWithErrorBoundary;
+export default DashboardPage;
diff --git a/superset-frontend/src/dashboard/index.jsx b/superset-frontend/src/dashboard/index.jsx
index 1a287c0..051c962 100644
--- a/superset-frontend/src/dashboard/index.jsx
+++ b/superset-frontend/src/dashboard/index.jsx
@@ -33,7 +33,6 @@ initFeatureFlags(bootstrapData.common.feature_flags);
const initialState = {
user: bootstrapData.user,
common: bootstrapData.common,
- datasources: bootstrapData.datasources,
};
const store = createStore(
diff --git a/superset-frontend/src/utils/queryParamConfig.test.ts b/superset-frontend/src/utils/queryParamConfig.test.ts
new file mode 100644
index 0000000..3d4dfa2
--- /dev/null
+++ b/superset-frontend/src/utils/queryParamConfig.test.ts
@@ -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 { TruthyParam } from './queryParamConfig';
+
+describe('url utils', () => {
+ describe('TruthyParam', () => {
+ // The behavior specified by this test is intended to preserve
+ // specific url parameters behavior.
+ it('decodes "true" to true', () => {
+ expect(TruthyParam.decode('true')).toEqual(true);
+ });
+ it('decodes "1" to true', () => {
+ expect(TruthyParam.decode('1')).toEqual(true);
+ });
+ it('decodes "false" to false', () => {
+ expect(TruthyParam.decode('false')).toEqual(false);
+ });
+ it('decodes "0" to false', () => {
+ expect(TruthyParam.decode('0')).toEqual(false);
+ });
+ it('encodes true', () => {
+ expect(TruthyParam.encode(true)).toEqual('true');
+ });
+ it('encodes false', () => {
+ expect(TruthyParam.encode(false)).toEqual('false');
+ });
+ });
+});
diff --git a/superset-frontend/src/utils/queryParamConfig.ts b/superset-frontend/src/utils/queryParamConfig.ts
new file mode 100644
index 0000000..8074664
--- /dev/null
+++ b/superset-frontend/src/utils/queryParamConfig.ts
@@ -0,0 +1,28 @@
+/**
+ * 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 { QueryParamConfig } from 'use-query-params';
+
+// Query parameters intended for use with the use-query-params hook
+
+/** A query param config for Superset's */
+export const TruthyParam: QueryParamConfig<boolean, any> = {
+ encode: (data?: any | null) => (data ? 'true' : undefined),
+ decode: (dataStr?: string | string[]) =>
+ dataStr !== 'false' && dataStr !== '0',
+};
diff --git a/superset-frontend/src/views/App.tsx b/superset-frontend/src/views/App.tsx
index babc03f..e36dd80 100644
--- a/superset-frontend/src/views/App.tsx
+++ b/superset-frontend/src/views/App.tsx
@@ -20,6 +20,8 @@ import React, { Suspense } from 'react';
import { hot } from 'react-hot-loader/root';
import { Provider as ReduxProvider } from 'react-redux';
import { BrowserRouter as Router, Switch, Route } from 'react-router-dom';
+import { DndProvider } from 'react-dnd';
+import { HTML5Backend } from 'react-dnd-html5-backend';
import { QueryParamProvider } from 'use-query-params';
import { initFeatureFlags } from 'src/featureFlags';
import { ThemeProvider } from '@superset-ui/core';
@@ -45,37 +47,43 @@ const menu = { ...bootstrap.common.menu_data };
const common = { ...bootstrap.common };
initFeatureFlags(bootstrap.common.feature_flags);
-const App = () => (
- <ReduxProvider store={store}>
- <ThemeProvider theme={theme}>
- <FlashProvider messages={common.flash_messages}>
- <Router>
+const RootContextProviders: React.FC = ({ children }) => (
+ <ThemeProvider theme={theme}>
+ <ReduxProvider store={store}>
+ <DndProvider backend={HTML5Backend}>
+ <FlashProvider messages={common.flash_messages}>
<DynamicPluginProvider>
<QueryParamProvider
ReactRouterRoute={Route}
stringifyOptions={{ encode: false }}
>
- <Menu data={menu} isFrontendRoute={isFrontendRoute} />
- <Switch>
- {routes.map(
- ({ path, Component, props = {}, Fallback = Loading }) => (
- <Route path={path} key={path}>
- <Suspense fallback={<Fallback />}>
- <ErrorBoundary>
- <Component user={user} {...props} />
- </ErrorBoundary>
- </Suspense>
- </Route>
- ),
- )}
- </Switch>
- <ToastPresenter />
+ {children}
</QueryParamProvider>
</DynamicPluginProvider>
- </Router>
- </FlashProvider>
- </ThemeProvider>
- </ReduxProvider>
+ </FlashProvider>
+ </DndProvider>
+ </ReduxProvider>
+ </ThemeProvider>
+);
+
+const App = () => (
+ <Router>
+ <RootContextProviders>
+ <Menu data={menu} isFrontendRoute={isFrontendRoute} />
+ <Switch>
+ {routes.map(({ path, Component, props = {}, Fallback = Loading }) => (
+ <Route path={path} key={path}>
+ <Suspense fallback={<Fallback />}>
+ <ErrorBoundary>
+ <Component user={user} {...props} />
+ </ErrorBoundary>
+ </Suspense>
+ </Route>
+ ))}
+ </Switch>
+ <ToastPresenter />
+ </RootContextProviders>
+ </Router>
);
export default hot(App);
diff --git a/superset-frontend/src/views/routes.tsx b/superset-frontend/src/views/routes.tsx
index f7de0c2..bbbd046 100644
--- a/superset-frontend/src/views/routes.tsx
+++ b/superset-frontend/src/views/routes.tsx
@@ -57,6 +57,12 @@ const DashboardList = lazy(
/* webpackChunkName: "DashboardList" */ 'src/views/CRUD/dashboard/DashboardList'
),
);
+const DashboardPage = lazy(
+ () =>
+ import(
+ /* webpackChunkName: "DashboardPage" */ 'src/dashboard/containers/DashboardPage'
+ ),
+);
const DatabaseList = lazy(
() =>
import(
@@ -105,6 +111,10 @@ export const routes: Routes = [
Component: DashboardList,
},
{
+ path: '/superset/dashboard/:idOrSlug/',
+ Component: DashboardPage,
+ },
+ {
path: '/chart/list/',
Component: ChartList,
},
diff --git a/superset-frontend/src/views/store.ts b/superset-frontend/src/views/store.ts
index c36d7d6..0fd4b4d 100644
--- a/superset-frontend/src/views/store.ts
+++ b/superset-frontend/src/views/store.ts
@@ -20,16 +20,48 @@ import { applyMiddleware, combineReducers, compose, createStore } from 'redux';
import thunk from 'redux-thunk';
import messageToastReducer from 'src/messageToasts/reducers';
import { initEnhancer } from 'src/reduxUtils';
+import charts from 'src/chart/chartReducer';
+import dataMask from 'src/dataMask/reducer';
+import dashboardInfo from 'src/dashboard/reducers/dashboardInfo';
+import dashboardState from 'src/dashboard/reducers/dashboardState';
+import dashboardFilters from 'src/dashboard/reducers/dashboardFilters';
+import nativeFilters from 'src/dashboard/reducers/nativeFilters';
+import datasources from 'src/dashboard/reducers/datasources';
+import sliceEntities from 'src/dashboard/reducers/sliceEntities';
+import dashboardLayout from 'src/dashboard/reducers/undoableDashboardLayout';
+
+// Some reducers don't do anything, and redux is just used to reference the initial "state".
+// This may change later, as the client application takes on more responsibilities.
+const noopReducer = <STATE = any>(initialState: STATE) => (
+ state: STATE = initialState,
+) => state;
const container = document.getElementById('app');
const bootstrap = JSON.parse(container?.getAttribute('data-bootstrap') ?? '{}');
-const common = { ...bootstrap.common };
+
+// reducers used only in the dashboard page
+const dashboardReducers = {
+ charts,
+ datasources,
+ dashboardInfo,
+ dashboardFilters,
+ dataMask,
+ nativeFilters,
+ dashboardState,
+ dashboardLayout,
+ sliceEntities,
+};
+
+const rootReducer = combineReducers({
+ messageToasts: messageToastReducer,
+ common: noopReducer(bootstrap.common),
+ user: noopReducer(bootstrap.user),
+ impressionId: noopReducer(''),
+ ...dashboardReducers,
+});
export const store = createStore(
- combineReducers({
- messageToasts: messageToastReducer,
- common: () => common,
- }),
+ rootReducer,
{},
compose(applyMiddleware(thunk), initEnhancer(false)),
);
diff --git a/superset-frontend/webpack.config.js b/superset-frontend/webpack.config.js
index a43d90a..368046b 100644
--- a/superset-frontend/webpack.config.js
+++ b/superset-frontend/webpack.config.js
@@ -205,7 +205,7 @@ const config = {
preamble: PREAMBLE,
addSlice: addPreamble('/src/addSlice/index.tsx'),
explore: addPreamble('/src/explore/index.jsx'),
- dashboard: addPreamble('/src/dashboard/index.jsx'),
+ // dashboard: addPreamble('/src/dashboard/index.jsx'),
sqllab: addPreamble('/src/SqlLab/index.tsx'),
crudViews: addPreamble('/src/views/index.tsx'),
menu: addPreamble('src/views/menu.tsx'),
diff --git a/superset/views/base.py b/superset/views/base.py
index 058e420..4f19435 100644
--- a/superset/views/base.py
+++ b/superset/views/base.py
@@ -272,7 +272,7 @@ class BaseSupersetView(BaseView):
def render_app_template(self) -> FlaskResponse:
payload = {
- "user": bootstrap_user_data(g.user),
+ "user": bootstrap_user_data(g.user, include_perms=True),
"common": common_bootstrap_payload(),
}
return self.render_template(
diff --git a/superset/views/core.py b/superset/views/core.py
index 95ba394..eda8975 100755
--- a/superset/views/core.py
+++ b/superset/views/core.py
@@ -1853,11 +1853,12 @@ class Superset(BaseSupersetView): # pylint: disable=too-many-public-methods
}
return self.render_template(
- "superset/dashboard.html",
- entry="dashboard",
+ "superset/crud_views.html",
+ entry="crudViews",
+ # entry="dashboard",
standalone_mode=standalone_mode,
- title=dashboard.dashboard_title,
- custom_css=dashboard.css,
+ # title=dashboard.dashboard_title,
+ # custom_css=dashboard.css,
bootstrap_data=json.dumps(
bootstrap_data, default=utils.pessimistic_json_iso_dttm_ser
),