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.removerRemoveForm.helpers.ask(id)opens confirmation anddismiss()clears it.- Pass
{ returnFocus: '#delete' }(orid => '#delete-' + id) as a third argument so cancelling returns focus to the button that opened the prompt. Remover.Message.Confirmed()andCancelled()confirm or dismiss.PostRemover.status(model),target(model), anderror(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.