@@ -10,67 +10,81 @@ import { Tooltip } from "react-tooltip";
1010import Pagination from "../../../components/Learn-Components/Pagination" ;
1111import QuizModal from "../../../components/Learn-Components/QuizModal" ;
1212
13- const Chapters = ( { chapterData, courseData, location, serviceMeshesList, TOCData, children } ) => {
14-
13+ const Chapters = ( {
14+ chapterData,
15+ courseData,
16+ location,
17+ serviceMeshesList,
18+ TOCData,
19+ children,
20+ } ) => {
1521 const { frontmatter } = chapterData ;
1622 const [ showQuizModal , setShowQuizModal ] = useState ( false ) ;
1723
1824 const serviceMeshImages = courseData . frontmatter . meshesYouLearn || [ ] ;
19- const tableOfContents = TOCData
20- . filter ( node => ! ! node . fields . section )
21- . map ( toc => ( { section : toc . fields . section , chapter : toc . fields . chapter } ) ) ;
22-
25+ const tableOfContents = TOCData . filter ( ( node ) => ! ! node . fields . section ) . map (
26+ ( toc ) => ( { section : toc . fields . section , chapter : toc . fields . chapter } ) ,
27+ ) ;
2328
2429 const replaceSlugPart = ( index ) => ( oldSlug ) => ( replacement ) => {
2530 let parts = oldSlug . split ( "/" ) ;
2631 parts [ index ] = replacement ;
2732 return parts . join ( "/" ) ;
2833 } ;
2934 const replaceServiceMeshInSlug = replaceSlugPart ( 4 ) ( chapterData . fields . slug ) ;
30- const replaceChapterInSlug = ( slugWithReplacedMesh ) => replaceSlugPart ( 5 ) ( slugWithReplacedMesh ) ;
35+ const replaceChapterInSlug = ( slugWithReplacedMesh ) =>
36+ replaceSlugPart ( 5 ) ( slugWithReplacedMesh ) ;
3137
3238 useEffect ( ( ) => {
33-
3439 let bookmarkPath = location . pathname ;
3540 if ( bookmarkPath . endsWith ( ".html" ) ) {
3641 bookmarkPath = bookmarkPath . replace ( ".html" , "" ) ;
3742 }
38- localStorage . setItem ( `bookmarkpath-${ location . pathname . split ( "/" ) [ 4 ] } ` , bookmarkPath ) ;
43+ localStorage . setItem (
44+ `bookmarkpath-${ location . pathname . split ( "/" ) [ 4 ] } ` ,
45+ bookmarkPath ,
46+ ) ;
3947 } , [ ] ) ;
4048
4149 const isMeshActive = ( sm ) => chapterData . fields . slug . split ( "/" ) [ 4 ] === sm ;
4250
4351 const mapMeshWithFormattedSlug = ( sm , serviceMeshes ) => {
4452 let chapterFound = false ;
45- tableOfContents . forEach ( toc => {
53+ tableOfContents . forEach ( ( toc ) => {
4654 if ( toc . section === sm . fields . section ) {
47- if ( toc . chapter === chapterData . fields . slug . split ( "/" ) [ 5 ] ) chapterFound = true ;
55+ if ( toc . chapter === chapterData . fields . slug . split ( "/" ) [ 5 ] )
56+ chapterFound = true ;
4857 }
4958 } ) ;
5059
51- if ( ! serviceMeshes . map ( sm => sm . section ) . includes ( sm . fields . section ) )
60+ if ( ! serviceMeshes . map ( ( sm ) => sm . section ) . includes ( sm . fields . section ) )
5261 serviceMeshes . push ( {
53- section : sm . fields . section , slug : chapterFound ?
54- replaceServiceMeshInSlug ( sm . fields . section )
55- : replaceChapterInSlug ( replaceServiceMeshInSlug ( sm . fields . section ) ) ( tableOfContents [ 0 ] . chapter )
62+ section : sm . fields . section ,
63+ slug : chapterFound
64+ ? replaceServiceMeshInSlug ( sm . fields . section )
65+ : replaceChapterInSlug ( replaceServiceMeshInSlug ( sm . fields . section ) ) (
66+ tableOfContents [ 0 ] . chapter ,
67+ ) ,
5668 } ) ;
57-
5869 } ;
5970
6071 const getAvailableServiceMeshes = ( ) => {
6172 let serviceMeshes = [ ] ;
62- serviceMeshesList . forEach ( sm => {
73+ serviceMeshesList . forEach ( ( sm ) => {
6374 mapMeshWithFormattedSlug ( sm , serviceMeshes ) ;
6475 } ) ;
6576
6677 return serviceMeshes ;
6778 } ;
6879 const availableServiceMeshesArray = getAvailableServiceMeshes ( ) ;
6980
70- const findServiceMeshImage = ( images , serviceMesh ) => images . find ( image => image . name . toLowerCase ( ) == serviceMesh ) ;
81+ const findServiceMeshImage = ( images , serviceMesh ) =>
82+ images . find ( ( image ) => image . name . toLowerCase ( ) == serviceMesh ) ;
7183 const hasMeshImageData = ( meshImage ) => {
7284 const imagePath = meshImage ?. imagepath ;
73- return Boolean ( imagePath ?. childImageSharp ?. gatsbyImageData || imagePath ?. publicURL ) ;
85+ return Boolean (
86+ imagePath ?. childImageSharp ?. gatsbyImageData || imagePath ?. publicURL ,
87+ ) ;
7488 } ;
7589 const capitalize = ( s ) => s . charAt ( 0 ) . toUpperCase ( ) + s . slice ( 1 ) ;
7690
@@ -81,74 +95,102 @@ const Chapters = ({ chapterData, courseData, location, serviceMeshesList, TOCDat
8195 } )
8296 . map ( ( { section } ) => section ) ;
8397
84- if ( missingServiceMeshImages . length > 0 ) {
98+ if (
99+ process . env . NODE_ENV === "development" &&
100+ missingServiceMeshImages . length > 0
101+ ) {
85102 const context = chapterData ?. fields ?. slug || "unknown-chapter" ;
86- throw new Error ( `[Chapters] Missing meshesYouLearn image data for: ${ missingServiceMeshImages . join ( ", " ) } (chapter: ${ context } ).` ) ;
103+ console . warn (
104+ `[Chapters] Missing meshesYouLearn image data for: ${ missingServiceMeshImages . join ( ", " ) } (chapter: ${ context } ).` ,
105+ ) ;
87106 }
88107
89- const ServiceMeshesAvailable = ( { serviceMeshes } ) => serviceMeshes . map ( ( sm , index ) => {
90- const meshImage = findServiceMeshImage ( serviceMeshImages , sm . section ) ;
108+ const availableServiceMeshesWithImages = availableServiceMeshesArray . filter (
109+ ( { section } ) => {
110+ const meshImage = findServiceMeshImage ( serviceMeshImages , section ) ;
111+ return hasMeshImageData ( meshImage ) ;
112+ } ,
113+ ) ;
91114
92- if ( ! meshImage ?. imagepath ) {
93- if ( process . env . NODE_ENV === "development" ) {
94- console . warn ( `[Chapters] Missing meshesYouLearn image data for: ${ sm . section } (chapter: ${ chapterData . fields . slug } )` ) ;
115+ const ServiceMeshesAvailable = ( { serviceMeshes } ) =>
116+ serviceMeshes . map ( ( sm , index ) => {
117+ const meshImage = findServiceMeshImage ( serviceMeshImages , sm . section ) ;
118+
119+ if ( ! hasMeshImageData ( meshImage ) ) {
120+ return null ;
95121 }
96- return null ;
97- }
98122
99- return (
100- < React . Fragment key = { sm . section || index } >
101- < div className = { `service-mesh-image ${ isMeshActive ( sm . section ) ? "service-mesh-image-active" : "" } ` } >
102- < Link to = { `/${ sm . slug } ` } data-tooltip-id = "mesh-name" data-tooltip-content = { capitalize ( sm . section ) } className = "course" key = { index } >
103- < Image
104- { ...meshImage . imagepath }
105- className = "docker"
106- alt = { sm . section }
107- />
108- </ Link >
109- </ div >
110- < Tooltip
111- id = "mesh-name"
112- place = "bottom"
113-
114- style = { { backgroundColor : "rgb(60,73,79)" } }
115- className = "mesh-tooltip"
116- />
117- </ React . Fragment > ) ;
118- } ) ;
123+ return (
124+ < React . Fragment key = { sm . section || index } >
125+ < div
126+ className = { `service-mesh-image ${ isMeshActive ( sm . section ) ? "service-mesh-image-active" : "" } ` }
127+ >
128+ < Link
129+ to = { `/${ sm . slug } ` }
130+ data-tooltip-id = "mesh-name"
131+ data-tooltip-content = { capitalize ( sm . section ) }
132+ className = "course"
133+ key = { index }
134+ >
135+ < Image
136+ { ...meshImage . imagepath }
137+ className = "docker"
138+ alt = { sm . section }
139+ />
140+ </ Link >
141+ </ div >
142+ < Tooltip
143+ id = "mesh-name"
144+ place = "bottom"
145+ style = { { backgroundColor : "rgb(60,73,79)" } }
146+ className = "mesh-tooltip"
147+ />
148+ </ React . Fragment >
149+ ) ;
150+ } ) ;
119151
120152 if ( showQuizModal ) {
121153 return < QuizModal /> ;
122154 }
123155
124-
125156 return (
126157 < ChapterWrapper >
127158 < Container className = "chapter-container" >
128159 < Row >
129160 < Col $sm = { 12 } $md = { 3 } >
130161 < div className = "toc-switcher-parent-div" >
131- < TOC courseData = { courseData } TOCData = { TOCData } chapterData = { chapterData } location = { location } />
162+ < TOC
163+ courseData = { courseData }
164+ TOCData = { TOCData }
165+ chapterData = { chapterData }
166+ location = { location }
167+ />
132168 < div >
133- { serviceMeshImages . length !== 0 && availableServiceMeshesArray . length != 0 && (
134- < >
135- < h4 > Technologies Available</ h4 >
136- < div className = "service-mesh-switcher" >
137- < ServiceMeshesAvailable serviceMeshes = { availableServiceMeshesArray } />
138- </ div >
139- </ >
140- ) }
169+ { serviceMeshImages . length !== 0 &&
170+ availableServiceMeshesWithImages . length != 0 && (
171+ < >
172+ < h4 > Technologies Available</ h4 >
173+ < div className = "service-mesh-switcher" >
174+ < ServiceMeshesAvailable
175+ serviceMeshes = { availableServiceMeshesWithImages }
176+ />
177+ </ div >
178+ </ >
179+ ) }
141180 </ div >
142181 </ div >
143182 </ Col >
144183 < Col $sm = { 12 } $md = { 9 } >
145184 < div className = "chapter-data" >
146185 < h1 className = "chapter-heading" > { frontmatter . chapterTitle } </ h1 >
147- < SRLWrapper >
148- { children }
149- </ SRLWrapper >
186+ < SRLWrapper > { children } </ SRLWrapper >
150187 </ div >
151- < Pagination TOCData = { TOCData } chapterData = { chapterData } location = { location } showQuizModal = { ( ) => setShowQuizModal ( true ) } />
188+ < Pagination
189+ TOCData = { TOCData }
190+ chapterData = { chapterData }
191+ location = { location }
192+ showQuizModal = { ( ) => setShowQuizModal ( true ) }
193+ />
152194 </ Col >
153195 </ Row >
154196 </ Container >
0 commit comments