Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: show children count in collection card #1298

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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