@@ -434,13 +434,44 @@ function filterHiddenSiteSpaces(siteSpaces: SiteSpace[]): SiteSpace[] {
434434}
435435
436436function parseSiteSectionsAndGroups ( structure : SiteStructure , siteSectionId : string ) {
437- const sectionsAndGroups = getSiteStructureSections ( structure , { ignoreGroups : false } ) ;
437+ const sectionsAndGroups = getSiteStructureSections ( structure ) ;
438+ const visibleSectionsAndGroups = filterSectionsAndGroupsWithHiddenSiteSpaces ( sectionsAndGroups ) ;
438439 const section = parseCurrentSection ( structure , siteSectionId ) ;
439440 assert ( section , `couldn't find section "${ siteSectionId } " in site structure` ) ;
440- return { list : sectionsAndGroups , current : section } satisfies SiteSections ;
441+ return { list : visibleSectionsAndGroups , current : section } satisfies SiteSections ;
441442}
442443
443444function parseCurrentSection ( structure : SiteStructure , siteSectionId : string ) {
444445 const sections = getSiteStructureSections ( structure , { ignoreGroups : true } ) ;
445446 return sections . find ( ( section ) => section . id === siteSectionId ) ;
446447}
448+
449+ type SectionOrGroup = SiteSection | SiteSectionGroup ;
450+
451+ /**
452+ * Filter out sections and groups with hidden site spaces.
453+ */
454+ function filterSectionsAndGroupsWithHiddenSiteSpaces (
455+ sectionsOrGroups : SectionOrGroup [ ]
456+ ) : SectionOrGroup [ ] {
457+ return sectionsOrGroups
458+ . map ( ( entry ) => {
459+ if ( entry . object === 'site-section' ) {
460+ return sectionHasHiddenSiteSpace ( entry ) ? null : entry ;
461+ }
462+
463+ const visibleChildren : SectionOrGroup [ ] = filterSectionsAndGroupsWithHiddenSiteSpaces (
464+ entry . children
465+ ) ;
466+
467+ return {
468+ ...entry ,
469+ children : visibleChildren ,
470+ } ;
471+ } )
472+ . filter ( ( entry ) : entry is SiteSection | SiteSectionGroup => Boolean ( entry ) ) ;
473+ }
474+
475+ function sectionHasHiddenSiteSpace ( section : SiteSection ) {
476+ return section . siteSpaces . every ( ( siteSpace ) => siteSpace . hidden ) ;
477+ }
0 commit comments