IF YOU WOULD LIKE TO GET AN ACCOUNT, please write an email to s dot adaszewski at gmail dot com. User accounts are meant only to report issues and/or generate pull requests. This is a purpose-specific Git hosting for ADARED projects. Thank you for your understanding!
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

54 lines
1.4KB

  1. import { h, Component } from 'preact';
  2. import makeArvadosRequest from 'make-arvados-request';
  3. import { encodeURIComponentIncludingDots } from 'wb-process-misc';
  4. class WBPathDisplay extends Component {
  5. fetchData() {
  6. const { app } = this.props;
  7. const { arvHost, arvToken } = app.state;
  8. let { path } = this.props;
  9. if (path.endsWith('/'))
  10. path = path.substr(0, path.length - 1);
  11. let m;
  12. if (m = /^[0-9a-f]{32}\+[0-9]+/.exec(path));
  13. else if (m = /^[a-z0-9]{5}-[a-z0-9]{5}-[a-z0-9]{15}/.exec(path));
  14. else return;
  15. let prom = makeArvadosRequest(arvHost, arvToken,
  16. '/arvados/v1/collections/' + m[0]);
  17. prom = prom.then(xhr => this.setState({
  18. item: xhr.response,
  19. tail: path.substr(m[0].length)
  20. }));
  21. prom = prom.catch(() => this.setState({ 'error': 'Cannot load' }));
  22. }
  23. componentDidMount() {
  24. this.fetchData();
  25. }
  26. componentWillReceiveProps(nextProps) {
  27. this.props = nextProps;
  28. this.fetchData();
  29. }
  30. render({}, { item, tail, error }) {
  31. if (error)
  32. return error;
  33. if (!item)
  34. return 'Loading...';
  35. return (
  36. <span>
  37. <a href={ '/collection-browse/' + item.uuid }>
  38. { item.name || item.uuid }
  39. </a><a href={ '/collection-browse/' + item.uuid + '/' + encodeURIComponentIncludingDots(tail) }>
  40. { tail }
  41. </a>
  42. </span>
  43. );
  44. }
  45. }
  46. export default WBPathDisplay;