@@ -3,18 +3,27 @@ import PropTypes from "prop-types";
3
3
4
4
import { connect } from "react-redux" ;
5
5
6
- import { Box , Anchor } from "grommet" ;
6
+ import { Box , Anchor , Button } from "grommet" ;
7
7
8
8
import Edit from "grommet/components/icons/base/FormEdit" ;
9
- import { toggleFilemanagerLayer } from "../../../../../../actions/drafts" ;
9
+ import CloudUploadIcon from "grommet/components/icons/base/CloudUpload" ;
10
+ import {
11
+ toggleFilemanagerLayer ,
12
+ uploadToZenodo
13
+ } from "../../../../../../actions/drafts" ;
14
+
15
+ import Status from "grommet/components/icons/Status" ;
10
16
11
17
class CapFile extends React . Component {
12
18
constructor ( props ) {
13
19
super ( props ) ;
14
-
20
+ let isZenodo = props . uiSchema [ "ui:options" ]
21
+ ? props . uiSchema [ "ui:options" ] [ "zenodo" ]
22
+ : null ;
15
23
this . state = {
16
24
layerActive : false ,
17
- selected : { }
25
+ selected : { } ,
26
+ isZenodo : isZenodo
18
27
} ;
19
28
}
20
29
@@ -42,6 +51,9 @@ class CapFile extends React.Component {
42
51
}
43
52
44
53
render ( ) {
54
+ let bucket = this . props . links ? this . props . links . get ( "bucket" ) : null ;
55
+ let bucket_id = bucket ? bucket . split ( "/" ) . pop ( ) : null ;
56
+
45
57
return (
46
58
< Box
47
59
pad = "small"
@@ -53,22 +65,46 @@ class CapFile extends React.Component {
53
65
wrap = { false }
54
66
>
55
67
{ this . props . formData ? (
56
- < React . Fragment >
57
- < span > { this . props . formData } </ span >
58
- < Anchor
59
- icon = { < Edit /> }
60
- onClick = { this . _toggleFileManager . bind ( this ) }
61
- />
62
- </ React . Fragment >
68
+ < Box >
69
+ < Box direction = "row" >
70
+ < Box pad = "small" > { this . props . formData } </ Box >
71
+ < Anchor
72
+ icon = { < Edit /> }
73
+ onClick = { this . _toggleFileManager . bind ( this ) }
74
+ />
75
+ </ Box >
76
+ { this . state . isZenodo ? (
77
+ < Box direction = "row" >
78
+ < Button
79
+ icon = { < CloudUploadIcon /> }
80
+ label = "Upload to zenodo"
81
+ onClick = { ( ) => {
82
+ this . props . uploadToZenodo (
83
+ this . props . idSchema . $id ,
84
+ bucket_id ,
85
+ this . props . formData
86
+ ) ;
87
+ } }
88
+ />
89
+ { this . props . zenodoId == 200 ? (
90
+ < Box pad = "small" >
91
+ < Status value = "ok" />
92
+ </ Box >
93
+ ) : null }
94
+ </ Box >
95
+ ) : null }
96
+ </ Box >
63
97
) : (
64
- < React . Fragment >
65
- < Anchor
66
- label = "Open File Manager"
67
- onClick = { this . _toggleFileManager . bind ( this ) }
68
- />
69
- < Box > -- OR -- </ Box >
70
- < Box > Drag & Drop files here </ Box >
71
- </ React . Fragment >
98
+ < Box >
99
+ < Box direction = "row" >
100
+ < Anchor
101
+ label = "Open File Manager"
102
+ onClick = { this . _toggleFileManager . bind ( this ) }
103
+ />
104
+ < Box > -- OR -- </ Box >
105
+ < Box > Drag & Drop files here </ Box >
106
+ </ Box >
107
+ </ Box >
72
108
) }
73
109
</ Box >
74
110
) ;
@@ -83,17 +119,31 @@ CapFile.propTypes = {
83
119
onChange : PropTypes . func ,
84
120
properties : PropTypes . object ,
85
121
toggleFilemanagerLayer : PropTypes . func ,
86
- formData : PropTypes . object
122
+ formData : PropTypes . object ,
123
+ uploadToZenodo : PropTypes . func ,
124
+ links : PropTypes . object ,
125
+ zenodo : PropTypes . object ,
126
+ uiSchema : PropTypes . object ,
127
+ idSchema : PropTypes . object
87
128
} ;
88
129
130
+ function mapStateToProps ( state , props ) {
131
+ return {
132
+ links : state . drafts . getIn ( [ "current_item" , "links" ] ) ,
133
+ zenodoId : state . drafts . getIn ( [ "zenodo" , props . idSchema . $id , "status" ] )
134
+ } ;
135
+ }
136
+
89
137
function mapDispatchToProps ( dispatch ) {
90
138
return {
91
139
toggleFilemanagerLayer : ( selectable = false , action ) =>
92
- dispatch ( toggleFilemanagerLayer ( selectable , action ) )
140
+ dispatch ( toggleFilemanagerLayer ( selectable , action ) ) ,
141
+ uploadToZenodo : ( element_id , bucket_id , filename ) =>
142
+ dispatch ( uploadToZenodo ( element_id , bucket_id , filename ) )
93
143
} ;
94
144
}
95
145
96
146
export default connect (
97
- null ,
147
+ mapStateToProps ,
98
148
mapDispatchToProps
99
149
) ( CapFile ) ;
0 commit comments