@@ -14,6 +14,7 @@ const ComponentPanelRoutingItem: React.FC<{}> = () => {
1414
1515 // find the root components that can be associated with a route
1616 // These will be the components that are displayed in the dropdown
17+ console . log ( 'in the comp panel routing, state is ' , state ) ;
1718 let navigableComponents = state . components
1819 . filter ( comp => state . rootComponents . includes ( comp . id ) )
1920 . map ( comp => comp . name ) ;
@@ -22,12 +23,22 @@ const ComponentPanelRoutingItem: React.FC<{}> = () => {
2223 const [ route , setRoute ] = useState ( navigableComponents [ 0 ] ) ;
2324
2425 // TODO: Add a useMemo so that this isn't recalculated on every render
25- const routeId = state . components . find ( comp => comp . name === route ) . id ;
26+ let routeId ;
27+ // check if the component in the drop down still references an existing component
28+ const referencedComponent = state . components . find (
29+ comp => comp . name === route
30+ ) ;
31+ // if so, set the route id for that component to the id of the referenced compnent
32+ if ( referencedComponent ) routeId = referencedComponent . id ;
33+ // otherwise, set the component name and and id to the root component
34+ else {
35+ setRoute ( state . components [ 0 ] . name ) ;
36+ routeId = 1 ;
37+ }
2638
2739 const handleRouteChange = event => {
2840 setRoute ( event . target . value ) ;
2941 } ;
30-
3142
3243 // useDrag hook allows components in left panel to be drag source
3344
0 commit comments