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

Entry deletion for the simple workflow #485

Merged
merged 3 commits into from
Jul 22, 2017

Conversation

Benaiah
Copy link
Contributor

@Benaiah Benaiah commented Jul 13, 2017

- Summary

This PR adds a "Delete" button to the entry page in the simple workflow which deletes the current entry from the backend. This does not close #291 completely, but it is most of the way there (the remaining work to close that ticket is to implement deletion in the editorial workflow, which is in progress in the delete-entries-in-editorial-workflow branch.

- Test plan

Existing tests pass, relevant spec tests were updated, and the PR was manually tested with editorial workflow both enabled and disabled.

- Description for the changelog

Entry deletion for the simple workflow

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

image

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.

Awesome work, just a couple of clean up requests.

@@ -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: true };
Copy link
Contributor

Choose a reason for hiding this comment

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

showDelete should also be false if the entry is new.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Currently it deletes your unsaved changes - that seemed like the most obvious approach to me. I'll switch this out.

Copy link
Contributor

Choose a reason for hiding this comment

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

Is this change still on the way?

};

handlePersistEntry = () => {
const { persistEntry, collection } = this.props;
setTimeout(() => {
persistEntry(collection);
persistEntry(collection).then(() => this.handleCloseEntry());
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

@@ -1,4 +1,5 @@
import semaphore from "semaphore";
import { resolvePromiseProperties } from "../../lib/promiseHelper";
Copy link
Contributor

Choose a reason for hiding this comment

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

Unused import.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the catch!

.then(({ sha }) => this.request(
`${ this.repoURL }/contents/${ path }`,
{
method: "DELETE",
Copy link
Contributor

Choose a reason for hiding this comment

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

Go with single quotes for this and other quotes in the PR (except React component attributes).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍

deleteFile(path, message, options={}) {
const branch = options.branch || this.branch;
// We need to request the file first to get the SHA
return this.request(`${ this.repoURL }/contents/${ path }`)
Copy link
Contributor

Choose a reason for hiding this comment

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

Nitpick: we can store the assembled url above the return and reuse.

// deletion should be idempotent, so we can consider this a
// success.
.catch((err) => {
if (err.message === "Reference does not exist") {
Copy link
Contributor

Choose a reason for hiding this comment

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

Nothing less ephemeral to check against, such as an error code?

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 error code here is a 422, and there's no other metadata available there other than the error message. 422 is a very general error code in the GitHub API, so resolving this promise for all 422s will other errors, so I checked the more specific error message.

https://developer.github.com/v3/#client-errors says clients should differentiate 422 errors based on the body of the response (the APIError wrapper we use isn't including this information, which should probably be changed in another PR). I was hoping there would be more metadata in the request, but when inspecting a relevant 422 response manually, only the message and documentation_url were present, leaving us with just the message and status to switch between. Given GitHub's API documentation, it seems that the message is intended to be used to differentiate errors, so I used that.

If you'd rather catch all 422 errors, I can change this pretty trivially (just need to change the condition to err.status === 422).

Copy link
Contributor

Choose a reason for hiding this comment

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

Okay, this is fine as is. Thanks for the explanation.

@Benaiah Benaiah force-pushed the delete-entries-in-simple-workflow branch from 49a3e32 to 82cd253 Compare July 21, 2017 02:07
@Benaiah Benaiah force-pushed the delete-entries-in-simple-workflow branch from 82cd253 to ef2f819 Compare July 21, 2017 02:09
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

@erquhart
Copy link
Contributor

erquhart commented Jul 22, 2017

@carlflor would you be up for reviewing this PR? You mentioned contributing, and code review is one area that needs much more community activity; we prefer to have two maintainers/collaborators okay a PR before merging. Let me know!

@carlflor
Copy link

@erquhart okay! cool! I can review this :)

Copy link

@carlflor carlflor left a comment

Choose a reason for hiding this comment

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

Looking good! :)

@Benaiah Benaiah merged commit dac57c6 into master Jul 22, 2017
@Benaiah
Copy link
Contributor Author

Benaiah commented Jul 22, 2017

@carlflor thanks for the review!

tech4him1 added a commit that referenced this pull request Aug 17, 2017
Deletion was added in #485, but the function for the `test-repo` backend
was `deleteEntry` instead of `deleteFile` like it was supposed to be.

Also, setting the key for a deleted file to `undefined` did not really
remove that file from the object, so there were then errors stating
`file.content` is not defined. `delete`ing the "file" from the object
fixes this bug.
@tech4him1 tech4him1 deleted the delete-entries-in-simple-workflow branch August 26, 2017 15:33
@mbergeronupgrade
Copy link

@Benaiah I think in editorial mode, the delete entry button does not respect the delete: false option from config.yml

@tech4him1
Copy link
Contributor

@mbergeronupgrade Please open a new issue for that.

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.

Ability to delete cards outside of editorial workflow
5 participants