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_r208066031
##########
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;
+ return (
+ <ReactTags
+ {...rest}
+ tags={this.state.tags}
+ suggestions={this.state.suggestions}
+ handleDelete={this.handleDelete.bind(this)}
Review comment:
👍 I want to add a lint rule for this but will be a bit of work to replace
all of the existing instances.
----------------------------------------------------------------
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:
[email protected]
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]