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

Fix item action guide #500

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion guides/actions/item-actions.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ Next, we need to implement the item action module.
defmodule DemoWeb.ItemAction.SoftDelete do
use BackpexWeb, :item_action

import Ecto.Changeset

alias Backpex.Resource

@impl Backpex.ItemAction
Expand Down Expand Up @@ -151,6 +153,9 @@ defmodule DemoWeb.ItemAction.SoftDelete do
@impl Backpex.ItemAction
def label(_assigns), do: Backpex.translate("Delete")

@impl Backpex.ItemAction
def confirm(_assigns), do: "Why do you want to delete this item?"
Copy link
Member Author

Choose a reason for hiding this comment

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

The confirm function is mandatory.

Copy link
Member Author

Choose a reason for hiding this comment

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

We could omit the confirm_label and cancel_label

Copy link
Collaborator

Choose a reason for hiding this comment

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

The confirm/1 function determines whether a confirmation modal is shown to the user. We can decide to add the confirm/1, confirm_label/1 and cancel_label/1 functions (a modal is shown) or remove them (no modal is shown) 🤔.

If we add the confirm/1 function as suggested, we must also keep confirm_label/1 and cancel_label/1.

Copy link
Member Author

Choose a reason for hiding this comment

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

The current example in the documentation makes no sense (confirm_label/1 and cancel_label/1 without modal).

If we add the confirm/1 function as suggested, we must also keep confirm_label/1 and cancel_label/1.

Thats not right. When omitted the default values ("Cancel" and "Apply") are used.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I did not see the default implementation 🙃


@impl Backpex.ItemAction
def confirm_label(_assigns), do: Backpex.translate("Delete")

Expand Down Expand Up @@ -189,4 +194,4 @@ In the above example, we define an item action to soft delete users. The item ac

The `handle/3` function is called when the item action is triggered. The handle function receives the socket, the items that should be affected by the action, and the parameters that were submitted by the user.

By default an item action is triggered immediately when the user clicks on the corresponding icon in the resource table or in the show view, but an item actions also supports a confirmation dialog. To enable the confirmation dialog you need to implement the `confirm_label/1` function and return a string that will be displayed in the confirmation dialog. The confirmation dialog will be displayed when the user clicks on the icon in the resource table.
By default an item action is triggered immediately when the user clicks on the corresponding icon in the resource table or in the show view, but an item actions also supports a confirmation dialog. To enable the confirmation dialog you need to implement the `confirm_label/1` function and return a string that will be displayed in the confirmation dialog. The confirmation dialog will be displayed when the user clicks on the icon in the resource table.