1- import '@patternfly/patternfly/base/patternfly-shield-inheritable.css ';
1+ import * as React from 'react ';
22import '@patternfly/patternfly/patternfly.min.css' ;
3- import '@patternfly/patternfly/utilities/Accessibility/accessibility.css' ;
43import '@patternfly/quickstarts/dist/quickstarts.css' ;
54import {
6- ProcedureAsciiDocParser ,
5+ ProcQuickStartParser ,
76 QuickStartCatalogPage ,
87 QuickStartContext ,
98 QuickStartDrawer ,
@@ -13,27 +12,47 @@ import {
1312import { Base64 } from 'js-base64' ;
1413
1514export const QuickStartsPreview = ( { initialData : config , filePath, vscode } ) => {
16- const decodedConfig = Base64 . decode ( config ) ;
17- const allQuickStarts = [ ] ;
18- if ( filePath . endsWith ( '.adoc' ) ) {
19- allQuickStarts . push ( ProcedureAsciiDocParser ( decodedConfig ) ) ;
20- } else {
21- allQuickStarts . push ( JSON . parse ( decodedConfig ) ) ;
15+ if ( ! config ) {
16+ console . error ( 'No initialData provided!' ) ;
17+ return < div style = { { padding : '20px' } } > Error: No data provided to preview</ div > ;
18+ }
19+
20+ try {
21+ const decodedConfig = Base64 . decode ( config ) ;
22+ const allQuickStarts = [ ] ;
23+ if ( filePath && filePath . endsWith ( '.adoc' ) ) {
24+ const parsedConfig = JSON . parse ( decodedConfig ) ;
25+ allQuickStarts . push ( ProcQuickStartParser ( parsedConfig ) ) ;
26+ } else {
27+ const parsed = JSON . parse ( decodedConfig ) ;
28+ allQuickStarts . push ( parsed ) ;
29+ }
30+
31+ const [ activeQuickStartID , setActiveQuickStartID ] = useLocalStorage ( 'quickstartId' , '' ) ;
32+ const [ allQuickStartStates , setAllQuickStartStates ] = useLocalStorage ( 'quickstarts' , { } ) ;
33+ const valuesForQuickstartContext = useValuesForQuickStartContext ( {
34+ allQuickStarts,
35+ activeQuickStartID,
36+ setActiveQuickStartID,
37+ allQuickStartStates,
38+ setAllQuickStartStates,
39+ } ) ;
40+ return (
41+ < QuickStartContext . Provider value = { valuesForQuickstartContext } >
42+ < QuickStartDrawer >
43+ < QuickStartCatalogPage />
44+ </ QuickStartDrawer >
45+ </ QuickStartContext . Provider >
46+ ) ;
47+ } catch ( error ) {
48+ console . error ( 'Error in QuickStartsPreview:' , error ) ;
49+ return (
50+ < div style = { { padding : '20px' , color : 'red' } } >
51+ < h2 > Error rendering Quick Start</ h2 >
52+ < pre > { error instanceof Error ? error . stack : String ( error ) } </ pre >
53+ < p > Config length: { config ?. length || 0 } </ p >
54+ < p > File path: { filePath || 'missing' } </ p >
55+ </ div >
56+ ) ;
2257 }
23- const [ activeQuickStartID , setActiveQuickStartID ] = useLocalStorage ( 'quickstartId' , '' ) ;
24- const [ allQuickStartStates , setAllQuickStartStates ] = useLocalStorage ( 'quickstarts' , { } ) ;
25- const valuesForQuickstartContext = useValuesForQuickStartContext ( {
26- allQuickStarts,
27- activeQuickStartID,
28- setActiveQuickStartID,
29- allQuickStartStates,
30- setAllQuickStartStates,
31- } ) ;
32- return (
33- < QuickStartContext . Provider value = { valuesForQuickstartContext } >
34- < QuickStartDrawer >
35- < QuickStartCatalogPage />
36- </ QuickStartDrawer >
37- </ QuickStartContext . Provider >
38- ) ;
3958} ;
0 commit comments