always show user choice even if no more in enum in columns

This commit is contained in:
simon lehericey 2024-12-12 09:46:59 +01:00
parent 6e5aa90bc7
commit c578c88f48
No known key found for this signature in database
GPG key ID: CDE670D827C7B3C5
2 changed files with 3 additions and 16 deletions

View file

@ -70,7 +70,7 @@ class Columns::ChampColumn < Column
when :date
parse_datetime(value)&.to_date
when :enum
parse_enum(value)
value
when :enums
parse_enums(value)
else
@ -91,9 +91,9 @@ class Columns::ChampColumn < Column
when ['integer_number', 'text'], ['decimal_number', 'text'] # number to text
value
when ['drop_down_list', 'multiple_drop_down_list'] # single list can become multi
[parse_enum(value)].compact_blank
[value]
when ['drop_down_list', 'text'] # single list can become text
parse_enum(value)
value
when ['multiple_drop_down_list', 'drop_down_list'] # multi list can become single
parse_enums(value)&.first
when ['multiple_drop_down_list', 'text'] # multi list can become text
@ -116,11 +116,6 @@ class Columns::ChampColumn < Column
end
end
def parse_enum(value)
return value if options_for_select.blank?
value if options_for_select.to_set(&:second).member?(value)
end
def parse_enums(value)
values = JSON.parse(value)
return values if options_for_select.blank?

View file

@ -121,14 +121,6 @@ describe Columns::ChampColumn do
expect(column('multiple_drop_down_list').value(champ)).to eq(['val1'])
expect(column('text').value(champ)).to eq('val1')
end
context 'value not in options' do
let(:value) { 'toto' }
it do
expect(column('simple_drop_down_list').value(champ)).to eq(nil)
end
end
end
context 'from a multiple_drop_down_list' do