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.

87 lines
3.0KB

  1. import { h, Component } from 'preact';
  2. import makeArvadosRequest from 'make-arvados-request';
  3. import WBTable from 'wb-table';
  4. import WBPagination from 'wb-pagination';
  5. import WBNameAndUuid from 'wb-name-and-uuid';
  6. import wbFetchObjects from 'wb-fetch-objects';
  7. import wbFormatDate from 'wb-format-date';
  8. import urlForObject from 'url-for-object';
  9. class WBWorkflowListing extends Component {
  10. constructor(...args) {
  11. super(...args);
  12. this.state.rows = [];
  13. this.state.numPages = 0;
  14. }
  15. componentDidMount() {
  16. this.fetchItems();
  17. }
  18. prepareRows(items, ownerLookup) {
  19. return items.map(item => [
  20. ( <WBNameAndUuid uuid={ item.uuid } lookup={ { [item.uuid]: item } } /> ),
  21. item.description,
  22. ( <WBNameAndUuid uuid={ item.owner_uuid } lookup={ ownerLookup } /> ),
  23. wbFormatDate(item.created_at),
  24. (<div>
  25. <a class="btn btn-outline-success mx-1 my-1" title="Launch"
  26. href={ urlForObject(item, 'launch') }><i class="fas fa-running"></i></a>
  27. <button class="btn btn-outline-primary mx-1 my-1" title="View"><i class="far fa-eye"></i></button>
  28. <button class="btn btn-outline-danger mx-1 my-1" title="Delete"><i class="fas fa-trash"></i></button>
  29. </div>)
  30. ]);
  31. }
  32. fetchItems() {
  33. const { arvHost, arvToken } = this.props.app.state;
  34. const { page, itemsPerPage, ownerUuid } = this.props;
  35. const filters = [];
  36. if (ownerUuid)
  37. filters.push([ 'owner_uuid', '=', ownerUuid ]);
  38. const select = ['uuid', 'name', 'description', 'owner_uuid', 'created_at'];
  39. let prom = makeArvadosRequest(arvHost, arvToken,
  40. '/arvados/v1/workflows?filters=' + encodeURIComponent(JSON.stringify(filters)) +
  41. '&select=' + encodeURIComponent(JSON.stringify(select)) +
  42. '&limit=' + encodeURIComponent(itemsPerPage) +
  43. '&offset=' + encodeURIComponent(itemsPerPage * page));
  44. let workflowResp;
  45. prom = prom.then(xhr => (workflowResp = xhr.response));
  46. prom = prom.then(() => wbFetchObjects(arvHost, arvToken,
  47. workflowResp.items.map(it => it.owner_uuid)));
  48. let ownerLookup;
  49. prom = prom.then(lookup => (ownerLookup = lookup));
  50. prom = prom.then(() =>
  51. this.setState({
  52. 'numPages': Math.ceil(workflowResp['items_available'] / workflowResp['limit']),
  53. 'rows': this.prepareRows(workflowResp.items, ownerLookup)
  54. }));
  55. }
  56. componentWillReceiveProps(nextProps, nextState) {
  57. this.props = nextProps;
  58. this.fetchItems();
  59. }
  60. render({ app, ownerUuid, page, getPageUrl }, { rows, numPages }) {
  61. return (
  62. <div>
  63. <WBTable columns={ [ 'Name', 'Description', 'Owner', 'Created At', 'Actions' ] }
  64. rows={ rows } />
  65. <WBPagination numPages={ numPages }
  66. activePage={ page }
  67. getPageUrl={ getPageUrl } />
  68. </div>
  69. );
  70. }
  71. }
  72. WBWorkflowListing.defaultProps = {
  73. 'itemsPerPage': 100,
  74. 'ownerUuid': null
  75. };
  76. export default WBWorkflowListing;