Skip to content

Commit

Permalink
chore(smart-actions): transform legacy widgets in hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
GuillaumeCisco committed Dec 3, 2020
1 parent 5db679f commit 297bf88
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 2 deletions.
10 changes: 8 additions & 2 deletions app/controllers/forest_liana/actions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,18 @@ def get_record
end

def get_smart_action_load_ctx(fields)
fields = fields.reduce({}) {|p, c| p.update(c[:field] => c.merge!(value: nil))}
fields = fields.reduce({}) do |p, c|
ForestLiana::WidgetsHelper.set_field_widget(c)
p.update(c[:field] => c.merge!(value: nil))
end
{:record => get_record, :fields => fields}
end

def get_smart_action_change_ctx(fields)
fields = fields.reduce({}) {|p, c| p.update(c[:field] => c.permit!.to_h)}
fields = fields.reduce({}) do |p, c|
ForestLiana::WidgetsHelper.set_field_widget(c)
p.update(c[:field] => c.permit!.to_h)
end
{:record => get_record, :fields => fields}
end

Expand Down
55 changes: 55 additions & 0 deletions app/helpers/forest_liana/widgets_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
require 'set'

module ForestLiana
module WidgetsHelper

widget_edit_list = [
'address editor',
'belongsto typeahead',
'belongsto dropdown',
'boolean editor',
'checkboxes',
'color editor',
'date editor',
'dropdown',
'embedded document editor',
'file picker',
'json code editor',
'input array',
'multiple select',
'number input',
'point editor',
'price editor',
'radio button',
'rich text',
'text area editor',
'text editor',
'time input',
]

v1_to_v2_edit_widgets_mapping = {
address: 'address editor',
'belongsto select': 'belongsto dropdown',
'color picker': 'color editor',
'date picker': 'date editor',
price: 'price editor',
'JSON editor': 'json code editor',
'rich text editor': 'rich text',
'text area': 'text area editor',
'text input': 'text editor',
}

def set_field_widget(field)
field[:widgetEdit] = nil
if field[:widget] && !field[:widgetEdit]
if v1_to_v2_edit_widgets_mapping[field[:widget]]
field[:widgetEdit] = {name: v1_to_v2_edit_widgets_mapping[field[:widget]], parameters: {}}
elsif widget_edit_list.include?(field[:widget])
field[:widgetEdit] = {name: field[:widget], parameters: {}}
end
end

field.delete(:widget)
end
end
end

0 comments on commit 297bf88

Please sign in to comment.