-
-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Conversation
There was a problem hiding this 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 }; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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()); |
There was a problem hiding this comment.
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"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unused import.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the catch!
src/backends/github/API.js
Outdated
.then(({ sha }) => this.request( | ||
`${ this.repoURL }/contents/${ path }`, | ||
{ | ||
method: "DELETE", |
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
src/backends/github/API.js
Outdated
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 }`) |
There was a problem hiding this comment.
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") { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
).
There was a problem hiding this comment.
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.
49a3e32
to
82cd253
Compare
82cd253
to
ef2f819
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
@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! |
@erquhart okay! cool! I can review this :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good! :)
@carlflor thanks for the review! |
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.
@Benaiah I think in editorial mode, the delete entry button does not respect the |
@mbergeronupgrade Please open a new issue for that. |
- 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 thedelete-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)