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!
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

111 wiersze
2.9KB

  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. fetchData() {
  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. componentDidMount() {
  70. this.fetchData();
  71. }
  72. componentWillReceiveProps(nextProps) {
  73. if (this.props.uuid !== nextProps.uuid) {
  74. this.props = nextProps;
  75. this.fetchData();
  76. }
  77. }
  78. render({ uuid, onLinkClicked }, { error, item }) {
  79. if (!uuid)
  80. return (
  81. <div><i>{ String(uuid) }</i></div>
  82. );
  83. return (
  84. <div>
  85. <div>
  86. { error ? error : (item ? (
  87. <a href={ urlForObject(item) } onclick={ onLinkClicked }>{ arvadosObjectName(item) }</a>
  88. ) : 'Loading...') }
  89. </div>
  90. <div>
  91. { uuid }
  92. </div>
  93. </div>
  94. );
  95. }
  96. }
  97. export default WBNameAndUuid;