fix: datafield edit view was shown alongside othe relements
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
carla 2026-02-26 12:37:52 +01:00
parent faf80bfb4b
commit 9751525a0c
8 changed files with 85 additions and 41 deletions

View file

@ -19,8 +19,8 @@ defmodule MvWeb.CustomFieldLive.IndexComponent do
assigns = assign(assigns, :field_type_label, &MvWeb.Translations.FieldTypes.label/1)
~H"""
<div id={@id} class="mt-8">
<div class="flex">
<div id={@id}>
<div :if={!@show_form} class="flex">
<p class="text-sm text-base-content/70">
{gettext("These will appear in addition to other data when adding new members.")}
</p>
@ -118,15 +118,15 @@ defmodule MvWeb.CustomFieldLive.IndexComponent do
<div>
<p class="font-semibold">
{ngettext(
"%{count} member has a value assigned for this custom field.",
"%{count} members have values assigned for this custom field.",
"%{count} member has a value assigned for this datafield.",
"%{count} members have values assigned for this datafield.",
@custom_field_to_delete.assigned_members_count,
count: @custom_field_to_delete.assigned_members_count
)}
</p>
<p class="mt-2 text-sm">
{gettext(
"All custom field values will be permanently deleted when you delete this custom field."
"All datafield values will be permanently deleted when you delete this datfield."
)}
</p>
</div>
@ -192,8 +192,8 @@ defmodule MvWeb.CustomFieldLive.IndexComponent do
@impl true
def update(assigns, socket) do
# Track previous show_form state to detect when form is closed
previous_show_form = Map.get(socket.assigns, :show_form, false)
# Use socket state so send_update(open_delete_for_id: ...) does not trigger false "form closed"
previous_show_form = socket.assigns[:show_form] || false
# If show_form is explicitly provided in assigns, reset editing state
socket =
@ -205,13 +205,6 @@ defmodule MvWeb.CustomFieldLive.IndexComponent do
socket
end
# Detect when form is closed (show_form changes from true to false)
new_show_form = Map.get(assigns, :show_form, false)
if previous_show_form and not new_show_form do
send(self(), {:editing_section_changed, nil})
end
# Get actor from assigns or fall back to socket assigns
actor = Map.get(assigns, :actor, socket.assigns[:actor])
@ -246,6 +239,13 @@ defmodule MvWeb.CustomFieldLive.IndexComponent do
|> assign(:open_delete_for_id, nil)
end
# Detect form closed only from final socket state (not from assigns alone)
current_show_form = socket.assigns[:show_form] || false
if previous_show_form and not current_show_form do
send(self(), {:editing_section_changed, nil})
end
{:ok, socket}
end