-
Notifications
You must be signed in to change notification settings - Fork 13
/
ManageSourceChildButton.jsx
151 lines (143 loc) · 5.26 KB
/
ManageSourceChildButton.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
import React from 'react';
import { Button, Menu, MenuList, MenuItem, ListItemIcon, ListItemText } from '@mui/material';
import {
Edit as EditIcon,
Delete as DeleteIcon,
RestoreFromTrash as RestoreIcon,
FileCopy as CopyIcon,
GetApp as DownloadIcon,
CompareArrows as CompareIcon,
ArrowDropDown as DownIcon,
BuildCircle as OperationsIcon,
} from '@mui/icons-material';
import { startCase } from 'lodash';
import { currentUserHasAccess, copyURL, toFullAPIURL, canViewOperationsPanel } from '../../common/utils';
import { ACTION_RED } from '../../common/constants';
import DownloadButton from './DownloadButton';
import { OperationsContext } from '../app/LayoutContext';
import BetaLabel from './BetaLabel';
const ManageSourceChildButton = ({
instance, currentURL, isVersionedObject, onEditClick, onRetire, onUnretire, mappings, resource, conceptCompareURL
}) => {
const {openOperations, setOpenOperations} = React.useContext(OperationsContext);
const [anchorEl, setAnchorEl] = React.useState(null);
const toggleMenu = event => setAnchorEl(anchorEl ? null : event.currentTarget)
const hasAccess = currentUserHasAccess();
const operationsPanelAccess = canViewOperationsPanel()
const onCopyClick = () => copyURL(toFullAPIURL(currentURL.replace('#', '')))
const onClick = (event, action) => {
setAnchorEl(null)
action(event)
}
const downloadFileName = isVersionedObject ?
`${resource}-${instance.id}` :
`${resource}-${instance.id}-version-${instance.version}`;
const isConcept = resource === 'concept'
const resourceLabel = startCase(resource)
const onCompareConceptsClick = event => {
event.stopPropagation()
event.preventDefault()
window.open(conceptCompareURL, '_blank')
}
const onOperationsClick = () => {
setAnchorEl(null)
setOpenOperations(!openOperations)
}
return (
<React.Fragment>
<Button variant='text' size='small' onClick={toggleMenu} color='default' style={{textTransform: 'none'}}>
Actions
<DownIcon style={{marginLeft: '4px'}} />
</Button>
<Menu
id="versions-menu"
anchorEl={anchorEl}
keepMounted
open={Boolean(anchorEl)}
onClose={toggleMenu}
>
<MenuList dense>
<MenuItem onClick={event => onClick(event, onCopyClick)}>
<ListItemIcon style={{minWidth: '28px'}}>
<CopyIcon fontSize="inherit" />
</ListItemIcon>
<ListItemText>
Copy URL
</ListItemText>
</MenuItem>
{
hasAccess && isVersionedObject &&
<MenuItem onClick={event => onClick(event, onEditClick)}>
<ListItemIcon style={{minWidth: '28px'}}>
<EditIcon fontSize="inherit" />
</ListItemIcon>
<ListItemText>
{
`Edit ${resourceLabel}`
}
</ListItemText>
</MenuItem>
}
{
conceptCompareURL &&
<MenuItem onClick={onCompareConceptsClick}>
<ListItemIcon style={{minWidth: '28px'}}>
<CompareIcon fontSize="inherit" />
</ListItemIcon>
<ListItemText>
Compare From/To Concepts
</ListItemText>
</MenuItem>
}
<DownloadButton
resource={isConcept ? {...instance, mappings: mappings} : instance}
filename={downloadFileName}
queryParams={isConcept ? {includeInverseMappings: true, includeHierarchyPath: true, includeParentConceptURLs: true} : null}
buttonFunc={params => (
<MenuItem {...params}>
<ListItemIcon style={{minWidth: '28px'}}>
<DownloadIcon fontSize="inherit" />
</ListItemIcon>
<ListItemText>
Download
</ListItemText>
</MenuItem>
)}
tooltipPlacement='right'
/>
{
instance.concept_class && operationsPanelAccess &&
<MenuItem onClick={onOperationsClick}>
<ListItemIcon style={{minWidth: '28px'}}>
<OperationsIcon fontSize="inherit" />
</ListItemIcon>
<ListItemText>
<BetaLabel label="Operations" />
</ListItemText>
</MenuItem>
}
{
hasAccess && isVersionedObject &&
<MenuItem onClick={event => onClick(event, instance.retired ? onUnretire : onRetire)}>
<ListItemIcon style={{minWidth: '28px', color: ACTION_RED}}>
{
instance.retired ?
<RestoreIcon fontSize='inherit' /> :
<DeleteIcon fontSize='inherit' />
}
</ListItemIcon>
<ListItemText style={{color: ACTION_RED}}>
{
instance.retired ?
`Un-Retire ${resourceLabel}` :
`Retire ${resourceLabel}`
}
</ListItemText>
</MenuItem>
}
</MenuList>
</Menu>
</React.Fragment>
)
}
export default ManageSourceChildButton;