Skip to content

Commit 6ba34f1

Browse files
committed
jekyll#333 Add save-as-copy button
1 parent a774118 commit 6ba34f1

File tree

4 files changed

+33
-3
lines changed

4 files changed

+33
-3
lines changed

src/components/Button.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export default class Button extends Component {
1010
const btnClass = classnames({
1111
'btn': true,
1212
'btn-active': active,
13-
'btn-success': active && (type == 'save' || type == 'create'),
13+
'btn-success': active && (type == 'save' || type == 'create' || type == 'copy'),
1414
'btn-delete': type == 'delete',
1515
'btn-view': type == 'view',
1616
'btn-inactive': !active,
@@ -32,6 +32,10 @@ export default class Button extends Component {
3232
case 'delete':
3333
label = labels.delete.label;
3434
break;
35+
case 'copy':
36+
label = labels.copy.label;
37+
triggeredLabel = labels.copy.triggeredLabel;
38+
break;
3539
case 'view':
3640
label = labels.view.label;
3741
break;

src/constants/lang/en.js

+4
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@ export const labels = {
6868
delete: {
6969
label: 'Delete'
7070
},
71+
copy: {
72+
label: 'Copy',
73+
triggeredLabel: 'Copied'
74+
},
7175
view: {
7276
label: 'View'
7377
},

src/containers/Sidebar.js

-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,6 @@ export class Sidebar extends Component {
9292

9393
return (
9494
<div className="sidebar">
95-
<Link className="logo" to={`${ADMIN_PREFIX}/pages`} />
9695
<ul className="routes">
9796
{this.renderCollections(hiddenLinks)}
9897
{links}

src/containers/views/DocumentEdit.js

+24-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import InputPath from '../../components/form/InputPath';
1313
import InputTitle from '../../components/form/InputTitle';
1414
import MarkdownEditor from '../../components/MarkdownEditor';
1515
import Metadata from '../../containers/MetaFields';
16-
import { fetchDocument, deleteDocument, putDocument } from '../../actions/collections';
16+
import { fetchDocument, deleteDocument, putDocument, createDocument } from '../../actions/collections';
1717
import { updateTitle, updateBody, updatePath } from '../../actions/metadata';
1818
import { clearErrors } from '../../actions/utils';
1919
import { injectDefaultFields } from '../../utils/metadata';
@@ -29,6 +29,7 @@ export class DocumentEdit extends Component {
2929
super(props);
3030

3131
this.handleClickSave = this.handleClickSave.bind(this);
32+
this.handleClickCopy = this.handleClickCopy.bind(this);
3233
this.routerWillLeave = this.routerWillLeave.bind(this);
3334
}
3435

@@ -97,6 +98,18 @@ export class DocumentEdit extends Component {
9798
}
9899
}
99100

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+
100113
render() {
101114
const {
102115
isFetching, currentDocument, errors, updateTitle, updateBody, updatePath, updated,
@@ -120,6 +133,7 @@ export class DocumentEdit extends Component {
120133

121134
const keyboardHandlers = {
122135
'save': this.handleClickSave,
136+
'copy': this.handleClickCopy,
123137
};
124138

125139
const document_title = directory ?
@@ -158,6 +172,13 @@ export class DocumentEdit extends Component {
158172
triggered={updated}
159173
icon="save"
160174
block />
175+
<Button
176+
onClick={this.handleClickCopy}
177+
type="copy"
178+
active={true}
179+
triggered={updated}
180+
icon="copy"
181+
block />
161182
{
162183
http_url &&
163184
<Button
@@ -188,6 +209,7 @@ DocumentEdit.propTypes = {
188209
fetchDocument: PropTypes.func.isRequired,
189210
deleteDocument: PropTypes.func.isRequired,
190211
putDocument: PropTypes.func.isRequired,
212+
createDocument: PropTypes.func.isRequired,
191213
updateTitle: PropTypes.func.isRequired,
192214
updateBody: PropTypes.func.isRequired,
193215
updatePath: PropTypes.func.isRequired,
@@ -215,6 +237,7 @@ const mapDispatchToProps = (dispatch) => bindActionCreators({
215237
fetchDocument,
216238
deleteDocument,
217239
putDocument,
240+
createDocument,
218241
updateTitle,
219242
updateBody,
220243
updatePath,

0 commit comments

Comments
 (0)