-
Notifications
You must be signed in to change notification settings - Fork 12
/
FlagItem.jsx
58 lines (54 loc) · 1.74 KB
/
FlagItem.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import React from 'react'
import { ObjectInspector } from 'react-inspector'
import IconButton from 'cozy-ui/transpiled/react/IconButton'
import Icon from 'cozy-ui/transpiled/react/Icon'
import PenIcon from 'cozy-ui/transpiled/react/Icons/Pen'
import TrashIcon from 'cozy-ui/transpiled/react/Icons/Trash'
import ListItem from 'cozy-ui/transpiled/react/ListItem'
import ListItemText from 'cozy-ui/transpiled/react/ListItemText'
import ListItemSecondaryAction from 'cozy-ui/transpiled/react/ListItemSecondaryAction'
import Checkbox from 'cozy-ui/transpiled/react/Checkbox'
import ListItemIcon from 'cozy-ui/transpiled/react/ListItemIcon'
import flagUtils from 'cozy-flags'
const FlagItem = ({ flag, onEdit, onTrash }) => {
const handleCheckboxChange = e => {
flagUtils(flag.name, e.target.checked)
location.reload()
}
return (
<ListItem size="small">
<ListItemIcon>
{flag.type === 'boolean' ? (
<Checkbox
size="small"
checked={flag.value}
onChange={handleCheckboxChange}
/>
) : null}
</ListItemIcon>
<ListItemText
primary={flag.humanName}
secondary={
flag.type === 'object' ? (
<ObjectInspector data={flag.value} />
) : flag.type !== 'boolean' ? (
flag.humanValue
) : null
}
/>
<ListItemSecondaryAction>
<IconButton size="small" onClick={() => onEdit(flag)}>
<Icon icon={PenIcon} />
</IconButton>
<IconButton
className="u-ml-1"
size="small"
onClick={() => onTrash(flag)}
>
<Icon icon={TrashIcon} />
</IconButton>
</ListItemSecondaryAction>
</ListItem>
)
}
export default FlagItem