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