@@ -12,12 +12,13 @@ import { MoreVert } from '@openedx/paragon/icons';
1212import { Link } from 'react-router-dom' ;
1313
1414import { getItemIcon , getComponentStyleColor } from '../../generic/block-type-utils' ;
15+ import { getBlockType } from '../../generic/key-utils' ;
1516import { ToastContext } from '../../generic/toast-context' ;
1617import { type ContainerHit , PublishStatus } from '../../search-manager' ;
1718import { useComponentPickerContext } from '../common/context/ComponentPickerContext' ;
1819import { useLibraryContext } from '../common/context/LibraryContext' ;
1920import { SidebarActions , useSidebarContext } from '../common/context/SidebarContext' ;
20- import { useContainerChildren , useRemoveItemsFromCollection } from '../data/apiHooks' ;
21+ import { useRemoveItemsFromCollection } from '../data/apiHooks' ;
2122import { useLibraryRoutes } from '../routes' ;
2223import AddComponentWidget from './AddComponentWidget' ;
2324import BaseCard from './BaseCard' ;
@@ -107,21 +108,17 @@ const ContainerMenu = ({ hit } : ContainerMenuProps) => {
107108} ;
108109
109110type ContainerCardPreviewProps = {
110- containerId : string ;
111+ childUsageKeys : Array < string > ;
111112 showMaxChildren ?: number ;
112113} ;
113114
114- const ContainerCardPreview = ( { containerId, showMaxChildren = 5 } : ContainerCardPreviewProps ) => {
115- const { data, isLoading, isError } = useContainerChildren ( containerId ) ;
116- if ( isLoading || isError ) {
117- return null ;
118- }
119-
120- const hiddenChildren = data . length - showMaxChildren ;
115+ const ContainerCardPreview = ( { childUsageKeys, showMaxChildren = 5 } : ContainerCardPreviewProps ) => {
116+ const hiddenChildren = childUsageKeys . length - showMaxChildren ;
121117 return (
122118 < Stack direction = "horizontal" gap = { 2 } >
123119 {
124- data . slice ( 0 , showMaxChildren ) . map ( ( { id, blockType, displayName } , idx ) => {
120+ childUsageKeys . slice ( 0 , showMaxChildren ) . map ( ( usageKey , idx ) => {
121+ const blockType = getBlockType ( usageKey ) ;
125122 let blockPreview : ReactNode ;
126123 let classNames ;
127124
@@ -133,7 +130,7 @@ const ContainerCardPreview = ({ containerId, showMaxChildren = 5 }: ContainerCar
133130 < Icon
134131 src = { getItemIcon ( blockType ) }
135132 screenReaderText = { blockType }
136- title = { displayName }
133+ title = { usageKey }
137134 />
138135 ) ;
139136 } else {
@@ -149,7 +146,7 @@ const ContainerCardPreview = ({ containerId, showMaxChildren = 5 }: ContainerCar
149146 < div
150147 // A container can have multiple instances of the same block
151148 // eslint-disable-next-line react/no-array-index-key
152- key = { `${ id } -${ idx } ` }
149+ key = { `${ usageKey } -${ idx } ` }
153150 className = { classNames }
154151 >
155152 { blockPreview }
@@ -178,6 +175,7 @@ const ContainerCard = ({ hit } : ContainerCardProps) => {
178175 published,
179176 publishStatus,
180177 usageKey : unitId ,
178+ content,
181179 } = hit ;
182180
183181 const numChildrenCount = showOnlyPublished ? (
@@ -188,6 +186,10 @@ const ContainerCard = ({ hit } : ContainerCardProps) => {
188186 showOnlyPublished ? formatted . published ?. displayName : formatted . displayName
189187 ) ?? '' ;
190188
189+ const childUsageKeys : Array < string > = (
190+ showOnlyPublished ? published ?. content ?. childUsageKeys : content ?. childUsageKeys
191+ ) ?? [ ] ;
192+
191193 const { navigateTo } = useLibraryRoutes ( ) ;
192194
193195 const openContainer = useCallback ( ( ) => {
@@ -202,7 +204,7 @@ const ContainerCard = ({ hit } : ContainerCardProps) => {
202204 < BaseCard
203205 itemType = { itemType }
204206 displayName = { displayName }
205- preview = { < ContainerCardPreview containerId = { unitId } /> }
207+ preview = { < ContainerCardPreview childUsageKeys = { childUsageKeys } /> }
206208 tags = { tags }
207209 numChildren = { numChildrenCount }
208210 actions = { (
0 commit comments