|
- import { h, Component } from 'preact';
- import makeArvadosRequest from 'make-arvados-request';
- import WBPagination from 'wb-pagination';
- import WBTable from 'wb-table';
-
- class WBBrowseDialogProjectList extends Component {
- constructor(...args) {
- super(...args);
- this.state.rows = [];
- }
-
- componentDidMount() {
- this.fetchRows();
- }
-
- componentWillReceiveProps(nextProps) {
- this.props = nextProps;
- this.setState({
- 'page': 0
- });
- this.fetchRows();
- }
-
- changePage(page) {
- this.setState({
- 'page': page
- });
- this.fetchRows();
- }
-
- prepareRows(items) {
- return items.map(it => [
- it.name,
- it.file_count,
- it.file_size_total
- ]);
- }
-
- fetchRows() {
- const { arvHost, arvToken } = this.props.app.state;
- const { textSearch, itemsPerPage } = this.props;
- const ownerUuid = ('ownerUuid' in this.state ?
- this.state.ownerUuid : this.props.ownerUuid);
- const { page } = this.state;
- const filters = [
- ['group_class', '=', 'project']
- ];
- if (ownerUuid)
- filters.push(['owner_uuid', '=', ownerUuid]);
- if (textSearch)
- filters.push(['name', 'ilike', '%' + textSearch + '%']);
- let prom = makeArvadosRequest(arvHost, arvToken,
- '/arvados/v1/groups?filters=' +
- encodeURIComponent(JSON.stringify(filters)) +
- '&limit=' + itemsPerPage +
- '&offset=' + (page * itemsPerPage));
- prom = prom.then(xhr => {
- this.setState({
- 'rows': this.prepareRows(xhr.response.items),
- 'numPages': xhr.response.items_available / itemsPerPage
- });
- });
- }
-
- render({ app }, { ownerUuid, textSearch, page, numPages, rows }) {
- return (
- <div>
- <WBTable columns={ ['Name', 'File Count', 'Size'] }
- rows={ rows } />
-
- <WBPagination numPages={ numPages } activePage={ page }
- onPageChanged={ i => this.changePage(i) } />
- </div>
- );
- }
- }
-
- WBBrowseDialogProjectList.defaultProps = {
- 'itemsPerPage': 5
- };
-
- export default WBBrowseDialogProjectList;
|