From 6aeae1b66d016fe1afcf437e3985fc1c4053050e Mon Sep 17 00:00:00 2001 From: Stanislaw Adaszewski Date: Tue, 11 Feb 2020 15:48:34 +0100 Subject: [PATCH] Implemented WBBrowseDialogUserList. --- .../js/dialog/wb-browse-dialog-user-list.js | 62 ++++++++++++++++++- frontend/src/js/dialog/wb-browse-dialog.js | 4 +- 2 files changed, 63 insertions(+), 3 deletions(-) diff --git a/frontend/src/js/dialog/wb-browse-dialog-user-list.js b/frontend/src/js/dialog/wb-browse-dialog-user-list.js index ed9ad21..ae85fad 100644 --- a/frontend/src/js/dialog/wb-browse-dialog-user-list.js +++ b/frontend/src/js/dialog/wb-browse-dialog-user-list.js @@ -1,11 +1,69 @@ import { h, Component } from 'preact'; +import WBTable from 'wb-table'; +import WBPagination from 'wb-pagination'; +import makeArvadosRequest from 'make-arvados-request'; class WBBrowseDialogUserList extends Component { - render() { + constructor(...args) { + super(...args); + this.state.rows = []; + } + + componentDidMount() { + this.fetchRows(); + } + + componentWillReceiveProps(nextProps) { + this.props = nextProps; + this.fetchRows(); + } + + prepareRows(items) { + const { navigate } = this.props; + return items.map(it => [ + ( + { e.preventDefault(); + navigate('/browse-dialog/browse/' + it.uuid); } }> + { it.last_name + ', ' + it.first_name } + + ), + it.uuid + ]); + } + + fetchRows() { + const { arvHost, arvToken } = this.props.app.state; + const { itemsPerPage, page, textSearch } = this.props; + const order = ['last_name asc', 'first_name asc']; + const filters = []; + if (textSearch) + filters.push([ 'any', 'ilike', '%' + textSearch + '%' ]); + let prom = makeArvadosRequest(arvHost, arvToken, + '/arvados/v1/users?order=' + + encodeURIComponent(JSON.stringify(order)) + + '&limit=' + itemsPerPage + + '&offset=' + (itemsPerPage * page)); + prom = prom.then(xhr => this.setState({ + 'rows': this.prepareRows(xhr.response.items), + 'numPages': Math.ceil(xhr.response.items_available / itemsPerPage) + })); + } + + render({ page, navigate }, { rows, numPages }) { return ( -
WBBrowseDialogUserList
+
+ + + navigate({ 'topPage': i }) } /> +
); } } +WBBrowseDialogUserList.defaultProps = { + 'itemsPerPage': 20 +}; + export default WBBrowseDialogUserList; diff --git a/frontend/src/js/dialog/wb-browse-dialog.js b/frontend/src/js/dialog/wb-browse-dialog.js index 7d8ce54..c557dcb 100644 --- a/frontend/src/js/dialog/wb-browse-dialog.js +++ b/frontend/src/js/dialog/wb-browse-dialog.js @@ -162,7 +162,9 @@ class WBBrowseDialog extends Component { ) : null } { (mode === 'users') ? ( - + this.navigate(url) } + page={ topPage } textSearch={ textSearch }/> ) : null } { (mode === 'content') ? (