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.

79 lines
2.1KB

  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. } else {
  43. this.setState({
  44. 'item': {
  45. 'uuid': uuid
  46. }
  47. });
  48. }
  49. }
  50. render({ uuid }, { item }) {
  51. if (!uuid)
  52. return (
  53. <div><i>{ String(uuid) }</i></div>
  54. );
  55. return (
  56. <div>
  57. <div>
  58. { item ? (
  59. <a href={ urlForObject(item) }>{ arvadosObjectName(item) }</a>
  60. ) : 'Loading...' }
  61. </div>
  62. <div>
  63. { uuid }
  64. </div>
  65. </div>
  66. );
  67. }
  68. }
  69. export default WBNameAndUuid;