Skip to content

Commit

Permalink
fix: open in new tab
Browse files Browse the repository at this point in the history
  • Loading branch information
rpenido committed Feb 21, 2025
1 parent f462f23 commit 42a4949
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 15 deletions.
29 changes: 15 additions & 14 deletions src/library-authoring/component-info/ComponentUsage.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { getConfig, getPath } from '@edx/frontend-platform';
import { FormattedMessage } from '@edx/frontend-platform/i18n';
import { Collapsible } from '@openedx/paragon';
import { Link } from 'react-router-dom';
import { Collapsible, Hyperlink } from '@openedx/paragon';

import AlertError from '../../generic/alert-error';
import Loading from '../../generic/Loading';
Expand All @@ -22,6 +22,10 @@ type ComponentUsageTree = Record<string, {
}[]
}>;

const getContainerUrl = (contextKey: string, usageKey: string) => (
`${getPath(getConfig().PUBLIC_PATH)}course/${contextKey}/container/${usageKey}`
);

export const ComponentUsage = ({ usageKey }: ComponentUsageProps) => {
const {
data: dataDownstreamLinks,
Expand Down Expand Up @@ -52,7 +56,7 @@ export const ComponentUsage = ({ usageKey }: ComponentUsageProps) => {
return <Loading />;
}

if (!downstreamKeys.length) {
if (!downstreamKeys.length || !downstreamHits) {
return <FormattedMessage {...messages.detailsTabUsageEmpty} />;
}

Expand All @@ -63,19 +67,18 @@ export const ComponentUsage = ({ usageKey }: ComponentUsageProps) => {
return acc;
}

const linkData = {
...link,
url: getContainerUrl(hit.contextKey, link.usageKey),
};

if (hit.contextKey in acc) {
acc[hit.contextKey].links.push({
...link,
url: `/course/${hit.contextKey}/container/${link.usageKey}`,
});
acc[hit.contextKey].links.push(linkData);
} else {
acc[hit.contextKey] = {
key: hit.contextKey,
contextName: hit.breadcrumbs[0].displayName,
links: [{
...link,
url: `/course/${hit.contextKey}/container/${link.usageKey}`,
}],
links: [linkData],
};
}
return acc;
Expand All @@ -89,9 +92,7 @@ export const ComponentUsage = ({ usageKey }: ComponentUsageProps) => {
componentUsageList.map((context) => (
<Collapsible key={context.key} title={context.contextName} styling="basic">
{context.links.map(({ usageKey: downstreamUsageKey, displayName, url }) => (
<Link key={downstreamUsageKey} to={url}>
{displayName}
</Link>
<Hyperlink key={downstreamUsageKey} destination={url} target="_blank">{displayName}</Hyperlink>
))}
</Collapsible>
))
Expand Down
2 changes: 1 addition & 1 deletion src/search-manager/data/__mocks__/downstream-links.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"display_name": "Sub Section 1"
},
{
"usage_key": "block-v1:org+course1+run+type@vertical+block@verticalId3",
"usage_key": "block-v1:org+course1+run+type@vertical+block@verticalId1",
"display_name": "Unit 1"
}
]
Expand Down

0 comments on commit 42a4949

Please sign in to comment.