feat: show children count in collection card (#1298)

This commit is contained in:
Navin Karkera
2024-09-19 22:20:38 +05:30
committed by GitHub
parent 053a9b1074
commit 9d3a05f1bd
4 changed files with 16 additions and 4 deletions

View File

@@ -17,6 +17,7 @@ const CollectionHitSample: CollectionHit = {
},
created: 1722434322294,
modified: 1722434322294,
numChildren: 2,
tags: {},
};
@@ -32,7 +33,8 @@ describe('<CollectionCard />', () => {
it('should render the card with title and description', () => {
render(<CollectionCard collectionHit={CollectionHitSample} />);
expect(screen.getByText('Collection Display Formated Name')).toBeInTheDocument();
expect(screen.getByText('Collection description')).toBeInTheDocument();
expect(screen.queryByText('Collection Display Formated Name')).toBeInTheDocument();
expect(screen.queryByText('Collection description')).toBeInTheDocument();
expect(screen.queryByText('Collection (2)')).toBeInTheDocument();
});
});

View File

@@ -21,8 +21,13 @@ const CollectionCard = ({ collectionHit } : CollectionCardProps) => {
type,
formatted,
tags,
numChildren,
} = collectionHit;
const { displayName = '', description = '' } = formatted;
const blockTypeDisplayName = numChildren ? intl.formatMessage(
messages.collectionTypeWithCount,
{ numChildren },
) : intl.formatMessage(messages.collectionType);
return (
<BaseComponentCard
@@ -40,7 +45,7 @@ const CollectionCard = ({ collectionHit } : CollectionCardProps) => {
/>
</ActionRow>
)}
blockTypeDisplayName={intl.formatMessage(messages.collectionType)}
blockTypeDisplayName={blockTypeDisplayName}
openInfoSidebar={() => {}}
/>
);

View File

@@ -16,6 +16,11 @@ const messages = defineMessages({
defaultMessage: 'Collection',
description: 'Collection type text',
},
collectionTypeWithCount: {
id: 'course-authoring.library-authoring.collection.type-with-count',
defaultMessage: 'Collection ({numChildren})',
description: 'Collection type text with children count',
},
menuEdit: {
id: 'course-authoring.library-authoring.component.menu.edit',
defaultMessage: 'Edit',

View File

@@ -135,7 +135,7 @@ export interface ContentHit extends BaseContentHit {
*/
export interface CollectionHit extends BaseContentHit {
description: string;
componentCount?: number;
numChildren?: number;
}
/**