Skip to content

Commit

Permalink
jekyll#333 Add save-as-copy button
Browse files Browse the repository at this point in the history
  • Loading branch information
rthrfrd committed Sep 27, 2017
1 parent a774118 commit 6ba34f1
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 3 deletions.
6 changes: 5 additions & 1 deletion src/components/Button.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export default class Button extends Component {
const btnClass = classnames({
'btn': true,
'btn-active': active,
'btn-success': active && (type == 'save' || type == 'create'),
'btn-success': active && (type == 'save' || type == 'create' || type == 'copy'),
'btn-delete': type == 'delete',
'btn-view': type == 'view',
'btn-inactive': !active,
Expand All @@ -32,6 +32,10 @@ export default class Button extends Component {
case 'delete':
label = labels.delete.label;
break;
case 'copy':
label = labels.copy.label;
triggeredLabel = labels.copy.triggeredLabel;
break;
case 'view':
label = labels.view.label;
break;
Expand Down
4 changes: 4 additions & 0 deletions src/constants/lang/en.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ export const labels = {
delete: {
label: 'Delete'
},
copy: {
label: 'Copy',
triggeredLabel: 'Copied'
},
view: {
label: 'View'
},
Expand Down
1 change: 0 additions & 1 deletion src/containers/Sidebar.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ export class Sidebar extends Component {

return (
<div className="sidebar">
<Link className="logo" to={`${ADMIN_PREFIX}/pages`} />
<ul className="routes">
{this.renderCollections(hiddenLinks)}
{links}
Expand Down
25 changes: 24 additions & 1 deletion src/containers/views/DocumentEdit.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import InputPath from '../../components/form/InputPath';
import InputTitle from '../../components/form/InputTitle';
import MarkdownEditor from '../../components/MarkdownEditor';
import Metadata from '../../containers/MetaFields';
import { fetchDocument, deleteDocument, putDocument } from '../../actions/collections';
import { fetchDocument, deleteDocument, putDocument, createDocument } from '../../actions/collections';
import { updateTitle, updateBody, updatePath } from '../../actions/metadata';
import { clearErrors } from '../../actions/utils';
import { injectDefaultFields } from '../../utils/metadata';
Expand All @@ -29,6 +29,7 @@ export class DocumentEdit extends Component {
super(props);

this.handleClickSave = this.handleClickSave.bind(this);
this.handleClickCopy = this.handleClickCopy.bind(this);
this.routerWillLeave = this.routerWillLeave.bind(this);
}

Expand Down Expand Up @@ -97,6 +98,18 @@ export class DocumentEdit extends Component {
}
}

handleClickCopy(e) {
const { createDocument, params } = this.props;

// Prevent the default event from bubbling
preventDefault(e);

const collection = params.collection_name;
const [directory, ...rest] = params.splat;
const filename = 'copy-' + rest.join('.');
createDocument(collection, directory || '/');
}

render() {
const {
isFetching, currentDocument, errors, updateTitle, updateBody, updatePath, updated,
Expand All @@ -120,6 +133,7 @@ export class DocumentEdit extends Component {

const keyboardHandlers = {
'save': this.handleClickSave,
'copy': this.handleClickCopy,
};

const document_title = directory ?
Expand Down Expand Up @@ -158,6 +172,13 @@ export class DocumentEdit extends Component {
triggered={updated}
icon="save"
block />
<Button
onClick={this.handleClickCopy}
type="copy"
active={true}
triggered={updated}
icon="copy"
block />
{
http_url &&
<Button
Expand Down Expand Up @@ -188,6 +209,7 @@ DocumentEdit.propTypes = {
fetchDocument: PropTypes.func.isRequired,
deleteDocument: PropTypes.func.isRequired,
putDocument: PropTypes.func.isRequired,
createDocument: PropTypes.func.isRequired,
updateTitle: PropTypes.func.isRequired,
updateBody: PropTypes.func.isRequired,
updatePath: PropTypes.func.isRequired,
Expand Down Expand Up @@ -215,6 +237,7 @@ const mapDispatchToProps = (dispatch) => bindActionCreators({
fetchDocument,
deleteDocument,
putDocument,
createDocument,
updateTitle,
updateBody,
updatePath,
Expand Down

0 comments on commit 6ba34f1

Please sign in to comment.