You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@superset.apache.org by GitBox <gi...@apache.org> on 2018/08/06 18:02:25 UTC

[GitHub] williaster commented on a change in pull request #5524: A tagging system for dashboards, charts and queries

williaster commented on a change in pull request #5524: A tagging system for dashboards, charts and queries
URL: https://github.com/apache/incubator-superset/pull/5524#discussion_r207976623
 
 

 ##########
 File path: superset/assets/src/components/ObjectTags.jsx
 ##########
 @@ -0,0 +1,122 @@
+import React from 'react';
+import PropTypes from 'prop-types';
+import ReactTags from 'react-tag-autocomplete';
+import { Glyphicon, Label } from 'react-bootstrap';
+import TooltipWrapper from './TooltipWrapper';
+
+import './ObjectTags.css';
+
+import { t } from '../locales';
+
+const propTypes = {
+  fetchTags: PropTypes.func,
+  fetchSuggestions: PropTypes.func,
+  deleteTag: PropTypes.func,
+  addTag: PropTypes.func,
+  editable: PropTypes.bool,
+  onChange: PropTypes.func,
+};
+
+const defaultProps = {
+  fetchTags: (callback) => { callback([]); },
+  fetchSuggestions: (callback) => { callback([]); },
+  deleteTag: (tag, callback) => { callback(); },
+  addTag: (tag, callback) => { callback(); },
+  editable: true,
+  onChange: () => {},
+};
+
+export default class ObjectTags extends React.Component {
+
+  constructor(props) {
+    super(props);
+    this.state = {
+      tags: [],
+      suggestions: [],
+    };
+  }
+
+  componentDidMount() {
+    this.props.fetchTags(tags => this.setState({ tags }));
+    this.props.fetchSuggestions(suggestions => this.setState({ suggestions }));
+  }
+
+  handleDelete(i) {
+    const tags = this.state.tags.slice(0);
+    const tag = tags.splice(i, 1)[0].name;
+    this.props.deleteTag(tag, () => this.setState({ tags }));
+    this.props.onChange(tags);
+  }
+
+  handleAddition(tag) {
+    const tags = [].concat(this.state.tags, tag);
+    this.props.addTag(tag.name, () => this.setState({ tags }));
+    this.props.onChange(tags);
+  }
+
+  renderEditableTags() {
+    const Tag = props => (
+      <Label bsStyle="info">
+        <a
+          href={`/superset/welcome?tags=${props.tag.name}#tags`}
+          className="deco-none"
+        >
+          {props.tag.name}
+        </a>
+        <TooltipWrapper
+          label="remove"
+          tooltip={t('Click to remove tag')}
+        >
+          <Glyphicon onClick={props.onDelete} glyph="remove" />
+        </TooltipWrapper>
+      </Label>
+    );
+    const {
+      fetchTags,
+      fetchSuggestions,
+      deleteTag,
+      addTag,
+      editable,
+      onChange,
+      ...rest } = this.props;
 
 Review comment:
   linting doesn't complain about rest props, you should have a new line here tho :) Can't wait until we get prettier in.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org