@@ -52,12 +52,14 @@ def handle_result(result, action)
5252 return render status : 500 , json : { error : 'Error in smart action load hook: hook must return an array of fields' }
5353 end
5454
55+ result = SmartActionFormParser . extract_fields_and_layout ( result )
56+
5557 # Validate that the fields are well formed.
5658 begin
5759 # action.hooks[:change] is a hashmap here
5860 # to do the validation, only the hook names are require
5961 change_hooks_name = action . hooks [ :change ] . nil? ? nil : action . hooks [ :change ] . keys
60- ForestLiana ::SmartActionFieldValidator . validate_smart_action_fields ( result , action . name , change_hooks_name )
62+ ForestLiana ::SmartActionFieldValidator . validate_smart_action_fields ( result [ :fields ] , action . name , change_hooks_name )
6163 rescue ForestLiana ::Errors ::SmartActionInvalidFieldError => invalid_field_error
6264 FOREST_LOGGER . warn invalid_field_error . message
6365 rescue ForestLiana ::Errors ::SmartActionInvalidFieldHookError => invalid_hook_error
@@ -67,8 +69,8 @@ def handle_result(result, action)
6769 end
6870
6971 # Apply result on fields (transform the object back to an array), preserve order.
70- fields = result . map do |field |
71- updated_field = result . find { |f | f [ :field ] == field [ :field ] }
72+ fields = result [ :fields ] . map do |field |
73+ updated_field = result [ :fields ] . find { |f | f [ :field ] == field [ :field ] }
7274
7375 # Reset `value` when not present in `enums` (which means `enums` has changed).
7476 if updated_field [ :enums ] . is_a? ( Array )
@@ -88,7 +90,10 @@ def handle_result(result, action)
8890 updated_field . transform_keys { |key | key . to_s . camelize ( :lower ) }
8991 end
9092
91- render serializer : nil , json : { fields : fields } , status : :ok
93+ response = { fields : fields }
94+ response [ :layout ] = result [ :layout ] unless result [ :layout ] . all? { |element | element [ :component ] == 'input' }
95+
96+ render serializer : nil , json : response , status : :ok
9297 end
9398
9499 def load
0 commit comments