1010import django
1111
1212import click
13+ import msgspec
1314from json_logic .meta import JSONLogicExpression
1415from json_logic .meta .expressions import destructure
1516from json_logic .typing import JSON
1617from tabulate import tabulate
1718
19+ from formio_types import AnyComponent , EditGrid , FormioConfiguration , Selectboxes
20+
1821SRC_DIR = Path (__file__ ).parent .parent / "src"
1922sys .path .insert (0 , str (SRC_DIR .resolve ()))
2023
@@ -86,15 +89,11 @@ def analyze_rule(
8689 * ,
8790 rule ,
8891 form ,
89- component_map ,
92+ component_map : dict [ str , AnyComponent ] ,
9093 components_with_affected_visibility ,
9194 data ,
9295):
93- from openforms .formio .service import (
94- get_component_empty_value ,
95- iter_components ,
96- )
97- from openforms .formio .typing import Component
96+ from openforms .formio .service import get_component_empty_value , iter_components
9897 from openforms .forms .constants import LogicActionTypes
9998 from openforms .variables .service import resolve_key
10099
@@ -110,14 +109,14 @@ def analyze_rule(
110109 continue
111110
112111 component = component_map [resolved_key ]
113- if component [ "type" ] == "editgrid" and var_name != resolved_key :
112+ if isinstance ( component , EditGrid ) and var_name != resolved_key :
114113 # We expect data access "editgrid.x.child_key" here, so discard the
115114 # parent key and index. Assuming there are no nested editgrids here
116115 # :see_no_evil:
117116 _ , child_key = var_name .removeprefix (f"{ resolved_key } ." ).split ("." , 1 )
118117
119- children_map : dict [str , Component ] = {
120- child [ " key" ] : child
118+ children_map : dict [str , AnyComponent ] = {
119+ child . key : child
121120 for child in iter_components (
122121 component , recursive = True , recurse_into_editgrid = False
123122 )
@@ -128,13 +127,13 @@ def analyze_rule(
128127
129128 # Visibility of component is not affected and/or component does not have
130129 # clearOnHide enabled, so it's not relevant
131- if resolved_key not in components_with_affected_visibility or not component . get (
132- "clearOnHide " , True
130+ if resolved_key not in components_with_affected_visibility or not getattr (
131+ component , "clear_on_hide " , True
133132 ):
134133 continue
135134
136135 empty_value = get_component_empty_value (component )
137- if component [ "type" ] == "selectboxes" :
136+ if isinstance ( component , Selectboxes ) :
138137 # `get_component_empty_value` returns {"option_a": False, "option_b": False, etc...}
139138 # for a selectboxes component, which is not a useful in this
140139 # context. It is not possible to use a dictionary as a comparison
@@ -148,7 +147,7 @@ def analyze_rule(
148147 # current default that is set when a variable is missing from the
149148 # context. Note that all form variables should be present in the context
150149 # at the moment, but there is no such guarantee for nested data.
151- if comp_value in [empty_value , None , component . get ( "defaultValue" )]:
150+ if comp_value in [empty_value , None , getattr ( component , "default_value" , None )]:
152151 variable_names .add (var_name )
153152
154153 if variable_names :
@@ -218,8 +217,8 @@ def analyze_rule(
218217
219218
220219def report_rules () -> bool :
221- from openforms . formio . service import iter_components
222- from openforms .formio .typing import Component
220+
221+ from openforms .formio .service import _fixup_component_properties , iter_components
223222 from openforms .formio .visibility import get_conditional
224223 from openforms .forms .models import Form
225224
@@ -233,18 +232,23 @@ def report_rules() -> bool:
233232
234233 # Mapping from component to step for quick access
235234 form_steps = form .formstep_set .select_related ("form_definition" )
236- component_map : dict [str , Component ] = {}
235+ component_map : dict [str , AnyComponent ] = {}
237236 for form_step in form_steps :
238- for component in iter_components (
237+ formio_configuration = msgspec . convert (
239238 form_step .form_definition .configuration ,
239+ type = FormioConfiguration ,
240+ dec_hook = _fixup_component_properties ,
241+ )
242+ for component in iter_components (
243+ formio_configuration ,
240244 recursive = True ,
241245 recurse_into_editgrid = False ,
242246 ):
243- component_map [component [ " key" ] ] = component
247+ component_map [component . key ] = component
244248
245249 # Component with visibility affected by a conditional
246250 if get_conditional (component ) is not None :
247- components_with_affected_visibility .add (component [ " key" ] )
251+ components_with_affected_visibility .add (component . key )
248252
249253 # Components with visibility affected by logic rules
250254 for rule in form .formlogic_set .iterator ():
@@ -261,7 +265,7 @@ def report_rules() -> bool:
261265
262266 component = component_map [key ]
263267 children = {
264- child [ " key" ]
268+ child . key
265269 for child in iter_components (
266270 component , recursive = True , recurse_into_editgrid = False
267271 )
0 commit comments