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.

73 lines
2.2KB

  1. import { h, Component } from 'preact';
  2. import WBTable from 'wb-table';
  3. import WBPagination from 'wb-pagination';
  4. import makeArvadosRequest from 'make-arvados-request';
  5. class WBBrowseDialogCollectionList extends Component {
  6. constructor(...args) {
  7. super(...args);
  8. this.state.rows = [];
  9. }
  10. componentDidMount() {
  11. this.fetchRows();
  12. }
  13. componentWillReceiveProps(nextProps) {
  14. this.props = nextProps;
  15. this.fetchRows();
  16. }
  17. prepareRows(items) {
  18. const { navigate, selectWhat, makeSelectionCell } = this.props;
  19. return items.map(it => (selectWhat === 'directory' ? [
  20. makeSelectionCell(it.uuid)
  21. ] : []).concat([
  22. (
  23. <a href="#" onclick={ e => { e.preventDefault();
  24. navigate('/browse-dialog/content/' + it.uuid + '////'); } }>{ it.name }</a>
  25. ),
  26. it.uuid
  27. ]));
  28. }
  29. fetchRows() {
  30. const { arvHost, arvToken } = this.props.app.state;
  31. const { ownerUuid, textSearch, page, itemsPerPage } = this.props;
  32. const filters = [];
  33. if (ownerUuid)
  34. filters.push(['owner_uuid', '=', ownerUuid]);
  35. if (textSearch)
  36. filters.push(['name', 'ilike', '%' + textSearch + '%']);
  37. let prom = makeArvadosRequest(arvHost, arvToken,
  38. '/arvados/v1/collections?filters=' +
  39. encodeURIComponent(JSON.stringify(filters)) +
  40. '&limit=' + itemsPerPage +
  41. '&offset=' + (itemsPerPage * page));
  42. prom = prom.then(xhr => this.setState({
  43. 'rows': this.prepareRows(xhr.response.items),
  44. 'numPages': Math.ceil(xhr.response.items_available / itemsPerPage)
  45. }));
  46. return prom;
  47. }
  48. render({ selectWhat, page, navigate }, { rows, numPages }) {
  49. return (
  50. <div>
  51. <WBTable columns={ (selectWhat === 'directory' ? [''] : []).concat(['Name', 'UUID']) }
  52. headerClasses={ selectWhat === 'directory' ? ['col-sm-1', 'col-sm-4', 'col-sm-4'] : [] }
  53. rows={ rows } />
  54. <WBPagination activePage={ page } numPages={ numPages }
  55. onPageChanged={ i => navigate({ 'bottomPage': i }) } />
  56. </div>
  57. );
  58. }
  59. }
  60. WBBrowseDialogCollectionList.defaultProps = {
  61. 'itemsPerPage': 20
  62. };
  63. export default WBBrowseDialogCollectionList;