@@ -5,17 +5,27 @@ import { connect } from "react-redux";
55
66import  Box  from  "grommet/components/Box" ; 
77import  Anchor  from  "grommet/components/Anchor" ; 
8+ import  Button  from  "grommet/components/Button" 
89
910import  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" ; 
1118
1219class  CapFile  extends  React . Component  { 
1320  constructor ( props )  { 
1421    super ( props ) ; 
15- 
22+     let  isZenodo  =  props . uiSchema [ "ui:options" ] 
23+       ? props . uiSchema [ "ui:options" ] [ "zenodo" ] 
24+       : null ; 
1625    this . state  =  { 
1726      layerActive : false , 
18-       selected : { } 
27+       selected : { } , 
28+       isZenodo : isZenodo 
1929    } ; 
2030  } 
2131
@@ -43,6 +53,9 @@ class CapFile extends React.Component {
4353  } 
4454
4555  render ( )  { 
56+     let  bucket  =  this . props . links  ? this . props . links . get ( "bucket" )  : null ; 
57+     let  bucket_id  =  bucket  ? bucket . split ( "/" ) . pop ( )  : null ; 
58+ 
4659    return  ( 
4760      < Box 
4861        pad = "small" 
@@ -54,13 +67,35 @@ class CapFile extends React.Component {
5467        wrap = { false } 
5568      > 
5669        { 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 > 
6499        )  : ( 
65100          < React . Fragment > 
66101            < Anchor 
@@ -82,17 +117,31 @@ CapFile.propTypes = {
82117  onChange : PropTypes . func , 
83118  properties : PropTypes . object , 
84119  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 
86126} ; 
87127
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+ 
88135function  mapDispatchToProps ( dispatch )  { 
89136  return  { 
90137    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 ) ) 
92141  } ; 
93142} 
94143
95144export  default  connect ( 
96-   null , 
145+   mapStateToProps , 
97146  mapDispatchToProps 
98147) ( CapFile ) ; 
0 commit comments