Skip to content

Commit

Permalink
feat: show children count in collection card (#1298)
Browse files Browse the repository at this point in the history
  • Loading branch information
navinkarkera authored Sep 19, 2024
1 parent 053a9b1 commit 9d3a05f
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 4 deletions.
6 changes: 4 additions & 2 deletions src/library-authoring/components/CollectionCard.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const CollectionHitSample: CollectionHit = {
},
created: 1722434322294,
modified: 1722434322294,
numChildren: 2,
tags: {},
};

Expand All @@ -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();
});
});
7 changes: 6 additions & 1 deletion src/library-authoring/components/CollectionCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -40,7 +45,7 @@ const CollectionCard = ({ collectionHit } : CollectionCardProps) => {
/>
</ActionRow>
)}
blockTypeDisplayName={intl.formatMessage(messages.collectionType)}
blockTypeDisplayName={blockTypeDisplayName}
openInfoSidebar={() => {}}
/>
);
Expand Down
5 changes: 5 additions & 0 deletions src/library-authoring/components/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
2 changes: 1 addition & 1 deletion src/search-manager/data/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ export interface ContentHit extends BaseContentHit {
*/
export interface CollectionHit extends BaseContentHit {
description: string;
componentCount?: number;
numChildren?: number;
}

/**
Expand Down

0 comments on commit 9d3a05f

Please sign in to comment.