@@ -31,9 +31,18 @@ def get_components():
3131 for componentPath in data :
3232 componentData = data [componentPath ]
3333 name = componentPath .split ('/' ).pop ().split ('.' )[0 ]
34- if name not in ['Checklist' , 'ConfirmDialog' , 'ConfirmDialogProvider' ,
35- 'Interval' , 'Graph' , 'Location' , 'Tab' , 'Tabs' ,
36- 'Slider' ]:
34+ if name not in [
35+ 'Checklist' ,
36+ 'ConfirmDialog' ,
37+ 'ConfirmDialogProvider' ,
38+ 'Interval' ,
39+ 'Graph' ,
40+ 'Location' ,
41+ 'Tab' ,
42+ 'Tabs' ,
43+ 'RangeSlider' ,
44+ 'Slider'
45+ ]:
3746 components [name ] = componentData ['props' ]
3847 return components
3948
@@ -127,50 +136,71 @@ def test(self):
127136 components_with_props = \
128137 generate_all_components_with_props (self .components )
129138 app = dash .Dash (__name__ )
130-
131- children = [
132- component (** props ) for component , props in components_with_props
133- ]
134- app .layout = html .Div (
135- children = [
136- html .Button (
137- 'Click for next component' ,
138- id = 'next-component'
139- ),
140- html .Div (id = 'component-container' ),
141- html .Div (id = 'test-details' ),
142- dcc .Link ()
143- ]
144- )
139+ app .config ['suppress_callback_exceptions' ] = True
140+
141+ PAGE_SIZE = 5
142+
143+ children = []
144+ button_ids = []
145+ props_to_add = []
146+ for c , p in components_with_props :
147+ button_id = "{}-button" .format (p ['id' ])
148+ children .append (c (** p ))
149+ children .append (html .Button ('Callback {}' .format (p ['id' ]),
150+ id = button_id ))
151+ button_ids .append (button_id )
152+ p_keys = list (p .keys ())
153+ p_keys .remove ('id' )
154+ if p_keys :
155+ other_key = p_keys [0 ]
156+ props_to_add .append ((
157+ p ['id' ],
158+ button_id ,
159+ other_key ,
160+ p [other_key ]
161+ ))
162+ app .layout = html .Div (children = [
163+ html .Div (id = 'container' ),
164+ html .Button (id = 'next-page' , children = 'next page' ),
165+ dcc .Link ()
166+ ])
145167
146168 @app .callback (
147- dash .dependencies .Output ('test-details ' , 'children' ),
148- [dash .dependencies .Input ('next-component ' , 'n_clicks' )]
169+ dash .dependencies .Output ('container ' , 'children' ),
170+ [dash .dependencies .Input ('next-page ' , 'n_clicks' )]
149171 )
150- def switch_detauls (n_clicks ):
172+ def next_page (n_clicks ):
151173 if n_clicks is None :
152174 n_clicks = 0
153- c , p = components_with_props [n_clicks ]
154- return html .Div ([
155- html .H1 ("Component: {}" .format (c .__name__ )),
156- html .Pre (pprint .pformat (p ))
157- ])
175+ left_bound = n_clicks * PAGE_SIZE * 2
176+ right_bound = (n_clicks + 1 ) * PAGE_SIZE * 2
177+ return children [left_bound : right_bound ]
158178
159- @app .callback (
160- dash .dependencies .Output ('component-container' , 'children' ),
161- [dash .dependencies .Input ('next-component' , 'n_clicks' )]
162- )
163- def switch_component (n_clicks ):
164- if n_clicks is None :
165- n_clicks = 0
166- return children [n_clicks ]
179+ prop_map = {p [0 ]: p [3 ] for p in props_to_add }
180+ for id , button_id , prop , _ in props_to_add :
181+
182+ @app .callback (
183+ dash .dependencies .Output (id , prop ),
184+ [dash .dependencies .Input (button_id , 'n_clicks' )],
185+ [dash .dependencies .State (id , 'id' )]
186+ )
187+ def update_prop (n_clicks , my_id ):
188+ if n_clicks :
189+ return prop_map [my_id ]
190+ return prop_map [my_id ]
167191
168192 self .startServer (app )
169193
170- clicks = 0
171- while clicks < len (children ) - 1 :
172- next_button = WebDriverWait (self .driver , 20 ).until (
173- EC .presence_of_element_located ((By .ID , 'next-component' ))
194+ click_cycle = 0
195+ for button_id in button_ids :
196+ if click_cycle == PAGE_SIZE :
197+ button = WebDriverWait (self .driver , 20 ).until (
198+ EC .presence_of_element_located ((By .ID , 'next-page' ))
199+ )
200+ button .click ()
201+ click_cycle = 0
202+ click_cycle += 1
203+ button = WebDriverWait (self .driver , 20 ).until (
204+ EC .presence_of_element_located ((By .ID , button_id ))
174205 )
175- next_button .click ()
176- clicks += 1
206+ button .click ()
0 commit comments