Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import PropTypes from "prop-types";
import { useMemo } from "react";
import { Link as RouterLink } from "react-router-dom";

import { useSessionStore } from "../../../store/session-store";

const { Text, Link, Paragraph } = Typography;

const CustomMarkdown = ({
Expand All @@ -11,6 +13,8 @@ const CustomMarkdown = ({
isSecondary = false,
styleClassName,
}) => {
const { sessionDetails } = useSessionStore();
const orgName = sessionDetails?.orgName;
const textType = isSecondary ? "secondary" : undefined;

/*
Expand Down Expand Up @@ -52,7 +56,8 @@ const CustomMarkdown = ({
case "link": {
const isInternal = url?.startsWith("/");
if (isInternal) {
return <RouterLink to={url}>{content}</RouterLink>;
const resolvedUrl = orgName ? `/${orgName}${url}` : url;
return <RouterLink to={resolvedUrl}>{content}</RouterLink>;
}
return (
<Link href={url} target="_blank" rel="noopener noreferrer">
Expand Down Expand Up @@ -99,7 +104,7 @@ const CustomMarkdown = ({
});

return elements;
}, [text, renderNewLines, textType]);
}, [text, renderNewLines, textType, orgName]);

return (
<Text type={textType} className={styleClassName}>
Expand Down
20 changes: 1 addition & 19 deletions frontend/src/hooks/useExceptionHandler.jsx
Original file line number Diff line number Diff line change
@@ -1,30 +1,12 @@
import PropTypes from "prop-types";
import { useNavigate } from "react-router-dom";

import { useSessionStore } from "../store/session-store.js";

const useExceptionHandler = () => {
const navigate = useNavigate();
const { sessionDetails } = useSessionStore();

// Resolves relative markdown links [text](/path) to [text](/{orgName}/path)
const enrichMarkdownLinks = (message) => {
if (typeof message !== "string") {
return message;
}
const orgName = sessionDetails?.orgName;
if (!orgName) {
return message;
}
return message.replace(
/\[([^\]]+)\]\(\/((?!\/)[^)]+)\)/g,
(_, text, path) => `[${text}](/${orgName}/${path})`,
);
};

const buildAlert = (content, title, duration) => ({
type: "error",
content: enrichMarkdownLinks(content),
content,
title,
duration,
});
Expand Down