-
Notifications
You must be signed in to change notification settings - Fork 12
/
ConceptHomeHeader.jsx
215 lines (209 loc) · 8.96 KB
/
ConceptHomeHeader.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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
import React from 'react';
import alertifyjs from 'alertifyjs';
import { Tooltip, ButtonGroup, Button, Collapse } from '@mui/material';
import {
Edit as EditIcon,
Delete as DeleteIcon,
RestoreFromTrash as RestoreIcon,
FileCopy as CopyIcon,
FormatIndentIncrease as HierarchyIcon,
} from '@mui/icons-material';
import { get } from 'lodash';
import { currentUserHasAccess, isLoggedIn, copyURL, toFullAPIURL, isAdminUser } from '../../common/utils';
import APIService from '../../services/APIService';
import OwnerButton from '../common/OwnerButton';
import SourceButton from '../common/SourceButton';
import ConceptButton from '../common/ConceptButton';
import VersionButton from '../common/VersionButton';
import LastUpdatedOnLabel from '../common/LastUpdatedOnLabel';
import ExternalIdLabel from '../common/ExternalIdLabel';
import CommonFormDrawer from '../common/CommonFormDrawer';
import DownloadButton from '../common/DownloadButton';
import AddToCollection from '../common/AddToCollection';
import CollapsibleDivider from '../common/CollapsibleDivider';
import ConceptIcon from './ConceptIcon';
import ConceptForm from './ConceptForm';
import ConceptDisplayName from './ConceptDisplayName';
const ConceptHomeHeader = ({
concept, mappings, isVersionedObject, versionedObjectURL, currentURL, hierarchy, onHierarchyClick,
header, tab
}) => {
const downloadFileName = isVersionedObject ?
`concept-${concept.id}` :
`concept-${concept.id}-version-${concept.version}`;
const isRetired = concept.retired;
const hasAccess = currentUserHasAccess();
const isAuthenticated = isLoggedIn();
const resourceRelativeURL = isVersionedObject ? concept.url : concept.version_url;
const [openHeader, setOpenHeader] = React.useState((!tab || tab === 0) && header);
const [conceptForm, setConceptForm] = React.useState(false);
const onRetire = () => {
const prompt = alertifyjs.prompt()
prompt.setContent('<form id="retireForm"> <p>Retire Reason</p> <textarea required id="comment" style="width: 100%;"></textarea> </form>')
prompt.set('onok', () => {
document.getElementById('retireForm').reportValidity();
const comment = document.getElementById('comment').value
if(!comment)
return false
retire(comment)
})
prompt.set('title', 'Retire Concept')
prompt.show()
}
const onUnretire = () => {
const prompt = alertifyjs
.prompt()
prompt.setContent('<form id="retireForm"> <p>Unretire Reason</p> <textarea required id="comment" style="width: 100%;"></textarea> </form>')
.set('onok', () => {
document.getElementById('retireForm').reportValidity();
const comment = document.getElementById('comment').value
if(!comment)
return false
unretire(comment)
})
.set('title', 'Unretire Concept')
.show()
}
const retire = comment => {
APIService.new().overrideURL(versionedObjectURL).delete({comment: comment}).then(response => {
if(get(response, 'status') === 204)
alertifyjs.success('Concept Retired', 1, () => window.location.reload())
else
alertifyjs.error('Something bad happened!')
})
}
const unretire = comment => {
APIService.new().overrideURL(versionedObjectURL).appendToUrl('reactivate/').put({comment: comment}).then(response => {
if(get(response, 'status') === 204)
alertifyjs.success('Concept UnRetired', 1, () => window.location.reload())
else
alertifyjs.error('Something bad happened!')
})
}
const onIconClick = () => copyURL(toFullAPIURL(encodeURI(currentURL)))
return (
<header className='home-header col-md-12'>
<div className='col-md-12 no-side-padding container' style={{paddingTop: '10px'}}>
<ConceptIcon shrink={!openHeader} />
<div className='col-md-11' style={{width: '95%', marginBottom: '5px'}}>
<div className='col-md-12 no-side-padding flex-vertical-center'>
<OwnerButton {...concept} href={versionedObjectURL} />
<span className='separator'>/</span>
<SourceButton label={concept.source} childURI={versionedObjectURL} />
<span className='separator'>/</span>
<ConceptButton label={concept.id} retired={isRetired} href={`#${encodeURI(versionedObjectURL)}`} />
{
!isVersionedObject &&
<React.Fragment>
<span className='separator'>/</span>
<VersionButton label={concept.version} retired={isRetired} href={`#${encodeURI(currentURL)}`} />
</React.Fragment>
}
<span style={{marginLeft: '15px'}}>
<ButtonGroup variant='text' size='large'>
<Tooltip arrow title="Copy URL">
<Button onClick={onIconClick} color='secondary' >
<CopyIcon fontSize="inherit" />
</Button>
</Tooltip>
{
hasAccess && isVersionedObject &&
<Tooltip arrow title='Edit Concept'>
<Button onClick={() => setConceptForm(true)} color='secondary'>
<EditIcon fontSize='inherit' />
</Button>
</Tooltip>
}
{
hasAccess && isVersionedObject &&
(
isRetired ?
<Tooltip arrow title='Un-Retire Concept'>
<Button onClick={onUnretire} color='secondary'>
<RestoreIcon fontSize='inherit' />
</Button>
</Tooltip> :
<Tooltip arrow title='Retire Concept'>
<Button onClick={onRetire} color='secondary'>
<DeleteIcon fontSize='inherit' />
</Button>
</Tooltip>
)
}
{
isAuthenticated &&
<AddToCollection
references={[{...concept, url: resourceRelativeURL}]}
iconButton
/>
}
{
isAdminUser() &&
<Tooltip arrow title={hierarchy ? 'Hide Hierarchy' : 'Show Hierarchy (Beta)'}>
<Button onClick={onHierarchyClick} color={hierarchy ? 'primary' : 'secondary'}>
<HierarchyIcon fontSize='inherit' />
</Button>
</Tooltip>
}
<DownloadButton resource={{...concept, mappings: mappings}} filename={downloadFileName} queryParams={{includeInverseMappings: true, includeHierarchyPath: true, includeParentConceptURLs: true}} />
</ButtonGroup>
</span>
</div>
<div className='col-md-12 no-side-padding flex-vertical-center' style={{paddingTop: '5px'}}>
<ConceptDisplayName concept={concept} style={{marginRight: '10px'}} />
</div>
<Collapse in={openHeader} className='col-md-12 no-side-padding' style={{padding: '0px', display: `${openHeader ? 'block' : 'none'}`}}>
<div className='col-md-12 no-side-padding flex-vertical-center'>
<span className='italic' style={{marginRight: '3px'}}>
Class:
</span>
<span>
{concept.concept_class},
</span>
<span className='italic' style={{marginLeft: '5px', marginRight: '3px'}}>
Datatype:
</span>
<span>
{concept.datatype}
</span>
</div>
<div className='col-md-12 no-side-padding flex-vertical-center' style={{marginTop: '2px'}}>
<span>
<LastUpdatedOnLabel
date={concept.updated_on}
by={concept.updated_by}
iconSize='medium'
noContainerClass
/>
</span>
<span style={{marginLeft: '10px'}}>
<LastUpdatedOnLabel
label='Created'
date={concept.created_on}
by={concept.created_by}
iconSize='medium'
noContainerClass
/>
</span>
{
concept.external_id &&
<span style={{marginLeft: '10px', marginTop: '-8px'}}>
<ExternalIdLabel externalId={concept.external_id} iconSize='medium' />
</span>
}
</div>
</Collapse>
</div>
<CollapsibleDivider open={openHeader} onClick={() => setOpenHeader(!openHeader)} light />
</div>
<CommonFormDrawer
isOpen={conceptForm}
onClose={() => setConceptForm(false)}
formComponent={
<ConceptForm edit reloadOnSuccess onCancel={() => setConceptForm(false)} concept={concept} parentURL={versionedObjectURL} />
}
/>
</header>
)
}
export default ConceptHomeHeader;