import React from 'react'; import _ from 'lodash'; import { fromUnixTime, formatDistanceToNow } from "date-fns"; import { formatInTimeZone } from 'date-fns-tz' import constants, { DEFAULT_TIMEZONE } from '../CloudApi/Constants.js'; import * as ApiUtils from '../CloudApi/ApiUtils.js'; import WaxIdBitField from './WaxIdBitField.jsx'; import ToolPathDownloadButton from './ToolPathDownloadButton.jsx'; import { Segment, Modal, Header, Icon, Button, Table, Form, Divider, Label } from 'semantic-ui-react' import ClickableTableRow from '../Util/ClickableTableRow.jsx'; export default class JobsList extends React.Component { constructor(props) { super(props); this.state = { loading: false }; } async componentDidMount() { this.setState({ loading: true }); let schemas = await ApiUtils.getFabricatorSchemas(); this.setState({ schemas }); this.setState({ loading: false }); } renderJob(job) { const createdAtDateTime = fromUnixTime(Math.floor(job.createdAt / 1000)); const created = formatInTimeZone(createdAtDateTime, DEFAULT_TIMEZONE, 'PPp'); const waxId = (job.waxIdSnapshots && job.waxIdSnapshots.length > 0) ? job.waxIdSnapshots[0].id : ""; const updatedDateTime = fromUnixTime(Math.floor(_.last(job.history).createdAt / 1000)); const updated = formatInTimeZone(updatedDateTime, DEFAULT_TIMEZONE, 'PPp'); const AWAITING_MANUFACTURE = 11; const jobState = Object.entries(this.state.schemas.JobStates).find(entry => entry[1] === job.jobState)[0]; const machineIdHistory = _.last(_.filter(job.history, item => item.metaData && item.metaData.machineId && item.metaData.machineId.startsWith("cb"))); return ( {job.id} {job.name &&

(Name: {job.name})

} {job.nfcTagId &&

NFC Tag Id:

}
{created} {updated} {job.priority} {machineIdHistory &&

Machine Id:

} {(job.ipd > 0) &&

IPD:

}
{job.bigOrderId && }
) } render() { if (this.props.loading) { return ( ); } else if (this.state.schemas && this.props.jobs) { return ( Job # Created Last Updated State Priority WaxId (showing latest) Info Big Order {this.props.jobs.map(job => this.renderJob(job))}
) } return null; } }