Skip to content

Commit

Permalink
fix: Search result redirect to unit lib component
Browse files Browse the repository at this point in the history
  • Loading branch information
yusuf-musleh committed May 22, 2024
1 parent 3647bcb commit 66c9505
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions src/search-modal/SearchResult.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ function getItemIcon(blockType) {
*/
function getLibraryHitUrl(hit, libraryAuthoringMfeUrl) {
const { contextKey } = hit;
return `${libraryAuthoringMfeUrl}/library/${contextKey}`;
return `${libraryAuthoringMfeUrl}library/${contextKey}`;
}

/**
Expand All @@ -62,10 +62,20 @@ function getUnitUrlSuffix(hit) {
function getUnitComponentUrlSuffix(hit) {
const { breadcrumbs, contextKey, usageKey } = hit;
if (breadcrumbs.length > 1) {
const parent = breadcrumbs[breadcrumbs.length - 1];
let parent = breadcrumbs[breadcrumbs.length - 1];

if ('usageKey' in parent) {
return `course/${contextKey}/container/${parent.usageKey}?show=${encodeURIComponent(usageKey)}`;
// Handle case for library component in unit
let libComponentUsageKey;
if (parent.usageKey.includes('type@library_content') && breadcrumbs.length > 2) {
libComponentUsageKey = parent.usageKey;
parent = breadcrumbs[breadcrumbs.length - 2];
}

if ('usageKey' in parent) {
const encodedUsageKey = encodeURIComponent(libComponentUsageKey || usageKey);
return `course/${contextKey}/container/${parent.usageKey}?show=${encodedUsageKey}`;
}
}
}

Expand Down Expand Up @@ -96,11 +106,13 @@ function getUrlSuffix(hit) {
return getUnitUrlSuffix(hit);
}

// Check if the parent is a unit
// Check if the parent is a unit or a library component in a unit
if (breadcrumbs.length > 1) {
const parent = breadcrumbs[breadcrumbs.length - 1];

if ('usageKey' in parent && parent.usageKey.includes('type@vertical')) {
if ('usageKey' in parent && (
parent.usageKey.includes('type@vertical') || parent.usageKey.includes('type@library_content'))
) {
return getUnitComponentUrlSuffix(hit);
}
}
Expand Down

0 comments on commit 66c9505

Please sign in to comment.