fix(dossier): should refresh dossier footer when removing options from multiselect

This commit is contained in:
Paul Chavard 2023-08-31 12:22:53 +02:00
parent dd85a495e0
commit 3a54e44b57
8 changed files with 28 additions and 13 deletions

View file

@ -5,8 +5,9 @@ class Champs::OptionsController < ApplicationController
def remove def remove
champ = policy_scope(Champ).includes(:champs).find(params[:champ_id]) champ = policy_scope(Champ).includes(:champs).find(params[:champ_id])
champ.remove_option([params[:option]].compact) champ.remove_option([params[:option]].compact, true)
champs = champ.private? ? champ.dossier.champs_private_all : champ.dossier.champs_public_all champs = champ.private? ? champ.dossier.champs_private_all : champ.dossier.champs_public_all
@dossier = champ.private? ? nil : champ.dossier
@to_show, @to_hide, @to_update = champs_to_turbo_update({ params[:champ_id] => true }, champs) @to_show, @to_hide, @to_update = champs_to_turbo_update({ params[:champ_id] => true }, champs)
end end
end end

View file

@ -62,8 +62,12 @@ class Champs::DropDownListChamp < Champ
options.include?(value) options.include?(value)
end end
def remove_option(options) def remove_option(options, touch = false)
update_column(:value, nil) if touch
update(value: nil)
else
update_column(:value, nil)
end
end end
private private

View file

@ -70,8 +70,12 @@ class Champs::LinkedDropDownListChamp < Champ
options.include?(primary_value) || options.include?(secondary_value) options.include?(primary_value) || options.include?(secondary_value)
end end
def remove_option(options) def remove_option(options, touch = false)
update_column(:value, nil) if touch
update(value: nil)
else
update_column(:value, nil)
end
end end
private private

View file

@ -51,8 +51,13 @@ class Champs::MultipleDropDownListChamp < Champ
(selected_options - options).size != selected_options.size (selected_options - options).size != selected_options.size
end end
def remove_option(options) def remove_option(options, touch = false)
update_column(:value, (selected_options - options).to_json) value = (selected_options - options).to_json
if touch
update(value:)
else
update_columns(value:)
end
end end
def focusable_input_id def focusable_input_id

View file

@ -1 +1 @@
= render partial: 'shared/dossiers/update_champs', locals: { to_show: @to_show, to_hide: @to_hide, to_update: @to_update } = render partial: 'shared/dossiers/update_champs', locals: { to_show: @to_show, to_hide: @to_hide, to_update: @to_update, dossier: @dossier }

View file

@ -1 +1 @@
= render partial: 'shared/dossiers/update_champs', locals: { to_show: @to_show, to_hide: @to_hide, to_update: @to_update } = render partial: 'shared/dossiers/update_champs', locals: { to_show: @to_show, to_hide: @to_hide, to_update: @to_update, dossier: nil }

View file

@ -13,3 +13,7 @@
= turbo_stream.remove_all(".editable-champ .spinner-removable") = turbo_stream.remove_all(".editable-champ .spinner-removable")
= turbo_stream.hide_all(".editable-champ .spinner") = turbo_stream.hide_all(".editable-champ .spinner")
- if dossier.present?
= turbo_stream.replace_all '.dossier-edit-sticky-footer' do
= render Dossiers::EditFooterComponent.new(dossier:, annotation: false)

View file

@ -1,4 +1 @@
= render partial: 'shared/dossiers/update_champs', locals: { to_show: @to_show, to_hide: @to_hide, to_update: @to_update, dossier: @dossier, annotation: false } = render partial: 'shared/dossiers/update_champs', locals: { to_show: @to_show, to_hide: @to_hide, to_update: @to_update, dossier: @dossier }
= turbo_stream.replace_all '.dossier-edit-sticky-footer' do
= render Dossiers::EditFooterComponent.new(dossier: @dossier, annotation: false)