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.

88 lines
2.4KB

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