@@ -28,9 +28,11 @@ import { VisualizedActions } from '../actions/VisualizedActions';
2828
2929import './ComponentViewer.css' ;
3030
31+ import { labelToKey } from './toolbar/labelUtils' ;
32+
3133export interface Props {
3234 registries : Registries ;
33- dropDown ? : ComponentViewerDropDown ;
35+ dropDowns : ComponentViewerDropDown [ ] ;
3436}
3537
3638class ComponentViewer extends Component < Props , ComponentViewerState > {
@@ -79,13 +81,13 @@ class ComponentViewer extends Component<Props, ComponentViewerState> {
7981 }
8082
8183 renderSelectionPanelAndDemo ( demoEntry : DemoEntry | null ) {
82- const { registries, dropDown } = this . props ;
84+ const { registries, dropDowns } = this . props ;
8385
8486 const {
8587 registryName,
8688 demoName,
8789 filterText,
88- selectedToolbarItem ,
90+ selectedToolbarItems ,
8991 isHelpOn
9092 } = this . state ;
9193
@@ -102,10 +104,9 @@ class ComponentViewer extends Component<Props, ComponentViewerState> {
102104 < div className = "rcv-toolbar-panel" >
103105 < Toolbar
104106 questionMarkToggledOn = { isHelpOn }
107+ dropDowns = { dropDowns }
108+ selectedItems = { selectedToolbarItems }
105109 onQuestionMarkClick = { this . onQuestionMarkToggle }
106- dropDownLabel = { dropDown ? dropDown . label : undefined }
107- dropDownSelected = { selectedToolbarItem }
108- dropDownItems = { dropDown ? dropDown . items : undefined }
109110 onDropDownItemSelection = { this . selectToolbarItem }
110111 />
111112 </ div >
@@ -171,14 +172,33 @@ class ComponentViewer extends Component<Props, ComponentViewerState> {
171172 }
172173
173174 triggerDropDownSelection ( ) {
174- const { dropDown } = this . props ;
175- if ( ! dropDown ) {
175+ const { dropDowns } = this . props ;
176+ if ( dropDowns . length === 0 ) {
176177 return ;
177178 }
178179
179- const { selectedToolbarItem} = this . state ;
180- if ( selectedToolbarItem . length > 0 ) {
181- dropDown . onSelect ( selectedToolbarItem ) ;
180+ const { selectedToolbarItems} = this . state ;
181+ Object . keys ( selectedToolbarItems ) . forEach ( dropDownKey => {
182+ const dropDown = dropDownByLabelKey ( dropDownKey ) ;
183+ const itemKey = selectedToolbarItems [ dropDownKey ] ;
184+ if ( ! dropDown ) {
185+ return ;
186+ }
187+
188+ const itemLabel = dropItemLabelByKey ( ) ;
189+ if ( itemLabel ) {
190+ dropDown . onSelect ( itemLabel ) ;
191+ }
192+
193+ function dropItemLabelByKey ( ) {
194+ const found = dropDown ! . items . filter ( item => labelToKey ( item . label ) === itemKey ) ;
195+ return found . length > 0 ? found [ 0 ] . label : undefined ;
196+ }
197+ } ) ;
198+
199+ function dropDownByLabelKey ( labelKey : string ) {
200+ const found = dropDowns . filter ( dd => labelToKey ( dd . label ) === labelKey ) ;
201+ return found . length ? found [ 0 ] : undefined ;
182202 }
183203 }
184204
@@ -189,14 +209,16 @@ class ComponentViewer extends Component<Props, ComponentViewerState> {
189209 private dropDownKeyBoundActions ( ) {
190210 const result : HotKeyBoundActions = { } ;
191211
192- const { dropDown } = this . props ;
193- if ( ! dropDown ) {
212+ const { dropDowns } = this . props ;
213+ if ( dropDowns . length === 0 ) {
194214 return result ;
195215 }
196216
197- dropDown . items
198- . filter ( item => ! ! item . hotKey )
199- . forEach ( item => result [ item . hotKey ! ] = ( ) => this . selectToolbarItem ( item . label ) ) ;
217+ dropDowns . forEach ( dropDown =>
218+ dropDown . items
219+ . filter ( item => ! ! item . hotKey )
220+ . forEach ( item => result [ item . hotKey ! ] =
221+ ( ) => this . selectToolbarItem ( dropDown . label , item . label ) ) ) ;
200222
201223 return result ;
202224 }
@@ -272,7 +294,8 @@ class ComponentViewer extends Component<Props, ComponentViewerState> {
272294 this . pushUrl ( {
273295 registryName,
274296 demoName : '' ,
275- entryTitle : '' } ) ;
297+ entryTitle : ''
298+ } ) ;
276299 }
277300
278301 private selectDemo = ( demoName : string ) => {
@@ -283,13 +306,20 @@ class ComponentViewer extends Component<Props, ComponentViewerState> {
283306 this . pushUrl ( { entryTitle : title } ) ;
284307 }
285308
286- private selectToolbarItem = ( label : string ) => {
287- const { dropDown} = this . props ;
309+ private selectToolbarItem = ( dropDownLabel : string , itemLabel : string ) => {
310+ const { dropDowns} = this . props ;
311+ const { selectedToolbarItems} = this . state ;
288312
289- this . pushUrl ( { selectedToolbarItem : label } ) ;
313+ this . pushUrl ( {
314+ selectedToolbarItems : {
315+ ...selectedToolbarItems ,
316+ [ labelToKey ( dropDownLabel ) ] : labelToKey ( itemLabel )
317+ }
318+ } ) ;
290319
291- if ( dropDown ) {
292- dropDown . onSelect ( label ) ;
320+ const found = dropDowns . filter ( dd => dd . label === dropDownLabel ) ;
321+ if ( found . length > 0 ) {
322+ found [ 0 ] . onSelect ( itemLabel ) ;
293323 }
294324 }
295325
0 commit comments