import { h, Component } from 'preact'; import { route } from 'preact-router'; import makeArvadosRequest from 'make-arvados-request'; import WBTable from 'wb-table'; import WBPagination from 'wb-pagination'; import WBCheckboxes from 'wb-checkboxes'; class WBProcessListing extends Component { constructor(...args) { super(...args); this.state.rows = []; this.state.numPages = 0; this.state.requestStates = [ 'Uncommitted', 'Committed', 'Final' ]; this.state.containerStates = [ 'Queued', 'Locked', 'Running', 'Cancelled', 'Complete' ]; this.state.reqStateMask = [ true, true, true ]; this.state.contStateMask = [ true, true, true, true, true ]; } componentDidMount() { this.fetchItems(); } prepareRows(items) { return items.map(item => [ (
{ e.preventDefault(); route('/process/' + item['uuid']) }}>{ item['name'] }
{ item['uuid'] }
), item['state'], item['owner_uuid'], item['created_at'].replace('T', ' ').substr(0, item['created_at'].length - 11) + '', item['output_uuid'], (
) ]); } fetchItems() { let { arvHost, arvToken } = this.props.appState; let i = this.props.activePage; let filters = [ [ 'state', 'in', this.state.requestStates.filter((_, idx) => this.state.reqStateMask[idx]) ] ]; if (this.props.ownerUuid) filters.push([ 'owner_uuid', '=', this.props.ownerUuid ]); let prom = makeArvadosRequest(arvHost, arvToken, '/arvados/v1/container_requests?filters=' + encodeURIComponent(JSON.stringify(filters)) + '&limit=' + encodeURIComponent(this.props.itemsPerPage) + '&offset=' + encodeURIComponent(this.props.itemsPerPage * i)); prom = prom.then(xhr => this.setState({ 'numPages': Math.ceil(xhr.response['items_available'] / xhr.response['limit']), 'rows': this.prepareRows(xhr.response['items']) })); } componentWillReceiveProps(nextProps, nextState) { // this.setState({ 'rows': [] }); // .rows = []; this.props = nextProps; this.fetchItems(); } render({ appState, ownerUuid, activePage, onPageChanged }, { rows, numPages, requestStates, containerStates, reqStateMask, contStateMask }) { return (
this.fetchItems() } /> this.fetchItems() } /> onPageChanged(i) } />
); } } WBProcessListing.defaultProps = { 'itemsPerPage': 100, 'ownerUuid': null }; export default WBProcessListing;