= ({ components, baseDir }) => {
const { id: boxId } = useParams();
// Boxes edit: the browser keeps an image of the page in memory, whatever
// the cache headers say. So each view of the message gets file URLs of its
// own, and the browser loads the files again.
const [view] = useState(() => ++views);
const urlTransform = useMemo(
- () => urlTransformFor(boxId, view),
- [boxId, view],
+ () => urlTransformFor(boxId, view, baseDir),
+ [boxId, view, baseDir],
);
const stableComponents = useShallowStable(components);
const markdownComponents = useMemo(() => {
@@ -104,13 +107,14 @@ let views = 0;
*
* @param boxId The id of the box, or undefined outside the view of a box.
* @param view The number of the view of the message, for the file URLs.
+ * @param baseDir The absolute directory in the box where a relative path starts, or undefined for the workspace.
* @returns The filter.
*/
const urlTransformFor =
- (boxId: string | undefined, view: number): UrlTransform =>
+ (boxId: string | undefined, view: number, baseDir?: string): UrlTransform =>
(url, key) => {
if (key === "src" && /^data:image\//i.test(url)) return url;
- const path = boxId && filePath(url);
+ const path = boxId && filePath(url, baseDir);
return path ? fileUrl(boxId, path, view) : defaultUrlTransform(url);
};
diff --git a/dashboard/src/components/review/MarkdownPreview.tsx b/dashboard/src/components/review/MarkdownPreview.tsx
new file mode 100644
index 00000000..f11bee53
--- /dev/null
+++ b/dashboard/src/components/review/MarkdownPreview.tsx
@@ -0,0 +1,32 @@
+import { TextMessagePartProvider } from '@assistant-ui/react';
+import { MarkdownText } from '@/components/assistant-ui/elements/markdown-text';
+import { WORKSPACE_DIR } from '@/lib/files';
+
+/**
+ * The pane that shows a markdown file of the review rendered, as the thread shows a message.
+ *
+ * @param path The workspace-relative path of the file.
+ * @param content The markdown text.
+ */
+export function MarkdownPreview({
+ path,
+ content,
+}: {
+ /** The workspace-relative path of the file. */
+ path: string;
+ /** The markdown text. */
+ content: string;
+}) {
+ // A relative path in the file starts from the directory of the file.
+ const baseDir = `${WORKSPACE_DIR}/${path}`.replace(/\/[^/]*$/, '');
+ return (
+ // The container lets a wide table or code block grow to the width of the pane.
+
+ );
+}
diff --git a/dashboard/src/components/review/ReviewToolbar.tsx b/dashboard/src/components/review/ReviewToolbar.tsx
index 392dea3a..21890346 100644
--- a/dashboard/src/components/review/ReviewToolbar.tsx
+++ b/dashboard/src/components/review/ReviewToolbar.tsx
@@ -2,13 +2,15 @@ import {
ChevronDown,
ChevronUp,
ExternalLink,
+ Eye,
GitCompare,
MessageSquare,
Pencil,
Undo2,
WrapText,
} from 'lucide-react';
-import { Button } from '@/components/ui/button';
+import { ImageZoom } from '@/components/assistant-ui/elements/image';
+import { Button, buttonVariants } from '@/components/ui/button';
import { cn } from '@/lib/utils';
/**
@@ -26,12 +28,16 @@ import { cn } from '@/lib/utils';
* @param dirty True when there are unsaved changes.
* @param busy True while a write is in flight.
* @param openHref The URL that serves the bytes of the file, or null for a file with none.
+ * @param preview The kind of preview of the file, or null when the file has none or the pane is in edit mode.
+ * @param previewing True while the pane shows the rendered markdown.
+ * @param imageSrc The URL of the image for the lightbox.
* @param onWrap Called when the user toggles wrapping.
* @param onStepChange Called with -1 for the previous change or 1 for the next.
* @param onStepComment Called with -1 for the previous comment or 1 for the next.
* @param onEdit Called when the user switches edit mode on or off.
* @param onSave Called when the user saves the file.
* @param onRevert Called when the user discards the unsaved changes.
+ * @param onPreview Called when the user switches the markdown preview on or off.
*/
export function ReviewToolbar({
changeCount,
@@ -43,12 +49,16 @@ export function ReviewToolbar({
dirty,
busy,
openHref,
+ preview,
+ previewing,
+ imageSrc,
onWrap,
onStepChange,
onStepComment,
onEdit,
onSave,
onRevert,
+ onPreview,
}: {
/** The number of changes in the file. */
changeCount: number;
@@ -68,6 +78,12 @@ export function ReviewToolbar({
busy: boolean;
/** The URL that serves the bytes of the file, or null for a file with none. */
openHref: string | null;
+ /** The kind of preview of the file, or null when the file has none or the pane is in edit mode. */
+ preview: 'image' | 'markdown' | null;
+ /** True while the pane shows the rendered markdown. */
+ previewing: boolean;
+ /** The URL of the image for the lightbox. */
+ imageSrc: string;
/** Called when the user toggles wrapping. */
onWrap: () => void;
/** Called with -1 for the previous change or 1 for the next. */
@@ -80,6 +96,8 @@ export function ReviewToolbar({
onSave: () => void;
/** Called when the user discards the unsaved changes. */
onRevert: () => void;
+ /** Called when the user switches the markdown preview on or off. */
+ onPreview: () => void;
}) {
return (
@@ -100,6 +118,30 @@ export function ReviewToolbar({
/>
+ {preview === 'image' ? (
+
+
+
+
+
+ ) : preview === 'markdown' ? (
+
+ ) : null}
+
{/* A plain link, so the browser handles the file by its type. */}
{openHref ? (