condition component manage invalid target
This commit is contained in:
parent
db4b7fc344
commit
30859774e4
2 changed files with 15 additions and 13 deletions
|
@ -45,26 +45,28 @@ class TypesDeChamp::ConditionsComponent < ApplicationComponent
|
|||
end
|
||||
|
||||
def left_operand_tag(targeted_champ, row_index)
|
||||
current_target_valid = targets.map(&:second).include?(targeted_champ.to_json)
|
||||
|
||||
selected_target = current_target_valid ? targeted_champ.to_json : empty.to_json
|
||||
|
||||
select_tag(
|
||||
input_name_for('targeted_champ'),
|
||||
options_for_select(available_targets, targeted_champ.to_json),
|
||||
options_for_select(targets, selected_target),
|
||||
onchange: "this.form.action = this.form.action + '/change_targeted_champ?row_index=#{row_index}'",
|
||||
id: input_id_for('targeted_champ', row_index)
|
||||
id: input_id_for('targeted_champ', row_index),
|
||||
class: { alert: !current_target_valid }
|
||||
)
|
||||
end
|
||||
|
||||
def targets
|
||||
available_targets
|
||||
.then { |targets| targets.unshift(['Sélectionner', empty.to_json]) }
|
||||
end
|
||||
|
||||
def available_targets
|
||||
targets = @upper_tdcs
|
||||
@upper_tdcs
|
||||
.filter { |tdc| ChampValue::MANAGED_TYPE_DE_CHAMP.values.include?(tdc.type_champ) }
|
||||
.map do |tdc|
|
||||
[tdc.libelle, champ_value(tdc.stable_id).to_json]
|
||||
end
|
||||
|
||||
if targets.present?
|
||||
targets.unshift(['Sélectionner', empty.to_json])
|
||||
end
|
||||
|
||||
targets
|
||||
.map { |tdc| [tdc.libelle, champ_value(tdc.stable_id).to_json] }
|
||||
end
|
||||
|
||||
def operator_tag(operator_name, targeted_champ, row_index)
|
||||
|
|
|
@ -77,7 +77,7 @@ describe TypesDeChamp::ConditionsComponent, type: :component do
|
|||
|
||||
it do
|
||||
expect(page).to have_select('type_de_champ[condition_form][rows][][operator_name]', with_options: ['Est'])
|
||||
expect(page).to have_select('type_de_champ[condition_form][rows][][value]', options: ['val1', 'val2', 'val3'])
|
||||
expect(page).to have_select('type_de_champ[condition_form][rows][][value]', options: ['Sélectionner', 'val1', 'val2', 'val3'])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue