Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not close entry page if it failed to save or delete. #566

Merged
merged 1 commit into from
Aug 29, 2017

Conversation

tech4him1
Copy link
Contributor

@tech4him1 tech4him1 commented Aug 29, 2017

- Summary

Fixes #555:

Currently, if the user tries to save an entry, but the backend has an error, the page still tries to redirect back to the dashboard. However, since the page is not saved yet, the user is presented with a popup: "Are you sure you want to leave this page?". If they click "OK", their content is lost. After the popup is closed (OK or Cancel), the red error notification show up: "Failed to persist entry: API_ERROR: ...".

- Test plan

Manually tested with the test-repo backend by returning a rejected promise from persistEntry and deleteFile.

- Description for the changelog

Do not close entry page if the entry failed to save or delete.

- A picture of a cute animal (not mandatory but encouraged)

@tech4him1 tech4him1 changed the title Do not close entry if it failed to save or delete. Do not close entry page if it failed to save or delete. Aug 29, 2017
@@ -97,7 +97,7 @@ class EntryPage extends React.Component {
handlePersistEntry = () => {
const { persistEntry, collection } = this.props;
setTimeout(() => {
persistEntry(collection).then(() => this.handleCloseEntry());
persistEntry(collection).then(() => this.handleCloseEntry()).catch(() => {/* Don't do anything, the error will be shown by the action. */});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the error here should continue to propagate, rather than be caught by the empty catch block, unless there's a particular reason you caught this here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only reason I did this was that I figured since the action is already showing a notification, we didn't need to do anything. I'll go ahead and test it without the .catch and make sure that there are no side effects, then I can remove it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like the only "downside" is that you get duplicate error messages in the console, so I'll go ahead and remove this.

@@ -110,7 +110,7 @@ class EntryPage extends React.Component {
const { deleteEntry, entry, collection } = this.props;
const slug = entry.get('slug');
setTimeout(() => {
deleteEntry(collection, slug).then(() => this.handleCloseEntry());
deleteEntry(collection, slug).then(() => this.handleCloseEntry()).catch(() => {/* Don't do anything, the error will be shown by the action. */});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the error here should continue to propagate, rather than be caught by the empty catch block, unless there's a particular reason you caught this here.

@@ -288,7 +288,7 @@ export function persistEntry(collection) {
kind: 'success',
dismissAfter: 4000,
}));
return dispatch(entryPersisted(collection, serializedEntry));
return Promise.resolve(dispatch(entryPersisted(collection, serializedEntry)));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think the Promise.resolve here isn't doing anything - dispatch(entryDeleted(...)) should already be returning a promise.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point -- since its returning from a then, it already gets wrapped in a promise.

@@ -297,7 +297,7 @@ export function persistEntry(collection) {
kind: 'danger',
dismissAfter: 8000,
}));
return dispatch(entryPersistFail(collection, serializedEntry, error));
return Promise.reject(dispatch(entryPersistFail(collection, serializedEntry, error)));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@@ -310,7 +310,7 @@ export function deleteEntry(collection, slug) {
dispatch(entryDeleting(collection, slug));
return backend.deleteEntry(state.config, collection, slug)
.then(() => {
return dispatch(entryDeleted(collection, slug));
return Promise.resolve(dispatch(entryDeleted(collection, slug)));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think the Promise.resolve here isn't doing anything - dispatch(entryDeleted(...)) should already be returning a promise.

@@ -319,7 +319,7 @@ export function deleteEntry(collection, slug) {
dismissAfter: 8000,
}));
console.error(error);
return dispatch(entryDeleteFail(collection, slug, error));
return Promise.reject(dispatch(entryDeleteFail(collection, slug, error)));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@tech4him1 tech4him1 force-pushed the entry-stop-navigation-on-fail branch from 8ae941f to 74662cb Compare August 29, 2017 18:23
@tech4him1
Copy link
Contributor Author

@Benaiah Should be updated now -- makes for a simple PR!

Copy link
Contributor

@erquhart erquhart left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

@erquhart erquhart merged commit ac8df98 into master Aug 29, 2017
@erquhart erquhart deleted the entry-stop-navigation-on-fail branch August 29, 2017 18:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Entry Page continues trying to close if entry not saved
3 participants