11import * as React from 'react' ;
22import QuickStartContent from './controller/QuickStartContent' ;
33import QuickStartFooter from './controller/QuickStartFooter' ;
4- import { QuickStartContext , QuickStartContextValues } from './utils/quick-start-context' ;
4+ import {
5+ getDefaultQuickStartState ,
6+ QuickStartContext ,
7+ QuickStartContextValues ,
8+ } from './utils/quick-start-context' ;
59import { QuickStart , QuickStartStatus , QuickStartTaskStatus } from './utils/quick-start-types' ;
610
711interface QuickStartControllerProps {
12+ /** The current active quickstart */
813 quickStart : QuickStart ;
14+ /** The next quickstart */
915 nextQuickStarts ?: QuickStart [ ] ;
10- footerClass : string ;
11- contentRef : React . Ref < HTMLDivElement > ;
16+ /** Additional footer classes */
17+ footerClass ?: string ;
18+ /** Ref for the quickstart content */
19+ contentRef ?: React . Ref < HTMLDivElement > ;
1220}
1321
14- const QuickStartController : React . FC < QuickStartControllerProps > = ( {
22+ export const QuickStartController : React . FC < QuickStartControllerProps > = ( {
1523 quickStart,
1624 nextQuickStarts,
1725 contentRef,
@@ -23,13 +31,26 @@ const QuickStartController: React.FC<QuickStartControllerProps> = ({
2331 } = quickStart ;
2432 const totalTasks = tasks ?. length ;
2533 const {
34+ activeQuickStartID,
35+ allQuickStartStates,
36+ setAllQuickStartStates,
2637 activeQuickStartState,
2738 setActiveQuickStart,
2839 setQuickStartTaskNumber,
2940 setQuickStartTaskStatus,
3041 nextStep,
3142 previousStep,
3243 } = React . useContext < QuickStartContextValues > ( QuickStartContext ) ;
44+ React . useEffect ( ( ) => {
45+ // If activeQuickStartID was changed through prop from QuickStartContainer, need to init the state if it does not exist yet
46+ if ( activeQuickStartID && ! allQuickStartStates [ activeQuickStartID ] ) {
47+ setAllQuickStartStates ( {
48+ ...allQuickStartStates ,
49+ [ activeQuickStartID ] : getDefaultQuickStartState ( ) ,
50+ } ) ;
51+ }
52+ } , [ activeQuickStartID , allQuickStartStates , setAllQuickStartStates ] ) ;
53+
3354 const status = activeQuickStartState ?. status as QuickStartStatus ;
3455 const taskNumber = activeQuickStartState ?. taskNumber as number ;
3556 const allTaskStatuses = tasks . map (
0 commit comments