@@ -3,18 +3,27 @@ import PropTypes from "prop-types";
33
44import { connect } from "react-redux" ;
55
6- import { Box , Anchor } from "grommet" ;
6+ import { Box , Anchor , Button } from "grommet" ;
77
88import 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" ;
1016
1117class CapFile extends React . Component {
1218 constructor ( props ) {
1319 super ( props ) ;
14-
20+ let isZenodo = props . uiSchema [ "ui:options" ]
21+ ? props . uiSchema [ "ui:options" ] [ "zenodo" ]
22+ : null ;
1523 this . state = {
1624 layerActive : false ,
17- selected : { }
25+ selected : { } ,
26+ isZenodo : isZenodo
1827 } ;
1928 }
2029
@@ -42,6 +51,9 @@ class CapFile extends React.Component {
4251 }
4352
4453 render ( ) {
54+ let bucket = this . props . links ? this . props . links . get ( "bucket" ) : null ;
55+ let bucket_id = bucket ? bucket . split ( "/" ) . pop ( ) : null ;
56+
4557 return (
4658 < Box
4759 pad = "small"
@@ -53,22 +65,46 @@ class CapFile extends React.Component {
5365 wrap = { false }
5466 >
5567 { 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 >
6397 ) : (
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 >
72108 ) }
73109 </ Box >
74110 ) ;
@@ -83,17 +119,31 @@ CapFile.propTypes = {
83119 onChange : PropTypes . func ,
84120 properties : PropTypes . object ,
85121 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
87128} ;
88129
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+
89137function mapDispatchToProps ( dispatch ) {
90138 return {
91139 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 ) )
93143 } ;
94144}
95145
96146export default connect (
97- null ,
147+ mapStateToProps ,
98148 mapDispatchToProps
99149) ( CapFile ) ;
0 commit comments