File tree Expand file tree Collapse file tree 3 files changed +72
-3
lines changed Expand file tree Collapse file tree 3 files changed +72
-3
lines changed Original file line number Diff line number Diff line change @@ -27,12 +27,19 @@ def get_record
2727 end
2828
2929 def get_smart_action_load_ctx ( fields )
30- fields = fields . reduce ( { } ) { |p , c | p . update ( c [ :field ] => c . merge! ( value : nil ) ) }
30+ fields = fields . reduce ( { } ) do |p , c |
31+ ForestLiana ::WidgetsHelper . set_field_widget ( c )
32+ p . update ( c [ :field ] => c . merge! ( value : nil ) )
33+ end
3134 { :record => get_record , :fields => fields }
3235 end
3336
3437 def get_smart_action_change_ctx ( fields )
35- fields = fields . reduce ( { } ) { |p , c | p . update ( c [ :field ] => c . permit! . to_h ) }
38+ fields = fields . reduce ( { } ) do |p , c |
39+ field = c . permit! . to_h . symbolize_keys
40+ ForestLiana ::WidgetsHelper . set_field_widget ( field )
41+ p . update ( c [ :field ] => field )
42+ end
3643 { :record => get_record , :fields => fields }
3744 end
3845
Original file line number Diff line number Diff line change 1+ require 'set'
2+
3+ module ForestLiana
4+ module WidgetsHelper
5+
6+ @widget_edit_list = [
7+ 'address editor' ,
8+ 'belongsto typeahead' ,
9+ 'belongsto dropdown' ,
10+ 'boolean editor' ,
11+ 'checkboxes' ,
12+ 'color editor' ,
13+ 'date editor' ,
14+ 'dropdown' ,
15+ 'embedded document editor' ,
16+ 'file picker' ,
17+ 'json code editor' ,
18+ 'input array' ,
19+ 'multiple select' ,
20+ 'number input' ,
21+ 'point editor' ,
22+ 'price editor' ,
23+ 'radio button' ,
24+ 'rich text' ,
25+ 'text area editor' ,
26+ 'text editor' ,
27+ 'time input' ,
28+ ]
29+
30+ @v1_to_v2_edit_widgets_mapping = {
31+ address : 'address editor' ,
32+ 'belongsto select' : 'belongsto dropdown' ,
33+ 'color picker' : 'color editor' ,
34+ 'date picker' : 'date editor' ,
35+ price : 'price editor' ,
36+ 'JSON editor' : 'json code editor' ,
37+ 'rich text editor' : 'rich text' ,
38+ 'text area' : 'text area editor' ,
39+ 'text input' : 'text editor' ,
40+ }
41+
42+ def self . set_field_widget ( field )
43+
44+ if field [ :widget ]
45+ if @v1_to_v2_edit_widgets_mapping [ field [ :widget ] . to_sym ]
46+ field [ :widgetEdit ] = { name : @v1_to_v2_edit_widgets_mapping [ field [ :widget ] . to_sym ] , parameters : { } }
47+ elsif @widget_edit_list . include? ( field [ :widget ] )
48+ field [ :widgetEdit ] = { name : field [ :widget ] , parameters : { } }
49+ end
50+ end
51+
52+ if !field . key? ( :widgetEdit )
53+ field [ :widgetEdit ] = nil
54+ end
55+
56+ field . delete ( :widget )
57+ end
58+ end
59+ end
Original file line number Diff line number Diff line change 114114 it 'should respond 200' do
115115 post '/forest/actions/my_action/hooks/change' , JSON . dump ( params ) , 'CONTENT_TYPE' => 'application/json'
116116 expect ( response . status ) . to eq ( 200 )
117- expect ( JSON . parse ( response . body ) ) . to eq ( { 'fields' => [ updated_foo . merge ( { :value => 'baz' } ) . stringify_keys ] } )
117+ expected = updated_foo . merge ( { :value => 'baz' } )
118+ expected [ :widgetEdit ] = nil
119+ expected . delete ( :widget )
120+ expect ( JSON . parse ( response . body ) ) . to eq ( { 'fields' => [ expected . stringify_keys ] } )
118121 end
119122
120123 it 'should respond 500 with bad params' do
You can’t perform that action at this time.
0 commit comments