import { h, Component } from 'preact'; import WBTable from 'wb-table'; import WBBreadcrumbs from 'wb-breadcrumbs'; import { WBManifestReader } from 'wb-collection-manifest'; import makeArvadosRequest from 'make-arvados-request'; class WBCollectionContent extends Component { constructor(...args) { super(...args); this.state.rows = []; this.state.manifestReader = null; } getUrl(params) { let res = '/collection-browse/' + (params.uuid || this.props.uuid) + '/' + encodeURIComponent(params.collectionPath || this.props.collectionPath) + '/' + (params.page || this.props.page); return res; } componentDidMount() { let { arvHost, arvToken } = this.props.app.state; let { uuid } = this.props; let select = [ 'manifest_text' ]; let prom = makeArvadosRequest(arvHost, arvToken, '/arvados/v1/collections/' + uuid + '?select=' + encodeURIComponent(JSON.stringify(select))); prom = prom.then(xhr => { this.state.manifestReader = new WBManifestReader(xhr.response.manifest_text); this.prepareRows(); }); } componentWillReceiveProps(nextProps) { this.props = nextProps; this.prepareRows(); } prepareRows() { let { manifestReader } = this.state; let { collectionPath } = this.props; //path = path.split('/'); //path = [ '.' ].concat(path); let listing = manifestReader.listDirectory('.' + collectionPath); this.setState({ 'rows': listing.map(item => ( (item[0] === 'd') ? [ ({ item[1] }/), 'Directory', null, (
) ] : [ ({ item[1] }), 'File', filesize(item[2]), (
) ] )) }); } render({ collectionPath }, { rows }) { return (
); } } WBCollectionContent.defaultProps = { 'collectionPath': '', 'page': 0 }; export default WBCollectionContent;