From 44ba5c2b87fcf7a60169845ccd8f6c1b27be46b7 Mon Sep 17 00:00:00 2001 From: Simon Hansen Date: Wed, 31 Jul 2024 20:51:38 +0200 Subject: [PATCH 1/3] Fix item action guide --- guides/actions/item-actions.md | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/guides/actions/item-actions.md b/guides/actions/item-actions.md index e0529a57..f41b528f 100644 --- a/guides/actions/item-actions.md +++ b/guides/actions/item-actions.md @@ -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 @@ -152,10 +154,10 @@ defmodule DemoWeb.ItemAction.SoftDelete do def label(_assigns), do: Backpex.translate("Delete") @impl Backpex.ItemAction - def confirm_label(_assigns), do: Backpex.translate("Delete") + def confirm(_assigns), do: Backpex.translate("Delete") @impl Backpex.ItemAction - def cancel_label(_assigns), do: Backpex.translate("Cancel") + def cancel(_assigns), do: Backpex.translate("Cancel") @impl Backpex.ItemAction def handle(socket, items, data) do @@ -189,4 +191,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. \ No newline at end of file +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/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. From 39d4b574c855c23e6350bbf854636c72c8360403 Mon Sep 17 00:00:00 2001 From: Simon Hansen Date: Wed, 31 Jul 2024 21:00:35 +0200 Subject: [PATCH 2/3] Update item-actions.md --- guides/actions/item-actions.md | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/guides/actions/item-actions.md b/guides/actions/item-actions.md index f41b528f..6688b351 100644 --- a/guides/actions/item-actions.md +++ b/guides/actions/item-actions.md @@ -154,10 +154,13 @@ defmodule DemoWeb.ItemAction.SoftDelete do def label(_assigns), do: Backpex.translate("Delete") @impl Backpex.ItemAction - def confirm(_assigns), do: Backpex.translate("Delete") + def confirm(_assigns), do: "Why do you want to delete this item?" @impl Backpex.ItemAction - def cancel(_assigns), do: Backpex.translate("Cancel") + def confirm_label(_assigns), do: Backpex.translate("Delete") + + @impl Backpex.ItemAction + def cancel_label(_assigns), do: Backpex.translate("Cancel") @impl Backpex.ItemAction def handle(socket, items, data) do @@ -191,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/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. From 62c833e4cf0ab9ee3945a3437d4b133bed591bdc Mon Sep 17 00:00:00 2001 From: Simon Hansen Date: Wed, 7 Aug 2024 21:07:34 +0200 Subject: [PATCH 3/3] Fix changeset/3 arity --- guides/actions/item-actions.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/guides/actions/item-actions.md b/guides/actions/item-actions.md index 6688b351..2aabbd4d 100644 --- a/guides/actions/item-actions.md +++ b/guides/actions/item-actions.md @@ -144,7 +144,7 @@ defmodule DemoWeb.ItemAction.SoftDelete do @required_fields ~w[reason]a @impl Backpex.ItemAction - def changeset(change, attrs) do + def changeset(change, attrs, _meta) do change |> cast(attrs, @required_fields) |> validate_required(@required_fields) @@ -190,7 +190,7 @@ defmodule DemoWeb.ItemAction.SoftDelete do end ``` -In the above example, we define an item action to soft delete users. The item action will also ask the user for a reason before the user can be deleted. The user needs to fill out the reason field before the item action can be performed. The reason field is defined in the `fields/0` function. The `changeset/2` function is used to validate the user input. +In the above example, we define an item action to soft delete users. The item action will also ask the user for a reason before the user can be deleted. The user needs to fill out the reason field before the item action can be performed. The reason field is defined in the `fields/0` function. The `changeset/3` function is used to validate the user input. 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.