Skip to content

Commit

Permalink
Merge pull request #9389 from tchak/fix-update-champs
Browse files Browse the repository at this point in the history
fix(dossier): removing options from multiselect should update conditions
  • Loading branch information
tchak authored Aug 8, 2023
2 parents 6552360 + b5f7219 commit 17cfc54
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 27 deletions.
8 changes: 6 additions & 2 deletions app/controllers/champs/options_controller.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
class Champs::OptionsController < ApplicationController
include TurboChampsConcern

before_action :authenticate_logged_user!

def remove
@champ = policy_scope(Champ).includes(:champs).find(params[:champ_id])
@champ.remove_option([params[:option]].compact)
champ = policy_scope(Champ).includes(:champs).find(params[:champ_id])
champ.remove_option([params[:option]].compact)
champs = champ.private? ? champ.dossier.champs_private_all : champ.dossier.champs_public_all
@to_show, @to_hide, @to_update = champs_to_turbo_update({ params[:champ_id] => true }, champs)
end
end
4 changes: 1 addition & 3 deletions app/views/champs/options/remove.turbo_stream.haml
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
= fields_for @champ.input_name, @champ do |form|
= turbo_stream.replace @champ.input_group_id do
= render EditableChamp::EditableChampComponent.new champ: @champ, form:
= render partial: 'shared/dossiers/update_champs', locals: { to_show: @to_show, to_hide: @to_hide, to_update: @to_update }
Original file line number Diff line number Diff line change
@@ -1,8 +1 @@
- if @to_show.present?
= turbo_stream.show_all(@to_show)
- if @to_hide.present?
= turbo_stream.hide_all(@to_hide)
- @to_update.each do |champ|
= fields_for champ.input_name, champ do |form|
= turbo_stream.replace champ.input_group_id do
= render EditableChamp::EditableChampComponent.new champ:, form:
= render partial: 'shared/dossiers/update_champs', locals: { to_show: @to_show, to_hide: @to_hide, to_update: @to_update }
15 changes: 15 additions & 0 deletions app/views/shared/dossiers/_update_champs.turbo_stream.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
- if to_show.present?
= turbo_stream.show_all(to_show)
- if to_hide.present?
= turbo_stream.hide_all(to_hide)
- to_update.each do |champ|
= fields_for champ.input_name, champ do |form|
- if champ.refresh_after_update?
= turbo_stream.replace champ.input_group_id do
= render EditableChamp::EditableChampComponent.new champ:, form:
- else
= turbo_stream.update champ.labelledby_id do
= render EditableChamp::ChampLabelContentComponent.new champ:, form:

= turbo_stream.remove_all(".editable-champ .spinner-removable")
= turbo_stream.hide_all(".editable-champ .spinner")
15 changes: 1 addition & 14 deletions app/views/users/dossiers/update.turbo_stream.haml
Original file line number Diff line number Diff line change
@@ -1,17 +1,4 @@
- if @to_show.present?
= turbo_stream.show_all(@to_show)
- if @to_hide.present?
= turbo_stream.hide_all(@to_hide)
- @to_update.each do |champ|
= fields_for champ.input_name, champ do |form|
- if champ.refresh_after_update?
= turbo_stream.replace champ.input_group_id do
= render EditableChamp::EditableChampComponent.new champ:, form:
- else
= turbo_stream.update champ.labelledby_id do
= render EditableChamp::ChampLabelContentComponent.new champ:, form:
= render partial: 'shared/dossiers/update_champs', locals: { to_show: @to_show, to_hide: @to_hide, to_update: @to_update, dossier: @dossier, annotation: false }

= turbo_stream.remove_all(".editable-champ .spinner-removable");
= turbo_stream.hide_all(".editable-champ .spinner");
= turbo_stream.replace_all '.dossier-edit-sticky-footer' do
= render Dossiers::EditFooterComponent.new(dossier: @dossier, annotation: false)

0 comments on commit 17cfc54

Please sign in to comment.