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.

82 lines
2.2KB

  1. import { h, Component } from 'preact';
  2. import makeArvadosRequest from 'make-arvados-request';
  3. import urlForObject from 'url-for-object';
  4. import arvadosObjectName from 'arvados-object-name';
  5. import arvadosTypeName from 'arvados-type-name';
  6. class WBNameAndUuid extends Component {
  7. componentDidMount() {
  8. let { uuid, app } = this.props;
  9. let { arvHost, arvToken } = app.state;
  10. if (!uuid)
  11. return;
  12. let prom = new Promise(accept => accept());
  13. if (/[0-9a-f]{32}\+[0-9]+/g.exec(uuid)) {
  14. let filters = [
  15. ['portable_data_hash', '=', uuid]
  16. ];
  17. prom = prom.then(() => makeArvadosRequest(arvHost, arvToken,
  18. '/arvados/v1/collections?filters=' +
  19. encodeURIComponent(JSON.stringify(filters))));
  20. prom = prom.then(xhr => {
  21. if (xhr.response.items.length === 0) {
  22. this.setState({
  23. 'item': {
  24. 'uuid': uuid,
  25. 'name': 'Collection with portable data hash ' + uuid
  26. }
  27. });
  28. return;
  29. }
  30. let item = xhr.response.items[0];
  31. if (xhr.response.items.length > 1)
  32. item.name += ' +' + (xhr.response.items.length - 1) + ' others';
  33. this.setState({ item });
  34. });
  35. } else if (/[a-z0-9]{5}-[a-z0-9]{5}-[a-z0-9]{15}/.exec(uuid)) {
  36. let typeName = arvadosTypeName(uuid);
  37. let prom = makeArvadosRequest(arvHost, arvToken,
  38. '/arvados/v1/' + typeName + 's/' + uuid );
  39. prom = prom.then(xhr => this.setState({
  40. 'item': xhr.response
  41. }));
  42. prom = prom.catch(xhr => this.setState({
  43. 'error': 'Unable to retrieve: ' + xhr.status + ' (' + xhr.statusText + ')'
  44. }));
  45. } else {
  46. this.setState({
  47. 'item': {
  48. 'uuid': uuid
  49. }
  50. });
  51. }
  52. }
  53. render({ uuid }, { error, item }) {
  54. if (!uuid)
  55. return (
  56. <div><i>{ String(uuid) }</i></div>
  57. );
  58. return (
  59. <div>
  60. <div>
  61. { error ? error : (item ? (
  62. <a href={ urlForObject(item) }>{ arvadosObjectName(item) }</a>
  63. ) : 'Loading...') }
  64. </div>
  65. <div>
  66. { uuid }
  67. </div>
  68. </div>
  69. );
  70. }
  71. }
  72. export default WBNameAndUuid;