1313 SuccessResult ,
1414 WebHookResult ,
1515)
16- from forestadmin .rpc_common .serializers .utils import camel_to_snake_case , enum_to_str_or_value , snake_to_camel_case
16+ from forestadmin .rpc_common .serializers .utils import enum_to_str_or_value
1717
1818
1919class ActionSerializer :
@@ -31,22 +31,23 @@ async def serialize(action_name: str, collection: Collection) -> dict:
3131 # ]
3232
3333 return {
34- "scope" : action .scope .value ,
35- "generateFile " : action .generate_file or False ,
36- "staticForm " : action .static_form or False ,
34+ "scope" : action .scope .value . lower () ,
35+ "is_generate_file " : action .generate_file or False ,
36+ "static_form " : action .static_form or False ,
3737 "description" : action .description ,
38- "submitButtonLabel " : action .submit_button_label ,
38+ "submit_button_label " : action .submit_button_label ,
3939 "form" : ActionFormSerializer .serialize (form ) if form is not None else [],
40+ "execute" : {}, # TODO: I'm pretty sure this is not needed
4041 }
4142
4243 @staticmethod
4344 def deserialize (action : dict ) -> dict :
4445 return {
45- "scope" : ActionsScope (action ["scope" ]),
46- "generate_file" : action ["generateFile " ],
47- "static_form" : action ["staticForm " ],
46+ "scope" : ActionsScope (action ["scope" ]. capitalize () ),
47+ "generate_file" : action ["is_generate_file " ],
48+ "static_form" : action ["static_form " ],
4849 "description" : action ["description" ],
49- "submit_button_label" : action ["submitButtonLabel " ],
50+ "submit_button_label" : action ["submit_button_label " ],
5051 "form" : ActionFormSerializer .deserialize (action ["form" ]) if action ["form" ] is not None else [],
5152 }
5253
@@ -57,35 +58,35 @@ def serialize(form) -> list[dict]:
5758 serialized_form = []
5859
5960 for field in form :
61+ tmp_field = {}
6062 if field ["type" ] == ActionFieldType .LAYOUT :
6163 if field ["component" ] == "Page" :
62- serialized_form .append (
63- {
64- ** field ,
65- "type" : "Layout" ,
66- "elements" : ActionFormSerializer .serialize (field ["elements" ]),
67- }
68- )
64+ tmp_field = {
65+ ** field ,
66+ "type" : "Layout" ,
67+ "elements" : ActionFormSerializer .serialize (field ["elements" ]),
68+ }
6969
7070 if field ["component" ] == "Row" :
71- serialized_form .append (
72- {
73- ** field ,
74- "type" : "Layout" ,
75- "fields" : ActionFormSerializer .serialize (field ["fields" ]),
76- }
77- )
71+ tmp_field = {
72+ ** field ,
73+ "type" : "Layout" ,
74+ "fields" : ActionFormSerializer .serialize (field ["fields" ]),
75+ }
7876 else :
7977 tmp_field = {
80- ** {snake_to_camel_case ( k ) : v for k , v in field .items ()},
78+ ** {k : v for k , v in field .items ()},
8179 "type" : enum_to_str_or_value (field ["type" ]),
8280 }
8381 if field ["type" ] == ActionFieldType .FILE :
8482 tmp_field .update (ActionFormSerializer ._serialize_file_field (tmp_field ))
85- print (tmp_field .keys ())
8683 if field ["type" ] == ActionFieldType .FILE_LIST :
8784 tmp_field .update (ActionFormSerializer ._serialize_file_list_field (tmp_field ))
88- serialized_form .append (tmp_field )
85+
86+ if "if_" in tmp_field :
87+ tmp_field ["if_condition" ] = tmp_field ["if_" ]
88+ del tmp_field ["if_" ]
89+ serialized_form .append (tmp_field )
8990
9091 return serialized_form
9192
@@ -105,7 +106,6 @@ def _serialize_file_field(field: dict) -> dict:
105106 ret ["defaultValue" ] = ActionFormSerializer ._serialize_file_obj (field ["defaultValue" ])
106107 if field .get ("value" ):
107108 ret ["value" ] = ActionFormSerializer ._serialize_file_obj (field ["value" ])
108- return ret
109109
110110 @staticmethod
111111 def _serialize_file_obj (f : File ) -> dict :
@@ -148,34 +148,35 @@ def deserialize(form: list) -> list[dict]:
148148 deserialized_form = []
149149
150150 for field in form :
151+ tmp_field = {}
151152 if field ["type" ] == "Layout" :
152153 if field ["component" ] == "Page" :
153- deserialized_form .append (
154- {
155- ** field ,
156- "type" : ActionFieldType ("Layout" ),
157- "elements" : ActionFormSerializer .deserialize (field ["elements" ]),
158- }
159- )
154+ tmp_field = {
155+ ** field ,
156+ "type" : ActionFieldType ("Layout" ),
157+ "elements" : ActionFormSerializer .deserialize (field ["elements" ]),
158+ }
160159
161160 if field ["component" ] == "Row" :
162- deserialized_form .append (
163- {
164- ** field ,
165- "type" : ActionFieldType ("Layout" ),
166- "fields" : ActionFormSerializer .deserialize (field ["fields" ]),
167- }
168- )
161+ tmp_field = {
162+ ** field ,
163+ "type" : ActionFieldType ("Layout" ),
164+ "fields" : ActionFormSerializer .deserialize (field ["fields" ]),
165+ }
169166 else :
170167 tmp_field = {
171- ** {camel_to_snake_case ( k ) : v for k , v in field .items ()},
168+ ** {k : v for k , v in field .items ()},
172169 "type" : ActionFieldType (field ["type" ]),
173170 }
174171 if tmp_field ["type" ] == ActionFieldType .FILE :
175172 tmp_field .update (ActionFormSerializer ._deserialize_file_field (tmp_field ))
176173 if tmp_field ["type" ] == ActionFieldType .FILE_LIST :
177174 tmp_field .update (ActionFormSerializer ._deserialize_file_list_field (tmp_field ))
178- deserialized_form .append (tmp_field )
175+
176+ if "if_condition" in tmp_field :
177+ tmp_field ["if_" ] = tmp_field ["if_condition" ]
178+ del tmp_field ["if_condition" ]
179+ deserialized_form .append (tmp_field )
179180
180181 return deserialized_form
181182
0 commit comments