@@ -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,19 @@ const ContainerMenu = ({ hit } : ContainerMenuProps) => {
107108} ;
108109
109110type ContainerCardPreviewProps = {
110- containerId : string ;
111+ hit : ContainerHit ,
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 = ( { hit, showMaxChildren = 5 } : ContainerCardPreviewProps ) => {
116+ const { content } = hit ;
117+ const { childUsageKeys } = content ?? { childUsageKeys : [ ] } ;
118+ const hiddenChildren = childUsageKeys . length - showMaxChildren ;
121119 return (
122120 < Stack direction = "horizontal" gap = { 2 } >
123121 {
124- data . slice ( 0 , showMaxChildren ) . map ( ( { id, blockType, displayName } , idx ) => {
122+ childUsageKeys . slice ( 0 , showMaxChildren ) . map ( ( usageKey , idx ) => {
123+ const blockType = getBlockType ( usageKey ) ;
125124 let blockPreview : ReactNode ;
126125 let classNames ;
127126
@@ -133,7 +132,7 @@ const ContainerCardPreview = ({ containerId, showMaxChildren = 5 }: ContainerCar
133132 < Icon
134133 src = { getItemIcon ( blockType ) }
135134 screenReaderText = { blockType }
136- title = { displayName }
135+ title = { usageKey }
137136 />
138137 ) ;
139138 } else {
@@ -147,7 +146,7 @@ const ContainerCardPreview = ({ containerId, showMaxChildren = 5 }: ContainerCar
147146 }
148147 return (
149148 < div
150- key = { `container-card-preview-block-${ id } ` }
149+ key = { `container-card-preview-block-${ usageKey } ` }
151150 className = { classNames }
152151 >
153152 { blockPreview }
@@ -200,7 +199,7 @@ const ContainerCard = ({ hit } : ContainerCardProps) => {
200199 < BaseCard
201200 itemType = { itemType }
202201 displayName = { displayName }
203- preview = { < ContainerCardPreview containerId = { unitId } /> }
202+ preview = { < ContainerCardPreview hit = { hit } /> }
204203 tags = { tags }
205204 numChildren = { numChildrenCount }
206205 actions = { (
0 commit comments