@@ -3,18 +3,28 @@ 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+ console . log ( ":::::" , props ) ;
21+ let isZenodo = props . uiSchema [ "ui:options" ]
22+ ? props . uiSchema [ "ui:options" ] [ "zenodo" ]
23+ : null ;
1524 this . state = {
1625 layerActive : false ,
17- selected : { }
26+ selected : { } ,
27+ isZenodo : isZenodo
1828 } ;
1929 }
2030
@@ -42,6 +52,9 @@ class CapFile extends React.Component {
4252 }
4353
4454 render ( ) {
55+ let bucket = this . props . links ? this . props . links . get ( "bucket" ) : null ;
56+ let bucket_id = bucket ? bucket . split ( "/" ) . pop ( ) : null ;
57+
4558 return (
4659 < Box
4760 pad = "small"
@@ -53,22 +66,46 @@ class CapFile extends React.Component {
5366 wrap = { false }
5467 >
5568 { 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 >
6398 ) : (
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 >
72109 ) }
73110 </ Box >
74111 ) ;
@@ -83,17 +120,31 @@ CapFile.propTypes = {
83120 onChange : PropTypes . func ,
84121 properties : PropTypes . object ,
85122 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
87129} ;
88130
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+
89138function mapDispatchToProps ( dispatch ) {
90139 return {
91140 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 ) )
93144 } ;
94145}
95146
96147export default connect (
97- null ,
148+ mapStateToProps ,
98149 mapDispatchToProps
99150) ( CapFile ) ;
0 commit comments