Merge pull request #7891 from betagouv/improve_condition_js_side
perf(user dossier): améliore la gestion des conditions coté js
This commit is contained in:
commit
9ce75585d6
3 changed files with 27 additions and 12 deletions
|
@ -181,7 +181,14 @@ module Users
|
|||
|
||||
respond_to do |format|
|
||||
format.html { render :brouillon }
|
||||
format.turbo_stream { render layout: false }
|
||||
format.turbo_stream do
|
||||
@to_shows, @to_hides = @dossier.champs
|
||||
.filter(&:conditional?)
|
||||
.partition(&:visible?)
|
||||
.map { |champs| champs_to_one_selector(champs) }
|
||||
|
||||
render(:update, layout: false)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -205,7 +212,14 @@ module Users
|
|||
|
||||
respond_to do |format|
|
||||
format.html { render :modifier }
|
||||
format.turbo_stream { render layout: false }
|
||||
format.turbo_stream do
|
||||
@to_shows, @to_hides = @dossier.champs
|
||||
.filter(&:conditional?)
|
||||
.partition(&:visible?)
|
||||
.map { |champs| champs_to_one_selector(champs) }
|
||||
|
||||
render layout: false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -521,5 +535,12 @@ module Users
|
|||
# rubocop:enable Lint/BooleanSymbol
|
||||
end
|
||||
end
|
||||
|
||||
def champs_to_one_selector(champs)
|
||||
champs
|
||||
.map(&:input_group_id)
|
||||
.map { |id| "##{id}" }
|
||||
.join(',')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
- @dossier.champs.filter(&:conditional?).each do |champ|
|
||||
- if champ.visible?
|
||||
= turbo_stream.show champ.input_group_id
|
||||
- else
|
||||
= turbo_stream.hide champ.input_group_id
|
||||
- if @to_shows.present?
|
||||
= turbo_stream.show_all(@to_shows)
|
||||
- if @to_hides.present?
|
||||
= turbo_stream.hide_all(@to_hides)
|
||||
|
|
|
@ -1,5 +0,0 @@
|
|||
- @dossier.champs.filter(&:conditional?).each do |champ|
|
||||
- if champ.visible?
|
||||
= turbo_stream.show champ.input_group_id
|
||||
- else
|
||||
= turbo_stream.hide champ.input_group_id
|
Loading…
Reference in a new issue