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