1
1
import React , { useEffect , useState } from 'react' ;
2
- import { Col , Row , Button , Popover } from 'antd' ;
2
+ import {
3
+ Col , Row , Button , Popover ,
4
+ } from 'antd' ;
3
5
import { useHistory , useLocation } from 'react-router-dom' ;
4
6
import { DiscoveryConfig } from '../../../DiscoveryConfig' ;
5
7
import { DiscoveryResource } from '../../../Discovery' ;
@@ -34,28 +36,26 @@ const ActionButtons = ({
34
36
const history = useHistory ( ) ;
35
37
const location = useLocation ( ) ;
36
38
37
- const studyMetadataFieldNameReference : string | undefined =
38
- discoveryConfig ?. features . exportToWorkspace . studyMetadataFieldName ;
39
- const manifestFieldName : string | undefined =
40
- discoveryConfig ?. features . exportToWorkspace . manifestFieldName ;
39
+ const studyMetadataFieldNameReference : string | undefined = discoveryConfig ?. features . exportToWorkspace . studyMetadataFieldName ;
40
+ const manifestFieldName : string | undefined = discoveryConfig ?. features . exportToWorkspace . manifestFieldName ;
41
41
const showDownloadStudyLevelMetadataButton = Boolean (
42
- discoveryConfig ?. features . exportToWorkspace . enableDownloadStudyMetadata &&
43
- studyMetadataFieldNameReference &&
44
- resourceInfo ?. [ studyMetadataFieldNameReference ]
42
+ discoveryConfig ?. features . exportToWorkspace . enableDownloadStudyMetadata
43
+ && studyMetadataFieldNameReference
44
+ && resourceInfo ?. [ studyMetadataFieldNameReference ] ,
45
45
) ;
46
46
const showDownloadFileManifestButtons = Boolean (
47
- discoveryConfig ?. features . exportToWorkspace . enableDownloadManifest
47
+ discoveryConfig ?. features . exportToWorkspace . enableDownloadManifest ,
48
48
) ;
49
49
const showDownloadAllFilesButtons = Boolean (
50
- discoveryConfig ?. features . exportToWorkspace . enableDownloadZip
50
+ discoveryConfig ?. features . exportToWorkspace . enableDownloadZip ,
51
51
) ;
52
52
const verifyExternalLoginsNeeded = Boolean (
53
- discoveryConfig ?. features . exportToWorkspace . verifyExternalLogins
53
+ discoveryConfig ?. features . exportToWorkspace . verifyExternalLogins ,
54
54
) ;
55
55
56
56
const showDownloadVariableMetadataButton = Boolean (
57
- discoveryConfig . features . exportToWorkspace . variableMetadataFieldName &&
58
- discoveryConfig . features . exportToWorkspace . enableDownloadVariableMetadata
57
+ discoveryConfig . features . exportToWorkspace . variableMetadataFieldName
58
+ && discoveryConfig . features . exportToWorkspace . enableDownloadVariableMetadata ,
59
59
) ;
60
60
const [ dataDictionaryInfo , setDataDictionaryInfo ] = useState ( {
61
61
noVariableLevelMetadata : true ,
@@ -67,18 +67,17 @@ const ActionButtons = ({
67
67
discoveryConfig ,
68
68
resourceInfo ,
69
69
showDownloadVariableMetadataButton ,
70
- setDataDictionaryInfo
70
+ setDataDictionaryInfo ,
71
71
) ;
72
72
} , [ resourceInfo ] ) ;
73
73
74
- const ConditionalPopover = ( { children } ) =>
75
- noData ? (
76
- < Popover title = { 'This file is not available for the selected study' } >
77
- { children }
78
- </ Popover >
79
- ) : (
80
- children
81
- ) ;
74
+ const ConditionalPopover = ( { children } ) => ( noData ? (
75
+ < Popover title = { 'This file is not available for the selected study' } >
76
+ { children }
77
+ </ Popover >
78
+ ) : (
79
+ children
80
+ ) ) ;
82
81
83
82
return (
84
83
< div className = 'discovery-modal_buttons-row' data-testid = 'actionButtons' >
@@ -89,77 +88,42 @@ const ActionButtons = ({
89
88
< Row className = 'row' >
90
89
{ showDownloadVariableMetadataButton && (
91
90
< Col flex = '1 0 auto' >
92
- { isUserLoggedIn && ! healLoginNeeded && (
93
- < Button
94
- className = 'discovery-action-bar-button'
95
- disabled = { Boolean (
96
- downloadStatus . inProgress ||
97
- dataDictionaryInfo . noVariableLevelMetadata
98
- ) }
99
- loading = {
100
- downloadStatus . inProgress === 'DownloadVariableMetadata'
101
- }
102
- onClick = { ( ) => {
103
- DownloadVariableMetadata (
104
- dataDictionaryInfo . dataDictionaries ,
105
- resourceInfo ,
106
- setDownloadStatus
107
- ) ;
108
- } }
109
- >
110
- Download < br />
111
- Variable-Level Metadata
112
- </ Button >
113
- ) }
114
- { ! dataDictionaryInfo . noVariableLevelMetadata &&
115
- ( ! isUserLoggedIn || healLoginNeeded ) && (
116
- < Button
117
- className = 'discovery-action-bar-button'
118
- disabled = { Boolean ( noData || downloadStatus . inProgress ) }
119
- onClick = { ( ) => {
120
- HandleRedirectToLoginClick ( resourceInfo , discoveryConfig ) ;
121
- } }
122
- >
123
- Login to Download
124
- < br />
125
- Variable Level Metadata
126
- </ Button >
91
+ < Button
92
+ className = 'discovery-action-bar-button'
93
+ disabled = { Boolean (
94
+ downloadStatus . inProgress
95
+ || dataDictionaryInfo . noVariableLevelMetadata ,
127
96
) }
97
+ loading = { downloadStatus . inProgress === 'DownloadVariableMetadata' }
98
+ onClick = { ( ) => {
99
+ DownloadVariableMetadata (
100
+ dataDictionaryInfo . dataDictionaries ,
101
+ resourceInfo ,
102
+ setDownloadStatus ,
103
+ ) ;
104
+ } }
105
+ >
106
+ Download < br />
107
+ Variable-Level Metadata
108
+ </ Button >
128
109
</ Col >
129
110
) }
130
111
{ showDownloadStudyLevelMetadataButton && (
131
112
< Col flex = '1 0 auto' >
132
- { isUserLoggedIn && ! healLoginNeeded && (
133
- < ConditionalPopover >
134
- < Button
135
- className = 'discovery-action-bar-button'
136
- disabled = { Boolean ( noData || downloadStatus . inProgress ) }
137
- onClick = { ( ) =>
138
- DownloadJsonFile (
139
- 'study-level-metadata' ,
140
- studyMetadataFieldNameReference &&
141
- resourceInfo [ studyMetadataFieldNameReference ]
142
- )
143
- }
144
- >
145
- Download < br />
146
- Study-Level Metadata
147
- </ Button >
148
- </ ConditionalPopover >
149
- ) }
150
- { ( ! isUserLoggedIn || healLoginNeeded ) && (
113
+ < ConditionalPopover >
151
114
< Button
152
115
className = 'discovery-action-bar-button'
153
116
disabled = { Boolean ( noData || downloadStatus . inProgress ) }
154
- onClick = { ( ) => {
155
- HandleRedirectToLoginClick ( resourceInfo , discoveryConfig ) ;
156
- } }
117
+ onClick = { ( ) => DownloadJsonFile (
118
+ 'study-level-metadata' ,
119
+ studyMetadataFieldNameReference
120
+ && resourceInfo [ studyMetadataFieldNameReference ] ,
121
+ ) }
157
122
>
158
- Login to Download
159
- < br />
123
+ Download < br />
160
124
Study-Level Metadata
161
125
</ Button >
162
- ) }
126
+ </ ConditionalPopover >
163
127
</ Col >
164
128
) }
165
129
{ showDownloadFileManifestButtons && (
@@ -173,7 +137,7 @@ const ActionButtons = ({
173
137
HandleDownloadManifestClick (
174
138
discoveryConfig ,
175
139
[ resourceInfo ] ,
176
- healLoginNeeded
140
+ healLoginNeeded ,
177
141
) ;
178
142
} }
179
143
>
@@ -189,7 +153,7 @@ const ActionButtons = ({
189
153
HandleRedirectToLoginClick (
190
154
resourceInfo ,
191
155
discoveryConfig ,
192
- 'manifest'
156
+ 'manifest' ,
193
157
) ;
194
158
} }
195
159
>
@@ -207,18 +171,16 @@ const ActionButtons = ({
207
171
className = 'discovery-action-bar-button'
208
172
disabled = { Boolean ( noData || downloadStatus . inProgress ) }
209
173
loading = { downloadStatus . inProgress === 'DownloadAllFiles' }
210
- onClick = { ( ) =>
211
- DownloadAllFiles (
212
- resourceInfo ,
213
- downloadStatus ,
214
- setDownloadStatus ,
215
- history ,
216
- location ,
217
- healLoginNeeded ,
218
- verifyExternalLoginsNeeded ,
219
- manifestFieldName
220
- )
221
- }
174
+ onClick = { ( ) => DownloadAllFiles (
175
+ resourceInfo ,
176
+ downloadStatus ,
177
+ setDownloadStatus ,
178
+ history ,
179
+ location ,
180
+ healLoginNeeded ,
181
+ verifyExternalLoginsNeeded ,
182
+ manifestFieldName ,
183
+ ) }
222
184
>
223
185
Download All Files
224
186
</ Button >
@@ -232,7 +194,7 @@ const ActionButtons = ({
232
194
HandleRedirectToLoginClick (
233
195
resourceInfo ,
234
196
discoveryConfig ,
235
- 'download'
197
+ 'download' ,
236
198
) ;
237
199
} }
238
200
>
0 commit comments