diff --git a/frontend/src/js/dialog/wb-pick-object-dialog.js b/frontend/src/js/dialog/wb-pick-object-dialog.js new file mode 100644 index 0000000..07d3b5c --- /dev/null +++ b/frontend/src/js/dialog/wb-pick-object-dialog.js @@ -0,0 +1,111 @@ +import { h, Component, createRef } from 'preact'; +import WBDialog from 'wb-dialog'; +import WBTable from 'wb-table'; +import WBPagination from 'wb-pagination'; +import makeArvadosRequest from 'make-arvados-request'; +import arvadosObjectName from 'arvados-object-name'; + +class WBPickObjectDialog extends Component { + constructor(...args) { + super(...args); + this.state.title = 'WBPickObjectDialog'; + this.state.rows = []; + this.state.textSearch = null; + this.dialogRef = createRef(); + } + + show(title, objectType, accept, filters=[]) { + this.setState({ title, objectType, page: 0, rows: [], accept, filters, textSearch: null }); + this.dialogRef.current.show(); + this.fetchData(); + } + + hide() { + this.dialogRef.current.hide(); + } + + fetchData() { + const { app, itemsPerPage } = this.props; + const { arvHost, arvToken } = app.state; + const { objectType, page, textSearch } = this.state; + let { filters } = this.state; + if (textSearch) + filters = filters.concat([['any', 'ilike', '%' + textSearch + '%']]); + const order = (objectType === 'user') ? + ['last_name asc', 'first_name asc'] : + ['name asc']; + let prom = makeArvadosRequest(arvHost, arvToken, + '/arvados/v1/' + objectType + + 's?offset=' + (page * itemsPerPage) + + '&limit=' + itemsPerPage + + '&filters=' + encodeURIComponent(JSON.stringify(filters)) + + '&order=' + encodeURIComponent(JSON.stringify(order)) + ); + prom = prom.then(xhr => this.setState({ + numPages: Math.ceil(xhr.response.items_available / itemsPerPage), + rows: this.prepareRows(xhr.response.items) + })); + return prom; + } + + prepareRows(items) { + const { accept } = this.state; + const { dialogRef } = this; + + return items.map(it => [ + (