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: Better looking checkboxes (#3345)
Date Mon, 21 Aug 2017 20:47:54 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 2546457  Better looking checkboxes (#3345)
2546457 is described below

commit 254645773ccfcf5693237a15a8f123a4b0fd208a
Author: Maxime Beauchemin <maximebeauchemin@gmail.com>
AuthorDate: Mon Aug 21 13:47:50 2017 -0700

    Better looking checkboxes (#3345)
    
    Also showing icon only on hover on control headers
---
 .../components/InfoTooltipWithTrigger.jsx          |  10 +-
 .../javascripts/explore/components/Control.jsx     |  11 +-
 .../explore/components/ControlHeader.jsx           | 120 ++++++++++++---------
 .../components/controls/CheckboxControl.jsx        |  14 ++-
 superset/assets/package.json                       |   2 +-
 .../explore/components/CheckboxControl_spec.jsx    |   3 +-
 superset/assets/stylesheets/superset.less          |   3 +
 7 files changed, 100 insertions(+), 63 deletions(-)

diff --git a/superset/assets/javascripts/components/InfoTooltipWithTrigger.jsx b/superset/assets/javascripts/components/InfoTooltipWithTrigger.jsx
index 85bc7fb..709a216 100644
--- a/superset/assets/javascripts/components/InfoTooltipWithTrigger.jsx
+++ b/superset/assets/javascripts/components/InfoTooltipWithTrigger.jsx
@@ -9,15 +9,19 @@ const propTypes = {
   icon: PropTypes.string,
   className: PropTypes.string,
   onClick: PropTypes.func,
+  placement: PropTypes.string,
 };
 const defaultProps = {
-  icon: 'question-circle-o',
+  icon: 'info-circle',
+  className: 'text-muted',
+  placement: 'right',
 };
 
-export default function InfoTooltipWithTrigger({ label, tooltip, icon, className, onClick
}) {
+export default function InfoTooltipWithTrigger({
+    label, tooltip, icon, className, onClick, placement }) {
   return (
     <OverlayTrigger
-      placement="right"
+      placement={placement}
       overlay={<Tooltip id={`${slugify(label)}-tooltip`}>{tooltip}</Tooltip>}
     >
       <i
diff --git a/superset/assets/javascripts/explore/components/Control.jsx b/superset/assets/javascripts/explore/components/Control.jsx
index 6022b9f..4ff5af0 100644
--- a/superset/assets/javascripts/explore/components/Control.jsx
+++ b/superset/assets/javascripts/explore/components/Control.jsx
@@ -56,6 +56,7 @@ const defaultProps = {
 export default class Control extends React.PureComponent {
   constructor(props) {
     super(props);
+    this.state = { hovered: false };
     this.validate = this.validate.bind(this);
     this.onChange = this.onChange.bind(this);
   }
@@ -65,6 +66,9 @@ export default class Control extends React.PureComponent {
   onChange(value, errors) {
     this.validateAndSetValue(value, errors);
   }
+  setHover(hovered) {
+    this.setState({ hovered });
+  }
   validateAndSetValue(value, errors) {
     let validationErrors = this.props.validationErrors;
     let currentErrors = this.validate(value);
@@ -96,9 +100,14 @@ export default class Control extends React.PureComponent {
     const ControlType = controlMap[this.props.type];
     const divStyle = this.props.hidden ? { display: 'none' } : null;
     return (
-      <div style={divStyle}>
+      <div
+        style={divStyle}
+        onMouseEnter={this.setHover.bind(this, true)}
+        onMouseLeave={this.setHover.bind(this, false)}
+      >
         <ControlType
           onChange={this.onChange}
+          hovered={this.state.hovered}
           {...this.props}
         />
       </div>
diff --git a/superset/assets/javascripts/explore/components/ControlHeader.jsx b/superset/assets/javascripts/explore/components/ControlHeader.jsx
index 616092b..a79d287 100644
--- a/superset/assets/javascripts/explore/components/ControlHeader.jsx
+++ b/superset/assets/javascripts/explore/components/ControlHeader.jsx
@@ -10,74 +10,92 @@ const propTypes = {
   renderTrigger: PropTypes.bool,
   rightNode: PropTypes.node,
   leftNode: PropTypes.node,
+  onClick: PropTypes.func,
+  hovered: PropTypes.bool,
 };
 
 const defaultProps = {
   validationErrors: [],
   renderTrigger: false,
+  hovered: false,
 };
 
-export default function ControlHeader({
-    label, description, validationErrors, renderTrigger, leftNode, rightNode }) {
-  const hasError = (validationErrors.length > 0);
-  return (
-    <div>
-      <div className="pull-left">
-        <ControlLabel>
-          {hasError ?
-            <strong className="text-danger">{label}</strong> :
-            <span>{label}</span>
-          }
-          {' '}
-          {(validationErrors.length > 0) &&
+export default class ControlHeader extends React.Component {
+  renderOptionalIcons() {
+    if (this.props.hovered) {
+      return (
+        <span>
+          {this.props.description &&
             <span>
-              <OverlayTrigger
-                placement="right"
-                overlay={
-                  <Tooltip id={'error-tooltip'}>
-                    {validationErrors.join(' ')}
-                  </Tooltip>
-                }
-              >
-                <i className="fa fa-exclamation-circle text-danger" />
-              </OverlayTrigger>
+              <InfoTooltipWithTrigger
+                label="descr"
+                tooltip={this.props.description}
+                placement="top"
+              />
               {' '}
             </span>
           }
-          {description &&
+          {this.props.renderTrigger &&
             <span>
-              <InfoTooltipWithTrigger label={label} tooltip={description} />
+              <InfoTooltipWithTrigger
+                label="bolt"
+                tooltip={this.props.description}
+                placement="top"
+                icon="bolt"
+              />
               {' '}
             </span>
           }
-          {renderTrigger &&
-            <span>
-              <OverlayTrigger
-                placement="right"
-                overlay={
-                  <Tooltip id={'rendertrigger-tooltip'}>
-                    Takes effect on chart immediatly
-                  </Tooltip>
-                }
-              >
-                <i className="fa fa-bolt text-muted" />
-              </OverlayTrigger>
-              {' '}
+        </span>);
+    }
+    return null;
+  }
+  render() {
+    const labelClass = (this.props.validationErrors.length > 0) ? 'text-danger' : '';
+    return (
+      <div
+        className="ControlHeader"
+      >
+        <div className="pull-left">
+          <ControlLabel>
+            {this.props.leftNode &&
+              <span>{this.props.leftNode}</span>
+            }
+            <span
+              onClick={this.props.onClick}
+              className={labelClass}
+              style={{ cursor: this.props.onClick ? 'pointer' : '' }}
+            >
+              {this.props.label}
             </span>
-          }
-          {leftNode &&
-            <span>{leftNode}</span>
-          }
-        </ControlLabel>
-      </div>
-      {rightNode &&
-        <div className="pull-right">
-          {rightNode}
+            {' '}
+            {(this.props.validationErrors.length > 0) &&
+              <span>
+                <OverlayTrigger
+                  placement="top"
+                  overlay={
+                    <Tooltip id={'error-tooltip'}>
+                      {this.props.validationErrors.join(' ')}
+                    </Tooltip>
+                  }
+                >
+                  <i className="fa fa-exclamation-circle text-danger" />
+                </OverlayTrigger>
+                {' '}
+              </span>
+            }
+            {this.renderOptionalIcons()}
+          </ControlLabel>
         </div>
-      }
-      <div className="clearfix" />
-    </div>
-  );
+        {this.props.rightNode &&
+          <div className="pull-right">
+            {this.props.rightNode}
+          </div>
+        }
+        <div className="clearfix" />
+      </div>
+    );
+  }
 }
 
 ControlHeader.propTypes = propTypes;
diff --git a/superset/assets/javascripts/explore/components/controls/CheckboxControl.jsx b/superset/assets/javascripts/explore/components/controls/CheckboxControl.jsx
index bb5d2ce..fa70c18 100644
--- a/superset/assets/javascripts/explore/components/controls/CheckboxControl.jsx
+++ b/superset/assets/javascripts/explore/components/controls/CheckboxControl.jsx
@@ -1,6 +1,5 @@
 import React from 'react';
 import PropTypes from 'prop-types';
-import { Checkbox } from 'react-bootstrap';
 import ControlHeader from '../ControlHeader';
 
 const propTypes = {
@@ -24,11 +23,16 @@ export default class CheckboxControl extends React.Component {
     return (
       <ControlHeader
         {...this.props}
+        onClick={this.onToggle.bind(this)}
         leftNode={
-          <Checkbox
-            checked={this.props.value}
-            onChange={this.onToggle.bind(this)}
-          />
+          <span>
+            <i
+              className={`fa fa-check ${this.props.value ? 'text-primary' : 'text-transparent'}`}
+              onClick={this.onToggle.bind(this)}
+              style={{ border: '1px solid #aaa', borderRadius: '2px', cursor: 'pointer' }}
+            />
+            &nbsp;&nbsp;
+          </span>
         }
       />
     );
diff --git a/superset/assets/package.json b/superset/assets/package.json
index d22381b..9cf9673 100644
--- a/superset/assets/package.json
+++ b/superset/assets/package.json
@@ -66,7 +66,7 @@
     "react-addons-css-transition-group": "^15.6.0",
     "react-addons-shallow-compare": "^15.4.2",
     "react-alert": "^1.0.14",
-    "react-bootstrap": "^0.31.0",
+    "react-bootstrap": "^0.31.2",
     "react-bootstrap-table": "^3.1.7",
     "react-dom": "^15.5.1",
     "react-gravatar": "^2.6.1",
diff --git a/superset/assets/spec/javascripts/explore/components/CheckboxControl_spec.jsx
b/superset/assets/spec/javascripts/explore/components/CheckboxControl_spec.jsx
index 0b08397..23e58ac 100644
--- a/superset/assets/spec/javascripts/explore/components/CheckboxControl_spec.jsx
+++ b/superset/assets/spec/javascripts/explore/components/CheckboxControl_spec.jsx
@@ -1,6 +1,5 @@
 /* eslint-disable no-unused-expressions */
 import React from 'react';
-import { Checkbox } from 'react-bootstrap';
 import sinon from 'sinon';
 import { expect } from 'chai';
 import { describe, it, beforeEach } from 'mocha';
@@ -28,6 +27,6 @@ describe('CheckboxControl', () => {
     expect(controlHeader).to.have.lengthOf(1);
 
     const headerWrapper = controlHeader.shallow();
-    expect(headerWrapper.find(Checkbox)).to.have.length(1);
+    expect(headerWrapper.find('i.fa-check')).to.have.length(1);
   });
 });
diff --git a/superset/assets/stylesheets/superset.less b/superset/assets/stylesheets/superset.less
index fcdece9..87ba288 100644
--- a/superset/assets/stylesheets/superset.less
+++ b/superset/assets/stylesheets/superset.less
@@ -329,3 +329,6 @@ iframe {
     border: none;
     width: 100%;
 }
+.text-transparent {
+    color: transparent;
+}

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

Mime
View raw message