mistercrunch 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_r207069368
 
 

 ##########
 File path: superset/assets/src/welcome/Tags.jsx
 ##########
 @@ -0,0 +1,151 @@
+/* eslint no-unused-vars: 0 */
+import React from 'react';
+import ReactDOM from 'react-dom';
+import PropTypes from 'prop-types';
+import moment from 'moment';
+import { Table, Tr, Td, Thead, Th, unsafe } from 'reactable';
+import 'whatwg-fetch';
+
+import Loading from '../components/Loading';
+import '../../stylesheets/reactable-pagination.css';
+import { t } from '../locales';
+
+const $ = window.$ = require('jquery');
+
+const propTypes = {
+  search: PropTypes.string,
+};
+
+export function fetchTags(objectType, objectId, includeTypes, callback) {
+  const url = `/tagview/tags/${objectType}/${objectId}/`;
+  window.fetch(url)
+    .then(response => response.json())
+    .then(json => callback(
+      json.filter(tag => tag.name.indexOf(':') === -1 || includeTypes)));
+}
+
+export function fetchSuggestions(includeTypes, callback) {
+  window.fetch('/tagview/tags/suggestions/')
+    .then(response => response.json())
+    .then(json => callback(
+      json.filter(tag => tag.name.indexOf(':') === -1 || includeTypes)));
+}
+
+export function deleteTag(CSRF_TOKEN, objectType, objectId, tag, callback, 
error) {
+  const url = `/tagview/tags/${objectType}/${objectId}/`;
+  window.fetch(url, {
+    body: JSON.stringify([tag]),
+    headers: {
+      'content-type': 'application/json',
+      'X-CSRFToken': CSRF_TOKEN,
+    },
+    credentials: 'same-origin',
+    method: 'DELETE',
+  })
+  .then((response) => {
+    if (response.ok) {
+      callback(response);
+    } else {
+      error(response);
+    }
+  });
+}
+
+export function addTag(CSRF_TOKEN, objectType, objectId, includeTypes, tag, 
callback, error) {
+  if (tag.indexOf(':') !== -1 && !includeTypes) {
+    return;
+  }
+  const url = `/tagview/tags/${objectType}/${objectId}/`;
+  window.fetch(url, {
+    body: JSON.stringify([tag]),
+    headers: {
+      'content-type': 'application/json',
+      'X-CSRFToken': CSRF_TOKEN,
+    },
+    credentials: 'same-origin',
+    method: 'POST',
+  })
+  .then((response) => {
+    if (response.ok) {
+      callback(response);
+    } else {
+      error(response);
+    }
+  });
+}
+
+export class Tags extends React.PureComponent {
+  constructor(props) {
+    super(props);
+    this.state = {
+      objects: false,
+    };
+    this.fetchResults = this.fetchResults.bind(this);
+  }
+  componentDidMount() {
+    this.fetchResults(this.props.search);
+  }
+  componentWillReceiveProps(newProps) {
+    if (this.props.search !== newProps.search) {
+      this.fetchResults(newProps.search);
+    }
+  }
+  fetchResults(search) {
+    const url = `/tagview/tagged_objects/?tags=${search}`;
+    $.getJSON(url, (data) => {
+      const objects = { dashboard: [], chart: [], query: [] };
+      data.forEach((object) => {
+        objects[object.type].push(object);
+      });
+      this.setState({ objects });
+    });
+  }
+  renderTable(type) {
 
 Review comment:
   How about not rendering the table if it is empty?

----------------------------------------------------------------
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]

Reply via email to