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.

100 lines
2.7KB

  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. const filters = [
  42. ['uuid', '=', uuid]
  43. ];
  44. let prom = makeArvadosRequest(arvHost, arvToken,
  45. '/arvados/v1/' + typeName +
  46. 's?filters=' + encodeURIComponent(JSON.stringify(filters)));
  47. prom = prom.then(xhr => {
  48. const item = xhr.response.items[0];
  49. if (!item)
  50. this.setState({ 'error': 'Item not found' });
  51. else
  52. this.setState({
  53. 'item': item
  54. });
  55. });
  56. prom = prom.catch(xhr => {
  57. this.setState({
  58. 'error': 'Unable to retrieve: ' + xhr.status + ' (' + xhr.statusText + ')'
  59. });
  60. });
  61. } else {
  62. this.setState({
  63. 'item': {
  64. 'uuid': uuid
  65. }
  66. });
  67. }
  68. }
  69. render({ uuid }, { error, item }) {
  70. if (!uuid)
  71. return (
  72. <div><i>{ String(uuid) }</i></div>
  73. );
  74. return (
  75. <div>
  76. <div>
  77. { error ? error : (item ? (
  78. <a href={ urlForObject(item) }>{ arvadosObjectName(item) }</a>
  79. ) : 'Loading...') }
  80. </div>
  81. <div>
  82. { uuid }
  83. </div>
  84. </div>
  85. );
  86. }
  87. }
  88. export default WBNameAndUuid;