-
Notifications
You must be signed in to change notification settings - Fork 12
/
ReferenceCascadeDialog.jsx
212 lines (205 loc) · 9.14 KB
/
ReferenceCascadeDialog.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
import React from 'react';
import {
Button, Dialog, DialogActions, DialogContent, DialogContentText, Collapse, Badge,
FormControlLabel, Tooltip, CircularProgress, FormControl, RadioGroup, Radio, Checkbox
} from '@mui/material'
import {
Help as HelpIcon,
ArrowDropDown as ArrowDropDownIcon,
ArrowDropUp as ArrowDropUpIcon,
} from '@mui/icons-material'
import DialogTitleWithCloseButton from './DialogTitleWithCloseButton';
import APIPreview from './APIPreview'
import { HtmlToolTipClone as HtmlToolTipRaw } from './HtmlToolTipRaw';
const ReferenceCascadeDialog = ({ references, collectionName, onCascadeChange, open, onClose, title, onAdd, isAdding, collection, noCascadePayloadFunc, cascadeMappingsFunc, cascadeToConceptsFunc, cascadeOpenMRSFunc, onTransformReferencesChange }) => {
const [cascadeMethod, setCascadeMethod] = React.useState('none')
const [transformReferences, setTransformReferences] = React.useState(false)
const [advancedSettings, setAdvancedSettings] = React.useState(false)
const toggleSettings = () => setAdvancedSettings(!advancedSettings)
const showAdvancedSettings = Boolean(onTransformReferencesChange)
const onChange = event => {
const newValue = event.target.value
setCascadeMethod(newValue)
_onTransformReferencesChange(newValue === 'OpenMRSCascade')
onCascadeChange({cascadeMappings: newValue === 'cascadeMappings', cascadeToConcepts: newValue === 'cascadeToConcepts', cascadeMethod: newValue})
}
const _onTransformReferencesChange = transform => {
setTransformReferences(transform)
onTransformReferencesChange(transform)
}
const getPayload = () => {
if(cascadeMethod === 'none' && noCascadePayloadFunc)
return noCascadePayloadFunc()
if(cascadeMethod === 'cascadeMappings' && cascadeMappingsFunc)
return cascadeMappingsFunc()
if(cascadeMethod === 'cascadeToConcepts' && cascadeToConceptsFunc)
return cascadeToConceptsFunc()
if(cascadeMethod === 'OpenMRSCascade' && cascadeOpenMRSFunc)
return cascadeOpenMRSFunc()
}
const cascadePayload = getPayload()
const queryString = new URLSearchParams(cascadePayload?.queryParams).toString()
const requestURL = collection ? collection.url + 'references/' + (queryString ? `?${queryString}` : '') : null
const getContent = () => (
<DialogContent>
{
isAdding ?
<div className='col-md-12' style={{textAlign: 'center'}}>
<CircularProgress />
</div> :
<React.Fragment>
<DialogContentText style={{color: 'black', marginBottom: '20px'}}>
{`${references.length} selected Reference(s) will be added to Collection: ${collectionName}`}
</DialogContentText>
<h4 style={{marginBottom: '5px'}}>
Would you like to also include associated Concepts and Mappings?
</h4>
<FormControl style={{marginBottom: '5px'}}>
<RadioGroup
aria-labelledby="demo-controlled-radio-buttons-group"
name="controlled-radio-buttons-group"
value={cascadeMethod}
onChange={onChange}
>
<FormControlLabel
value="none"
control={<Radio />}
label={
<span className='flex-vertical-center'>
<span style={{marginRight: '5px', fontSize: '14px'}}>
No, only include the selected resources
</span>
</span>
}
/>
<FormControlLabel
value="cascadeMappings"
control={<Radio />}
label={
<span className='flex-vertical-center'>
<span style={{marginRight: '5px', fontSize: '14px'}}>
Yes, include associated Mappings from the same source
</span>
</span>
}
/>
<FormControlLabel
value="cascadeToConcepts"
control={<Radio />}
label={
<span className='flex-vertical-center'>
<span style={{marginRight: '5px', fontSize: '14px'}}>
Yes, include associated Mappings and target Concepts from the same source
</span>
</span>
}
/>
<FormControlLabel
value="OpenMRSCascade"
control={<Radio />}
label={
<span className='flex-vertical-center'>
<span style={{marginRight: '5px', fontSize: '14px'}}>
Yes, apply OpenMRS-compatible cascade
</span>
<Tooltip arrow title='Includes associated Mappings and target Concepts from the same source, and recursively adds any of their associated answer and set member concepts and mappings (e.g. Q-AND-A and CONCEPT-SET mappings)'>
<HelpIcon fontSize='small' style={{fontSize: '14px'}}/>
</Tooltip>
</span>
}
/>
</RadioGroup>
{
showAdvancedSettings &&
<div className='col-xs-12 no-side-padding' style={{marginTop: '10px'}}>
<Badge badgeContent={transformReferences && !advancedSettings ? 1 : 0} color='primary'>
<Button
size='small'
variant='text'
endIcon={
advancedSettings ?
<ArrowDropUpIcon fontSize='inherit' /> :
<ArrowDropDownIcon fontSize='inherit' />
}
style={{textTransform: 'none', marginLeft: '-4px'}}
onClick={toggleSettings}>
Advanced Settings
</Button>
</Badge>
<Collapse in={advancedSettings} timeout="auto" unmountOnExit style={{marginTop: '-15px'}}>
{
advancedSettings &&
<div className='col-xs-12 no-side-padding' style={{margin: '15px 0'}}>
<FormControlLabel
control={<Checkbox checked={transformReferences} onChange={() => _onTransformReferencesChange(!transformReferences)}/>}
label={
<span className='flex-vertical-center'>
<span style={{marginRight: '5px', fontSize: '14px'}}>
Transform to static references
</span>
<HtmlToolTipRaw
placement='right'
title={
<span>
<span>
Transforming to static references means that after concepts and mappings are added to your collection, they will not change even if they are updated at the source.
</span>
<br />
<br />
<span>
Uncheck this box to allow dynamic references, which may help you to keep your collection up to date in the future. See this <a href="https://www.youtube.com/watch?v=bl2IilO0Fec&list=PLbjKElEpop-Ubhm5Xz4sQ7u7ugune_CXF&index=2" target="_blank" rel="noopener noreferrer" style={{color: 'inherit', textDecoration: 'underline', fontWeight: 'bold'}}>YouTube video</a> for details.
</span>
</span>
}
arrow
>
<HelpIcon fontSize='small' style={{fontSize: '14px'}}/>
</HtmlToolTipRaw>
</span>
}
/>
</div>
}
</Collapse>
</div>
}
</FormControl>
{
cascadePayload &&
<APIPreview verb='PUT' payload={cascadePayload.payload} url={requestURL}/>
}
</React.Fragment>
}
</DialogContent>
);
return (
<React.Fragment>
{
open ?
(
<Dialog open={open} onClose={onClose}>
{
title &&
<DialogTitleWithCloseButton onClose={onClose}>
{title}
</DialogTitleWithCloseButton>
}
{ getContent() }
<DialogActions>
<React.Fragment>
<Button onClick={onClose} color="secondary" disabled={isAdding}>
Cancel
</Button>
<Button onClick={onAdd} color="primary" disabled={isAdding}>
Add
</Button>
</React.Fragment>
</DialogActions>
</Dialog>
) :
(getContent())
}
</React.Fragment>
)
}
export default ReferenceCascadeDialog;