CRUD / foldkit-crud

Deleting

A remover wraps a delete mutation with a confirmation step (Idle, Confirming, Deleting, Deleted, DeleteFailed):

ts
const Remover = Crud.remover('PostRemover', {
  mutation: DeletePostMutation,
  input: id => ({ id }), // the mutation's input for an id
})
// In the page: Bundle.withChild('remover', Remover.bundle), beside the editor.

const PostRemover = Remover.at({ data: Data, model: App.model.remover })
// With the editor's: Bundle.configure('remover', { onOut: PostRemover.onOut })
const RemoveForm = Page.children.remover
  • RemoveForm.helpers.ask(id) opens confirmation and dismiss() clears it.
  • Pass { returnFocus: '#delete' } (or id => '#delete-' + id) as a third argument so cancelling returns focus to the button that opened the prompt.
  • Remover.Message.Confirmed() and Cancelled() confirm or dismiss.
  • PostRemover.status(model), target(model), and error(model) drive the confirmation UI.

When the server mutation returns deleted IDs, Remote removes the record from every list and relation automatically and transitions open details and editors to NotFound.