// // Copyright (C) Stanislaw Adaszewski, 2020 // Contact: s.adaszewski@gmail.com // Website: https://adared.ch/wba // License: GNU Affero General Public License, Version 3 // import { h, Component } from 'preact'; import WBTable from 'wb-table'; import WBNameAndUuid from 'wb-name-and-uuid'; import wbFetchObjects from 'wb-fetch-objects'; import wbFormatDate from 'wb-format-date'; class WBToolboxDialog extends Component { constructor(...args) { super(...args); this.state.rows = []; this.state.selectedValues = {}; } componentDidMount() { this.fetchRows(); } componentWillReceiveProps(nextProps) { this.props = nextProps; this.fetchRows(); } fetchRows() { const { items, id, selectMany, onAccepted } = this.props; const { arvHost, arvToken } = this.props.app.state; const { selectedValues } = this.state; let prom = wbFetchObjects(arvHost, arvToken, items); let lookup; prom = prom.then(lkup => (lookup = lkup)); prom = prom.then(() => wbFetchObjects(arvHost, arvToken, items.map(uuid => lookup[uuid].owner_uuid))); let ownerLookup; prom = prom.then(lkup => (ownerLookup = lkup)); prom = prom.then(() => { const rows = items.map((uuid, idx) => { const it = lookup[uuid]; const ow = ownerLookup[it.owner_uuid]; let r = []; if (selectMany) r.push(); r = r.concat([ selectMany ? (
{ if (e.target.value === 'on') selectedValues[uuid] = true; else delete selectedValues[uuid]; } } /> { '\u00A0' }
) : ( ), ( $('#' + id).modal('hide') } /> ), it.kind, wbFormatDate(it.created_at), ( $('#' + id).modal('hide') } /> ) ]); return r; }); this.setState({ rows }); }); } render({ id, selectMany, onAccepted, items, app }, { rows, selectedValues }) { return ( ); } } WBToolboxDialog.defaultProps = { 'onAccepted': () => {} }; export default WBToolboxDialog;