1import { withStyles } from '@material-ui/core/styles'
2import TableCell from '@material-ui/core/TableCell/TableCell'
3import TableRow from '@material-ui/core/TableRow/TableRow'
4import Tooltip from '@material-ui/core/Tooltip/Tooltip'
5import Typography from '@material-ui/core/Typography'
6import ErrorOutline from '@material-ui/icons/ErrorOutline'
7import gql from 'graphql-tag'
8import React from 'react'
9import { Link } from 'react-router-dom'
10import * as moment from 'moment'
11
12const Open = ({className}) => <Tooltip title="Open">
13 <ErrorOutline nativeColor='#28a745' className={className}/>
14</Tooltip>
15
16const Closed = ({className}) => <Tooltip title="Closed">
17 <ErrorOutline nativeColor='#cb2431' className={className}/>
18</Tooltip>
19
20const Status = ({status, className}) => {
21 switch(status) {
22 case 'OPEN': return <Open className={className}/>
23 case 'CLOSED': return <Closed className={className}/>
24 default: return 'unknown status ' + status
25 }
26}
27
28const styles = theme => ({
29 cell: {
30 display: 'flex',
31 alignItems: 'center'
32 },
33 status: {
34 margin: 10
35 },
36 title: {
37 display: 'inline-block',
38 textDecoration: 'none'
39 },
40 labels: {
41 display: 'inline-block',
42 paddingLeft: theme.spacing.unit,
43 '&>span': {
44 padding: '0 4px',
45 margin: '0 1px',
46 backgroundColor: '#da9898',
47 borderRadius: '3px',
48 }
49 },
50})
51
52const BugSummary = ({bug, classes}) => (
53 <TableRow hover>
54 <TableCell className={classes.cell}>
55 <Status status={bug.status} className={classes.status}/>
56 <div>
57 <Link to={'bug/'+bug.humanId}>
58 <Typography variant={'title'} className={classes.title}>
59 {bug.title}
60 </Typography>
61 </Link>
62 <span className={classes.labels}>
63 {bug.labels.map(l => (
64 <span key={l}>{l}</span>)
65 )}
66 </span>
67 <Typography color={'textSecondary'}>
68 {bug.humanId} opened
69 <Tooltip title={moment(bug.createdAt).format('MMMM D, YYYY, h:mm a')}>
70 <span> {moment(bug.createdAt).fromNow()} </span>
71 </Tooltip>
72 by {bug.author.name}
73 </Typography>
74 </div>
75 </TableCell>
76 </TableRow>
77)
78
79BugSummary.fragment = gql`
80 fragment BugSummary on Bug {
81 id
82 humanId
83 title
84 status
85 createdAt
86 labels
87 author {
88 name
89 }
90 }
91`
92
93export default withStyles(styles)(BugSummary)