Skip to content

Commit 9d3a05f

Browse files
authored
feat: show children count in collection card (#1298)
1 parent 053a9b1 commit 9d3a05f

File tree

4 files changed

+16
-4
lines changed

4 files changed

+16
-4
lines changed

src/library-authoring/components/CollectionCard.test.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ const CollectionHitSample: CollectionHit = {
1717
},
1818
created: 1722434322294,
1919
modified: 1722434322294,
20+
numChildren: 2,
2021
tags: {},
2122
};
2223

@@ -32,7 +33,8 @@ describe('<CollectionCard />', () => {
3233
it('should render the card with title and description', () => {
3334
render(<CollectionCard collectionHit={CollectionHitSample} />);
3435

35-
expect(screen.getByText('Collection Display Formated Name')).toBeInTheDocument();
36-
expect(screen.getByText('Collection description')).toBeInTheDocument();
36+
expect(screen.queryByText('Collection Display Formated Name')).toBeInTheDocument();
37+
expect(screen.queryByText('Collection description')).toBeInTheDocument();
38+
expect(screen.queryByText('Collection (2)')).toBeInTheDocument();
3739
});
3840
});

src/library-authoring/components/CollectionCard.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,13 @@ const CollectionCard = ({ collectionHit } : CollectionCardProps) => {
2121
type,
2222
formatted,
2323
tags,
24+
numChildren,
2425
} = collectionHit;
2526
const { displayName = '', description = '' } = formatted;
27+
const blockTypeDisplayName = numChildren ? intl.formatMessage(
28+
messages.collectionTypeWithCount,
29+
{ numChildren },
30+
) : intl.formatMessage(messages.collectionType);
2631

2732
return (
2833
<BaseComponentCard
@@ -40,7 +45,7 @@ const CollectionCard = ({ collectionHit } : CollectionCardProps) => {
4045
/>
4146
</ActionRow>
4247
)}
43-
blockTypeDisplayName={intl.formatMessage(messages.collectionType)}
48+
blockTypeDisplayName={blockTypeDisplayName}
4449
openInfoSidebar={() => {}}
4550
/>
4651
);

src/library-authoring/components/messages.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ const messages = defineMessages({
1616
defaultMessage: 'Collection',
1717
description: 'Collection type text',
1818
},
19+
collectionTypeWithCount: {
20+
id: 'course-authoring.library-authoring.collection.type-with-count',
21+
defaultMessage: 'Collection ({numChildren})',
22+
description: 'Collection type text with children count',
23+
},
1924
menuEdit: {
2025
id: 'course-authoring.library-authoring.component.menu.edit',
2126
defaultMessage: 'Edit',

src/search-manager/data/api.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ export interface ContentHit extends BaseContentHit {
135135
*/
136136
export interface CollectionHit extends BaseContentHit {
137137
description: string;
138-
componentCount?: number;
138+
numChildren?: number;
139139
}
140140

141141
/**

0 commit comments

Comments
 (0)