Entry deletion for the simple workflow (#485)
This commit is contained in:
committed by
GitHub
parent
1d08f1a33b
commit
dac57c60a0
@ -10,6 +10,7 @@ import {
|
||||
changeDraftField,
|
||||
changeDraftFieldValidation,
|
||||
persistEntry,
|
||||
deleteEntry,
|
||||
} from '../actions/entries';
|
||||
import { closeEntry } from '../actions/editor';
|
||||
import { addAsset, removeAsset } from '../actions/media';
|
||||
@ -34,6 +35,8 @@ class EntryPage extends React.Component {
|
||||
entryDraft: ImmutablePropTypes.map.isRequired,
|
||||
loadEntry: PropTypes.func.isRequired,
|
||||
persistEntry: PropTypes.func.isRequired,
|
||||
deleteEntry: PropTypes.func.isRequired,
|
||||
showDelete: PropTypes.bool.isRequired,
|
||||
removeAsset: PropTypes.func.isRequired,
|
||||
closeEntry: PropTypes.func.isRequired,
|
||||
openSidebar: PropTypes.func.isRequired,
|
||||
@ -79,16 +82,29 @@ class EntryPage extends React.Component {
|
||||
};
|
||||
|
||||
handleCloseEntry = () => {
|
||||
this.props.closeEntry();
|
||||
return this.props.closeEntry();
|
||||
};
|
||||
|
||||
handlePersistEntry = () => {
|
||||
const { persistEntry, collection } = this.props;
|
||||
setTimeout(() => {
|
||||
persistEntry(collection);
|
||||
persistEntry(collection).then(() => this.handleCloseEntry());
|
||||
}, 0);
|
||||
};
|
||||
|
||||
handleDeleteEntry = () => {
|
||||
if (!window.confirm('Are you sure you want to delete this entry?')) { return; }
|
||||
if (this.props.newEntry) {
|
||||
return this.handleCloseEntry();
|
||||
}
|
||||
|
||||
const { deleteEntry, entry, collection } = this.props;
|
||||
const slug = entry.get('slug');
|
||||
setTimeout(() => {
|
||||
deleteEntry(collection, slug).then(() => this.handleCloseEntry());
|
||||
}, 0);
|
||||
}
|
||||
|
||||
render() {
|
||||
const {
|
||||
entry,
|
||||
@ -124,6 +140,8 @@ class EntryPage extends React.Component {
|
||||
onAddAsset={addAsset}
|
||||
onRemoveAsset={removeAsset}
|
||||
onPersist={this.handlePersistEntry}
|
||||
onDelete={this.handleDeleteEntry}
|
||||
showDelete={this.props.showDelete}
|
||||
onCancelEdit={this.handleCloseEntry}
|
||||
/>
|
||||
);
|
||||
@ -162,6 +180,7 @@ export default connect(
|
||||
createEmptyDraft,
|
||||
discardDraft,
|
||||
persistEntry,
|
||||
deleteEntry,
|
||||
closeEntry,
|
||||
openSidebar,
|
||||
}
|
||||
|
@ -15,8 +15,9 @@ export default function EntryPageHOC(EntryPage) {
|
||||
function mapStateToProps(state, ownProps) {
|
||||
const { collections } = state;
|
||||
const isEditorialWorkflow = (state.config.get('publish_mode') === EDITORIAL_WORKFLOW);
|
||||
const returnObj = { isEditorialWorkflow };
|
||||
const returnObj = { isEditorialWorkflow, showDelete: !ownProps.newEntry };
|
||||
if (isEditorialWorkflow) {
|
||||
returnObj.showDelete = false;
|
||||
const slug = ownProps.params.slug;
|
||||
const collection = collections.get(ownProps.params.name);
|
||||
const unpublishedEntry = selectUnpublishedEntry(state, collection.get('name'), slug);
|
||||
@ -35,14 +36,16 @@ export default function EntryPageHOC(EntryPage) {
|
||||
|
||||
if (isEditorialWorkflow) {
|
||||
// Overwrite loadEntry to loadUnpublishedEntry
|
||||
returnObj.loadEntry = (collection, slug) => {
|
||||
returnObj.loadEntry = (collection, slug) =>
|
||||
dispatch(loadUnpublishedEntry(collection, slug));
|
||||
};
|
||||
|
||||
|
||||
// Overwrite persistEntry to persistUnpublishedEntry
|
||||
returnObj.persistEntry = (collection) => {
|
||||
returnObj.persistEntry = collection =>
|
||||
dispatch(persistUnpublishedEntry(collection, unpublishedEntry));
|
||||
};
|
||||
|
||||
// Overwrite deleteEntry to a noop (deletion is currently
|
||||
// disabled in the editorial workflow)
|
||||
returnObj.deleteEntry = () => undefined;
|
||||
}
|
||||
|
||||
return {
|
||||
|
Reference in New Issue
Block a user