-
Notifications
You must be signed in to change notification settings - Fork 12
/
ScopeHeader.jsx
178 lines (173 loc) · 7.17 KB
/
ScopeHeader.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
import React from 'react';
import { Link } from 'react-router-dom';
import alertifyjs from 'alertifyjs';
import { IconButton, Chip, Tooltip } from '@mui/material';
import {
CancelOutlined as CancelIcon,
} from '@mui/icons-material';
import { get } from 'lodash';
import APIService from '../../services/APIService';
import { BLUE, BLACK } from '../../common/constants';
import LastUpdatedOnLabel from '../common/LastUpdatedOnLabel';
import ExternalIdLabel from '../common/ExternalIdLabel';
import CommonFormDrawer from '../common/CommonFormDrawer';
import ConceptIcon from './ConceptIcon';
import ConceptForm from './ConceptForm';
import ResourceTextBreadcrumbs from '../common/ResourceTextBreadcrumbs';
import HomeActionButton from '../common/SourceChildHomeActionButton';
const ScopeHeader = ({
concept, versionedObjectURL, header, onClose, global, scoped, showActions, isVersionedObject, mappings,
currentURL
}) => {
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 resourceURL = ((get(concept, 'versioned_object_id') || '').toString() === concept.uuid || concept.is_latest_version) ? concept.url : concept.version_url
return (
<header className='resource-header home-header col-xs-12' style={{paddingTop: '5px', paddingBottom: 0, position: 'fixed', zIndex: 2, paddingLeft: '5px'}}>
<div className='col-md-12 no-side-padding container' style={{lineHeight: 'normal'}}>
<div className="col-xs-12 no-side-padding">
{
(global || scoped === 'collection') && concept &&
<div className="col-xs-11 no-side-padding">
<ResourceTextBreadcrumbs style={{marginBottom: '5px', marginLeft: '5px'}} resource={concept} />
</div>
}
{
onClose &&
<span className='col-xs-1 no-side-padding' style={{display: 'block', textAlign: 'right', position: 'fixed', right: '10px', marginTop: '2px'}}>
<IconButton size='small' color='secondary' onClick={onClose}>
<CancelIcon fontSize='inherit' />
</IconButton>
</span>
}
</div>
<ConceptIcon shrink={false} style={{marginTop: '-10px', marginLeft: '5px'}} />
<div className='col-xs-11 no-side-padding'>
<div className='col-xs-12 no-side-padding' style={{fontSize: '20px'}}>
<Tooltip title="Navigate to this Concept under its Source" arrow placement="left">
<Link to={resourceURL} className="no-anchor-styles">
<React.Fragment>
<span style={{color: BLUE}}>
<b className='searchable'>{concept.id}</b>
</span>
<span style={{marginLeft: '5px', color: BLACK}}>
<b className='searchable'>{concept.display_name}</b>
</span>
</React.Fragment>
</Link>
</Tooltip>
{
concept.retired &&
<Chip className='retired-red' style={{marginLeft: '10px'}} size='small' label='Retired' />
}
{
showActions &&
<span style={{marginLeft: '15px'}}>
<HomeActionButton
instance={concept}
currentURL={currentURL}
isVersionedObject={isVersionedObject}
onEditClick={() => setConceptForm(true)}
onRetire={onRetire}
onUnretire={onUnretire}
mappings={mappings}
resource='concept'
/>
</span>
}
</div>
<div className='col-md-12 no-side-padding' style={{marginTop: '2px'}}>
<div className='col-md-12 no-side-padding flex-vertical-center'>
<span className='italic' style={{marginRight: '5px', color: '#707070'}}>
Class:
</span>
<span>
{concept.concept_class}
</span>
<span className='italic' style={{marginLeft: '15px', marginRight: '5px', color: '#707070'}}>
Datatype:
</span>
<span>
{concept.datatype}
</span>
</div>
<div className='col-md-12 no-side-padding flex-vertical-center' style={{marginTop: '2px'}}>
<LastUpdatedOnLabel
label='Created'
date={concept.created_on}
by={concept.created_by}
iconSize='medium'
noContainerClass
/>
</div>
<div className='col-md-12 no-side-padding flex-vertical-center' style={{marginTop: '-6px'}}>
<LastUpdatedOnLabel
date={concept.updated_on}
by={concept.updated_by}
iconSize='medium'
noContainerClass
/>
</div>
{
concept.external_id &&
<div className='col-md-12 no-side-padding flex-vertical-center' style={{marginTop: '-6px'}}>
<ExternalIdLabel externalId={concept.external_id} iconSize='medium' searchable />
</div>
}
</div>
</div>
</div>
<CommonFormDrawer
style={{zIndex: 1202}}
isOpen={conceptForm}
onClose={() => setConceptForm(false)}
formComponent={
<ConceptForm edit reloadOnSuccess onCancel={() => setConceptForm(false)} concept={concept} parentURL={versionedObjectURL} />
}
/>
</header>
)
}
export default ScopeHeader;