@@ -31,9 +31,18 @@ def get_components():
31
31
for componentPath in data :
32
32
componentData = data [componentPath ]
33
33
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
+ ]:
37
46
components [name ] = componentData ['props' ]
38
47
return components
39
48
@@ -127,50 +136,71 @@ def test(self):
127
136
components_with_props = \
128
137
generate_all_components_with_props (self .components )
129
138
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
+ ])
145
167
146
168
@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' )]
149
171
)
150
- def switch_detauls (n_clicks ):
172
+ def next_page (n_clicks ):
151
173
if n_clicks is None :
152
174
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 ]
158
178
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 ]
167
191
168
192
self .startServer (app )
169
193
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 ))
174
205
)
175
- next_button .click ()
176
- clicks += 1
206
+ button .click ()
0 commit comments