feat: improve collection sidebar (#1320)

* feat: improve collection sidebar

* feat: add comments to splice blockTypesArray code

Co-authored-by: Jillian <jill@opencraft.com>
---------

Co-authored-by: Jillian <jill@opencraft.com>
Co-authored-by: Chris Chávez <xnpiochv@gmail.com>
This commit is contained in:
Rômulo Penido
2024-09-27 23:24:12 -03:00
committed by GitHub
parent c80483c053
commit 4d67e8bda9
29 changed files with 1155 additions and 139 deletions

View File

@@ -101,6 +101,8 @@ interface BaseContentHit {
id: string;
type: 'course_block' | 'library_block' | 'collection';
displayName: string;
usageKey: string;
blockId: string;
/** The course or library ID */
contextKey: string;
org: string;
@@ -117,8 +119,6 @@ interface BaseContentHit {
* Defined in edx-platform/openedx/core/djangoapps/content/search/documents.py
*/
export interface ContentHit extends BaseContentHit {
usageKey: string;
blockId: string;
/** The block_type part of the usage key. What type of XBlock this is. */
blockType: string;
/**
@@ -144,7 +144,7 @@ export interface CollectionHit extends BaseContentHit {
* Convert search hits to camelCase
* @param hit A search result directly from Meilisearch
*/
function formatSearchHit(hit: Record<string, any>): ContentHit | CollectionHit {
export function formatSearchHit(hit: Record<string, any>): ContentHit | CollectionHit {
// eslint-disable-next-line @typescript-eslint/naming-convention
const { _formatted, ...newHit } = hit;
newHit.formatted = {
@@ -303,6 +303,29 @@ export async function fetchSearchResults({
};
}
/**
* Fetch the block types facet distribution for the search results.
*/
export const fetchBlockTypes = async (
client: MeiliSearch,
indexName: string,
extraFilter?: Filter,
): Promise<Record<string, number>> => {
// Convert 'extraFilter' into an array
const extraFilterFormatted = forceArray(extraFilter);
const { results } = await client.multiSearch({
queries: [{
indexUid: indexName,
facets: ['block_type'],
filter: extraFilterFormatted,
limit: 0, // We don't need any "hits" for this - just the facetDistribution
}],
});
return results[0].facetDistribution?.block_type ?? {};
};
/** Information about a single tag in the tag tree, as returned by fetchAvailableTagOptions() */
export interface TagEntry {
tagName: string;