feat: unit cards in library [FC-0083] (#1742)

Unit cards in library and rename BaseComponentCard -> BaseCard
This commit is contained in:
Rômulo Penido
2025-03-31 12:54:07 -03:00
committed by GitHub
parent df7405ec39
commit 98ae74e78c
20 changed files with 352 additions and 103 deletions

View File

@@ -105,7 +105,7 @@ export interface ContentHitTags {
*/
interface BaseContentHit {
id: string;
type: 'course_block' | 'library_block' | 'collection';
type: 'course_block' | 'library_block' | 'collection' | 'library_container';
displayName: string;
usageKey: string;
blockId: string;
@@ -167,11 +167,26 @@ export interface CollectionHit extends BaseContentHit {
published?: ContentPublishedData;
}
/**
* Information about a single container returned in the search results
* Defined in edx-platform/openedx/core/djangoapps/content/search/documents.py
*/
export interface ContainerHit extends BaseContentHit {
type: 'library_container';
blockType: 'unit'; // This should be expanded to include other container types
numChildren?: number;
published?: ContentPublishedData;
publishStatus: PublishStatus;
formatted: BaseContentHit['formatted'] & { published?: ContentPublishedData, };
}
export type HitType = ContentHit | CollectionHit | ContainerHit;
/**
* Convert search hits to camelCase
* @param hit A search result directly from Meilisearch
*/
export function formatSearchHit(hit: Record<string, any>): ContentHit | CollectionHit {
export function formatSearchHit(hit: Record<string, any>): HitType {
// eslint-disable-next-line @typescript-eslint/naming-convention
const { _formatted, ...newHit } = hit;
newHit.formatted = {
@@ -214,7 +229,7 @@ export async function fetchSearchResults({
skipBlockTypeFetch = false,
limit = 20,
}: FetchSearchParams): Promise<{
hits: (ContentHit | CollectionHit)[],
hits: HitType[],
nextOffset: number | undefined,
totalHits: number,
blockTypes: Record<string, number>,