superset-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From maximebeauche...@apache.org
Subject [incubator-superset] branch master updated: Use react-alert for backend message flashing (#3315)
Date Thu, 17 Aug 2017 06:00:26 GMT
This is an automated email from the ASF dual-hosted git repository.

maximebeauchemin pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-superset.git


The following commit(s) were added to refs/heads/master by this push:
     new 59268e9  Use react-alert for backend message flashing (#3315)
59268e9 is described below

commit 59268e978aa2753166371f790fa648ddaa398f52
Author: Maxime Beauchemin <maximebeauchemin@gmail.com>
AuthorDate: Wed Aug 16 23:00:23 2017 -0700

    Use react-alert for backend message flashing (#3315)
---
 .../assets/javascripts/SqlLab/components/App.jsx     |  4 +++-
 .../assets/javascripts/components/AlertsWrapper.jsx  | 20 ++++++++++++++++++++
 superset/assets/javascripts/dashboard/Dashboard.jsx  |  8 ++++++--
 superset/assets/javascripts/explore/index.jsx        |  3 +--
 superset/templates/superset/basic.html               |  1 -
 superset/templates/superset/dashboard.html           |  2 --
 superset/views/base.py                               | 12 +++++++++++-
 superset/views/core.py                               |  6 +++++-
 8 files changed, 46 insertions(+), 10 deletions(-)

diff --git a/superset/assets/javascripts/SqlLab/components/App.jsx b/superset/assets/javascripts/SqlLab/components/App.jsx
index 2a6eb41..2d45281 100644
--- a/superset/assets/javascripts/SqlLab/components/App.jsx
+++ b/superset/assets/javascripts/SqlLab/components/App.jsx
@@ -70,7 +70,7 @@ class App extends React.PureComponent {
     }
     return (
       <div className="App SqlLab">
-        <AlertsWrapper />
+        <AlertsWrapper initMessages={this.props.initMessages} />
         <div className="container-fluid">
           {content}
         </div>
@@ -82,11 +82,13 @@ class App extends React.PureComponent {
 App.propTypes = {
   alerts: PropTypes.array,
   actions: PropTypes.object,
+  initMessages: PropTypes.array,
 };
 
 function mapStateToProps(state) {
   return {
     alerts: state.alerts,
+    initMessages: state.flash_messages,
   };
 }
 function mapDispatchToProps(dispatch) {
diff --git a/superset/assets/javascripts/components/AlertsWrapper.jsx b/superset/assets/javascripts/components/AlertsWrapper.jsx
index bb3c2d6..672c56d 100644
--- a/superset/assets/javascripts/components/AlertsWrapper.jsx
+++ b/superset/assets/javascripts/components/AlertsWrapper.jsx
@@ -1,7 +1,25 @@
+/* global notify */
 import React from 'react';
 import AlertContainer from 'react-alert';
+import PropTypes from 'prop-types';
+
+const propTypes = {
+  initMessages: PropTypes.array,
+};
+const defaultProps = {
+  initMessages: [],
+};
 
 export default class AlertsWrapper extends React.PureComponent {
+  componentDidMount() {
+    this.props.initMessages.forEach((msg) => {
+      if (['info', 'error', 'success'].indexOf(msg[0]) >= 0) {
+        notify[msg[0]](msg[1]);
+      } else {
+        notify.show(msg[1]);
+      }
+    });
+  }
   render() {
     return (
       <AlertContainer
@@ -16,3 +34,5 @@ export default class AlertsWrapper extends React.PureComponent {
       />);
   }
 }
+AlertsWrapper.propTypes = propTypes;
+AlertsWrapper.defaultProps = defaultProps;
diff --git a/superset/assets/javascripts/dashboard/Dashboard.jsx b/superset/assets/javascripts/dashboard/Dashboard.jsx
index 283475a..7cc7699 100644
--- a/superset/assets/javascripts/dashboard/Dashboard.jsx
+++ b/superset/assets/javascripts/dashboard/Dashboard.jsx
@@ -18,7 +18,11 @@ const utils = require('../modules/utils');
 appSetup();
 
 export function getInitialState(boostrapData) {
-  const dashboard = Object.assign({}, utils.controllerInterface, boostrapData.dashboard_data);
+  const dashboard = Object.assign(
+    {},
+    utils.controllerInterface,
+    boostrapData.dashboard_data,
+    { common: boostrapData.common });
   dashboard.firstLoad = true;
 
   dashboard.posDict = {};
@@ -62,7 +66,7 @@ function renderAlert() {
 function initDashboardView(dashboard) {
   render(
     <div>
-      <AlertsWrapper />
+      <AlertsWrapper initMessages={dashboard.common.flash_messages} />
       <Header dashboard={dashboard} />
     </div>,
     document.getElementById('dashboard-header'),
diff --git a/superset/assets/javascripts/explore/index.jsx b/superset/assets/javascripts/explore/index.jsx
index 525f2c4..501002a 100644
--- a/superset/assets/javascripts/explore/index.jsx
+++ b/superset/assets/javascripts/explore/index.jsx
@@ -56,12 +56,11 @@ const initState = {
 const store = createStore(rootReducer, initState,
   compose(applyMiddleware(thunk), initEnhancer(false)),
 );
-
 ReactDOM.render(
   <Provider store={store}>
     <div>
       <ExploreViewContainer />
-      <AlertsWrapper />
+      <AlertsWrapper initMessages={bootstrappedState.common.flash_messages} />
     </div>
   </Provider>,
   exploreViewContainer,
diff --git a/superset/templates/superset/basic.html b/superset/templates/superset/basic.html
index 87b058d..ea7f5b1 100644
--- a/superset/templates/superset/basic.html
+++ b/superset/templates/superset/basic.html
@@ -41,7 +41,6 @@
     {% endblock %}
 
     {% block body %}
-      {% include 'superset/flash_wrapper.html' %}
       <div id="app" data-bootstrap="{{ bootstrap_data }}" >
         <img src="/static/assets/images/loading.gif" style="width: 50px; margin: 10px;">
       </div>
diff --git a/superset/templates/superset/dashboard.html b/superset/templates/superset/dashboard.html
index e297e51..d3e81f2 100644
--- a/superset/templates/superset/dashboard.html
+++ b/superset/templates/superset/dashboard.html
@@ -5,8 +5,6 @@
   class="dashboard container-fluid"
   data-bootstrap="{{ bootstrap_data }}"
 >
-  {% include 'superset/flash_wrapper.html' %}
-
   <div id="dashboard-header"></div>
 
   <!-- gridster class used for backwards compatibility -->
diff --git a/superset/views/base.py b/superset/views/base.py
index d036258..6974f71 100644
--- a/superset/views/base.py
+++ b/superset/views/base.py
@@ -3,7 +3,7 @@ import json
 import logging
 import traceback
 
-from flask import g, redirect, Response, flash, abort
+from flask import g, redirect, Response, flash, abort, get_flashed_messages
 from flask_babel import gettext as __
 from flask_babel import lazy_gettext as _
 
@@ -17,6 +17,8 @@ from superset import appbuilder, conf, db, utils, sm, sql_parse
 from superset.connectors.connector_registry import ConnectorRegistry
 from superset.connectors.sqla.models import SqlaTable
 
+FRONTEND_CONF_KEYS = ('SUPERSET_WEBSERVER_TIMEOUT',)
+
 
 def get_error_msg():
     if conf.get("SHOW_STACKTRACE"):
@@ -186,6 +188,14 @@ class BaseSupersetView(BaseView):
             full_names = {d.full_name for d in user_datasources}
             return [d for d in datasource_names if d in full_names]
 
+    def common_bootsrap_payload(self):
+        """Common data always sent to the client"""
+        messages = get_flashed_messages(with_categories=True)
+        return {
+            'flash_messages': messages,
+            'conf': {k: conf.get(k) for k in FRONTEND_CONF_KEYS},
+        }
+
 
 class SupersetModelView(ModelView):
     page_size = 100
diff --git a/superset/views/core.py b/superset/views/core.py
index 85aa460..98a0aa6 100755
--- a/superset/views/core.py
+++ b/superset/views/core.py
@@ -1087,6 +1087,7 @@ class Superset(BaseSupersetView):
             "standalone": standalone,
             "user_id": user_id,
             "forced_height": request.args.get('height'),
+            'common': self.common_bootsrap_payload(),
         }
         table_name = datasource.table_name \
             if datasource_type == 'table' \
@@ -1719,6 +1720,7 @@ class Superset(BaseSupersetView):
             'user_id': g.user.get_id(),
             'dashboard_data': dashboard_data,
             'datasources': {ds.uid: ds.data for ds in datasources},
+            'common': self.common_bootsrap_payload(),
         }
 
         return self.render_template(
@@ -2268,7 +2270,8 @@ class Superset(BaseSupersetView):
                 'email': user.email,
                 'roles': roles,
                 'permissions': permissions,
-            }
+            },
+            'common': self.common_bootsrap_payload(),
         }
         return self.render_template(
             'superset/basic.html',
@@ -2284,6 +2287,7 @@ class Superset(BaseSupersetView):
         """SQL Editor"""
         d = {
             'defaultDbId': config.get('SQLLAB_DEFAULT_DBID'),
+            'common': self.common_bootsrap_payload(),
         }
         return self.render_template(
             'superset/basic.html',

-- 
To stop receiving notification emails like this one, please contact
['"commits@superset.apache.org" <commits@superset.apache.org>'].

Mime
View raw message