99 UserDefinedSection ,
1010 Section ,
1111} from '../types' ;
12- import { getActiveSectionsWithData } from '../utils' ;
12+ import { getActiveSectionsWithData , getFeatures } from '../utils' ;
1313import useDebouncedFetchSection from './useDebouncedFetchSections' ;
1414import useFetchRecommendationPod from './useFetchRecommendationPod' ;
1515import { isAutocompleteSection , isRecommendationsSection } from '../typeGuards' ;
@@ -21,12 +21,15 @@ export default function useSections(
2121 zeroStateSections : UserDefinedSection [ ] | undefined ,
2222 advancedParameters ?: AdvancedParameters
2323) {
24- const zeroStateActiveSections = ! query . length && zeroStateSections ;
24+ const zeroStateActiveSections = ! query . length && zeroStateSections ?. length ;
2525
2626 // Define All Sections
27- const activeSections = zeroStateActiveSections ? zeroStateSections : sections ;
27+ const [ activeSections , setActiveSections ] = useState < UserDefinedSection [ ] > (
28+ zeroStateActiveSections ? zeroStateSections : sections
29+ ) ;
2830 const sectionsRefs = useRef < RefObject < HTMLLIElement > [ ] > ( activeSections . map ( ( ) => createRef ( ) ) ) ;
2931 const [ activeSectionsWithData , setActiveSectionsWithData ] = useState < Section [ ] > ( [ ] ) ;
32+
3033 const autocompleteSections = useMemo (
3134 ( ) =>
3235 activeSections ?. filter ( ( config : UserDefinedSection ) =>
@@ -56,6 +59,21 @@ export default function useSections(
5659 recommendationsSections
5760 ) ;
5861
62+ // Remove sections if necessary
63+ useEffect ( ( ) => {
64+ const features = getFeatures ( Object . values ( podsData || { } ) ?. [ 0 ] ?. request ) ;
65+
66+ if ( zeroStateActiveSections ) {
67+ if ( ! features . featureDisplayZeroStateRecommendations ) {
68+ setActiveSections ( [ ] ) ;
69+ } else {
70+ setActiveSections ( zeroStateSections ) ;
71+ }
72+ } else {
73+ setActiveSections ( sections ) ;
74+ }
75+ } , [ zeroStateSections , zeroStateActiveSections , sections , podsData ] ) ;
76+
5977 // Merge Recommendation Pods Display Name from Dashboard
6078 const activeSectionConfigs = useMemo (
6179 ( ) =>
0 commit comments