import React from 'react'; import { RouteComponentProps } from 'react-router'; import { withRouter } from 'react-router-dom'; import Text from 'antd/lib/typography/Text'; import { Col, Row, Button, Icon, Progress, Dropdown, } from 'antd'; import moment from 'moment'; import ActionsMenu from '../actions-menu/actions-menu'; export interface TaskItemProps { installedTFAnnotation: boolean; installedAutoAnnotation: boolean; taskInstance: any; previewImage: string; dumpActivities: string[] | null; loadActivity: string | null; loaders: any[]; dumpers: any[]; deleted: boolean; onDeleteTask: (taskInstance: any) => void; onDumpAnnotation: (task: any, dumper: any) => void; onLoadAnnotation: (task: any, loader: any, file: File) => void; } class TaskItemComponent extends React.PureComponent { constructor(props: TaskItemProps & RouteComponentProps) { super(props); } private renderPreview() { return (
Preview
) } private renderDescription() { // Task info const task = this.props.taskInstance; const { id } = task; const owner = task.owner ? task.owner.username : null; const updated = moment(task.updatedDate).fromNow(); const created = moment(task.createdDate).format('MMMM Do YYYY'); // Get and truncate a task name const name = `${task.name.substring(0, 70)}${task.name.length > 70 ? '...' : ''}`; return ( {`${id} ${name}`}
{ owner ? <> Created { owner ? 'by ' + owner : '' } on {created}
: null } Last updated {updated} ) } private renderProgress() { const task = this.props.taskInstance; // Count number of jobs and performed jobs const numOfJobs = task.jobs.length; const numOfCompleted = task.jobs.filter( (job: any) => job.status === 'completed' ).length; // Progress appearence depends on number of jobs const progressColor = numOfCompleted === numOfJobs ? 'cvat-task-completed-progress': numOfCompleted ? 'cvat-task-progress-progress' : 'cvat-task-pending-progress'; return ( { numOfCompleted === numOfJobs ? Completed : numOfCompleted ? In Progress : Pending } {`${numOfCompleted} of ${numOfJobs} jobs`} ) } private renderNavigation() { const subMenuIcon = () => (); const { id } = this.props.taskInstance; return ( Actions ) } public render() { const style = {}; if (this.props.deleted) { (style as any).pointerEvents = 'none'; (style as any).opacity = 0.5; } return ( {this.renderPreview()} {this.renderDescription()} {this.renderProgress()} {this.renderNavigation()} ) }; } export default withRouter(TaskItemComponent);