@@ -13,7 +13,7 @@ import InputPath from '../../components/form/InputPath';
13
13
import InputTitle from '../../components/form/InputTitle' ;
14
14
import MarkdownEditor from '../../components/MarkdownEditor' ;
15
15
import Metadata from '../../containers/MetaFields' ;
16
- import { fetchDocument , deleteDocument , putDocument } from '../../actions/collections' ;
16
+ import { fetchDocument , deleteDocument , putDocument , createDocument } from '../../actions/collections' ;
17
17
import { updateTitle , updateBody , updatePath } from '../../actions/metadata' ;
18
18
import { clearErrors } from '../../actions/utils' ;
19
19
import { injectDefaultFields } from '../../utils/metadata' ;
@@ -29,6 +29,7 @@ export class DocumentEdit extends Component {
29
29
super ( props ) ;
30
30
31
31
this . handleClickSave = this . handleClickSave . bind ( this ) ;
32
+ this . handleClickCopy = this . handleClickCopy . bind ( this ) ;
32
33
this . routerWillLeave = this . routerWillLeave . bind ( this ) ;
33
34
}
34
35
@@ -97,6 +98,18 @@ export class DocumentEdit extends Component {
97
98
}
98
99
}
99
100
101
+ handleClickCopy ( e ) {
102
+ const { createDocument, params } = this . props ;
103
+
104
+ // Prevent the default event from bubbling
105
+ preventDefault ( e ) ;
106
+
107
+ const collection = params . collection_name ;
108
+ const [ directory , ...rest ] = params . splat ;
109
+ const filename = 'copy-' + rest . join ( '.' ) ;
110
+ createDocument ( collection , directory || '/' ) ;
111
+ }
112
+
100
113
render ( ) {
101
114
const {
102
115
isFetching, currentDocument, errors, updateTitle, updateBody, updatePath, updated,
@@ -120,6 +133,7 @@ export class DocumentEdit extends Component {
120
133
121
134
const keyboardHandlers = {
122
135
'save' : this . handleClickSave ,
136
+ 'copy' : this . handleClickCopy ,
123
137
} ;
124
138
125
139
const document_title = directory ?
@@ -158,6 +172,13 @@ export class DocumentEdit extends Component {
158
172
triggered = { updated }
159
173
icon = "save"
160
174
block />
175
+ < Button
176
+ onClick = { this . handleClickCopy }
177
+ type = "copy"
178
+ active = { true }
179
+ triggered = { updated }
180
+ icon = "copy"
181
+ block />
161
182
{
162
183
http_url &&
163
184
< Button
@@ -188,6 +209,7 @@ DocumentEdit.propTypes = {
188
209
fetchDocument : PropTypes . func . isRequired ,
189
210
deleteDocument : PropTypes . func . isRequired ,
190
211
putDocument : PropTypes . func . isRequired ,
212
+ createDocument : PropTypes . func . isRequired ,
191
213
updateTitle : PropTypes . func . isRequired ,
192
214
updateBody : PropTypes . func . isRequired ,
193
215
updatePath : PropTypes . func . isRequired ,
@@ -215,6 +237,7 @@ const mapDispatchToProps = (dispatch) => bindActionCreators({
215
237
fetchDocument,
216
238
deleteDocument,
217
239
putDocument,
240
+ createDocument,
218
241
updateTitle,
219
242
updateBody,
220
243
updatePath,
0 commit comments