From a14fb34cf87c6586ca9bc6b508e03281e0e89816 Mon Sep 17 00:00:00 2001 From: Maxime Beauchemin Date: Mon, 17 Apr 2017 21:15:28 -0700 Subject: [PATCH 1/5] Adding a stats footer to the dashboard view --- .../javascripts/components/TooltipWrapper.jsx | 21 +-- .../javascripts/components/UserImage.jsx | 61 +++++++++ .../javascripts/dashboard/Dashboard.jsx | 5 + .../dashboard/components/Footer.css | 21 +++ .../dashboard/components/Footer.jsx | 124 ++++++++++++++++++ .../profile/components/CreatedContent.jsx | 4 +- .../profile/components/Favorites.jsx | 4 +- .../profile/components/RecentActivity.jsx | 2 +- .../profile/components/UserInfo.jsx | 25 ++-- .../versions/cd8aba67c8b6_image_url.py | 24 ++++ ...8976cf2d39e_adding_dashboard_stat_index.py | 33 +++++ superset/models/core.py | 63 ++++++++- superset/models/helpers.py | 9 +- superset/templates/superset/dashboard.html | 1 + superset/views/core.py | 73 +++++++++-- 15 files changed, 426 insertions(+), 44 deletions(-) create mode 100644 superset/assets/javascripts/components/UserImage.jsx create mode 100644 superset/assets/javascripts/dashboard/components/Footer.css create mode 100644 superset/assets/javascripts/dashboard/components/Footer.jsx create mode 100644 superset/migrations/versions/cd8aba67c8b6_image_url.py create mode 100644 superset/migrations/versions/e8976cf2d39e_adding_dashboard_stat_index.py diff --git a/superset/assets/javascripts/components/TooltipWrapper.jsx b/superset/assets/javascripts/components/TooltipWrapper.jsx index b189041603de8..81737c688b841 100644 --- a/superset/assets/javascripts/components/TooltipWrapper.jsx +++ b/superset/assets/javascripts/components/TooltipWrapper.jsx @@ -5,7 +5,7 @@ import { slugify } from '../modules/utils'; const propTypes = { label: PropTypes.string.isRequired, - tooltip: PropTypes.node.isRequired, + tooltip: PropTypes.node, children: PropTypes.node.isRequired, placement: PropTypes.string, }; @@ -15,14 +15,17 @@ const defaultProps = { }; export default function TooltipWrapper({ label, tooltip, children, placement }) { - return ( - {tooltip}} - > - {children} - - ); + if (tooltip) { + return ( + {tooltip}} + > + {children} + + ); + } + return children; } TooltipWrapper.propTypes = propTypes; diff --git a/superset/assets/javascripts/components/UserImage.jsx b/superset/assets/javascripts/components/UserImage.jsx new file mode 100644 index 0000000000000..258fe7cb7568c --- /dev/null +++ b/superset/assets/javascripts/components/UserImage.jsx @@ -0,0 +1,61 @@ +import React from 'react'; +import PropTypes from 'prop-types'; +import Gravatar from 'react-gravatar'; + +import TooltipWrapper from './TooltipWrapper'; + +const propTypes = { + href: PropTypes.string, + user: PropTypes.object, + tooltip: PropTypes.node, + width: PropTypes.string, + height: PropTypes.string, + imgStyle: PropTypes.object, + showTooltip: PropTypes.bool, + linkToProfile: PropTypes.bool, +}; +const defaultProps = { + imgStyle: { borderRadius: 3 }, + linkToProfile: true, + showTooltip: true, +}; + +export default function UserImage(props) { + let tooltip; + if (props.showTooltip) { + tooltip = props.tooltip || props.user.username; + } + let href = props.href || '#'; + if (props.linkToProfile) { + href = `/superset/profile/${props.user.username}/`; + } + return ( + + + + {props.user.image_url ? + {tooltip + : + + } + + + + ); +} + +UserImage.propTypes = propTypes; +UserImage.defaultProps = defaultProps; diff --git a/superset/assets/javascripts/dashboard/Dashboard.jsx b/superset/assets/javascripts/dashboard/Dashboard.jsx index 8b0a0e1c69114..3f87647a369ae 100644 --- a/superset/assets/javascripts/dashboard/Dashboard.jsx +++ b/superset/assets/javascripts/dashboard/Dashboard.jsx @@ -6,6 +6,7 @@ import moment from 'moment'; import GridLayout from './components/GridLayout'; import Header from './components/Header'; +import Footer from './components/Footer'; import { appSetup } from '../common'; import AlertsWrapper from '../components/AlertsWrapper'; @@ -72,6 +73,10 @@ function initDashboardView(dashboard) { , document.getElementById('grid-container'), ); + render( +