Skip to content

Commit 4e218f3

Browse files
committed
update
1 parent 146dfa8 commit 4e218f3

2 files changed

Lines changed: 8 additions & 77 deletions

File tree

ui/src/components/dialog/dataset/preview.test.tsx

Lines changed: 0 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -139,69 +139,4 @@ describe("DatasetPreviewDialog", () => {
139139

140140
expect(mockOnClose).toHaveBeenCalledTimes(1);
141141
});
142-
143-
describe("Image Dataset Preview", () => {
144-
const imageBase64 =
145-
"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUA AAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO 9TXL0Y4OHwAAAABJRU5ErkJggg==";
146-
const imageUrl = "https://example.com/image1.jpg";
147-
148-
it("renders images correctly from URLs and base64 strings", async () => {
149-
const imageData = {
150-
type: "image" as const,
151-
data: [imageUrl, imageBase64],
152-
};
153-
(mockPreviewDataset as Mock).mockResolvedValue(imageData);
154-
renderDialog();
155-
156-
await waitFor(() => {
157-
expect(screen.getAllByRole("img")).toHaveLength(2);
158-
});
159-
160-
const images = screen.getAllByRole("img");
161-
expect(images[0]).toHaveAttribute("src", imageUrl);
162-
expect(images[0]).toHaveAttribute("alt", "Preview 1");
163-
expect(screen.getByText("image1.jpg")).toBeInTheDocument();
164-
165-
expect(images[1]).toHaveAttribute("src", imageBase64);
166-
expect(images[1]).toHaveAttribute("alt", "Preview 2");
167-
expect(screen.getByText("Image 2")).toBeInTheDocument(); // Generic name for base64
168-
});
169-
170-
it("handles empty image list", async () => {
171-
const emptyImageData = {
172-
type: "image" as const,
173-
data: [],
174-
};
175-
(mockPreviewDataset as Mock).mockResolvedValue(emptyImageData);
176-
renderDialog();
177-
178-
await waitFor(() => {
179-
expect(
180-
screen.getByText(
181-
"Preview for this data type is not yet implemented or the data is empty/invalid.",
182-
),
183-
).toBeInTheDocument();
184-
});
185-
expect(screen.queryAllByRole("img")).toHaveLength(0);
186-
});
187-
188-
it("shows loading state for image preview", async () => {
189-
(mockPreviewDataset as Mock).mockReturnValue(new Promise(() => {})); // Never resolves
190-
renderDialog();
191-
// Check for DialogTitle to ensure dialog is attempting to render
192-
expect(screen.getByText("Dataset Preview")).toBeInTheDocument();
193-
// Check for presence of skeleton loaders (assuming they use 'animate-pulse')
194-
const skeletons = document.querySelectorAll(".animate-pulse");
195-
expect(skeletons.length).toBeGreaterThan(0); // Or a more specific count if known
196-
});
197-
198-
it("shows error state if fetching image data fails", async () => {
199-
const errorMessage = "Failed to fetch image dataset.";
200-
(mockPreviewDataset as Mock).mockRejectedValue(new Error(errorMessage));
201-
renderDialog();
202-
await waitFor(() => {
203-
expect(screen.getByText(`Error: ${errorMessage}`)).toBeInTheDocument();
204-
});
205-
});
206-
});
207142
});

ui/src/components/dialog/dataset/preview.tsx

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { previewDataset } from "@/actions";
22
import { Badge } from "@/components/ui/badge";
33
import { Button } from "@/components/ui/button";
4+
import { Card, CardContent } from "@/components/ui/card";
45
import {
56
Dialog,
67
DialogContent,
@@ -9,12 +10,6 @@ import {
910
DialogHeader,
1011
DialogTitle,
1112
} from "@/components/ui/dialog";
12-
import {
13-
Card,
14-
CardContent,
15-
// CardMedia, // Not available, will use img directly
16-
CardTitle,
17-
} from "@/components/ui/card";
1813
import { Skeleton } from "@/components/ui/skeleton";
1914
import {
2015
Table,
@@ -25,6 +20,7 @@ import {
2520
TableRow,
2621
} from "@/components/ui/table";
2722
import { JSONObject } from "@/json";
23+
import { imageUrl } from "@/urls";
2824
import React, { useEffect, useState } from "react";
2925

3026
interface PreviewData {
@@ -145,19 +141,19 @@ export const DatasetPreviewDialog: React.FC<DatasetPreviewDialogProps> = ({
145141
) : data.type === "image" && Array.isArray(data.data) ? (
146142
<div className="flex flex-wrap justify-center p-4">
147143
{(data.data as string[]).map((item, index) => {
148-
const isBase64 = item.startsWith("data:image");
149-
const filename = isBase64
150-
? `Image ${index + 1}`
151-
: item.substring(item.lastIndexOf("/") + 1);
144+
const filename = item.substring(item.lastIndexOf("/") + 1);
152145
return (
153146
<Card key={`image-${index}`} className="m-2 w-48">
154147
<img
155-
src={item}
148+
src={imageUrl(item)}
156149
alt={`Preview ${index + 1}`}
157150
className="object-contain h-40 w-full rounded-t-lg"
158151
/>
159152
<CardContent className="p-2">
160-
<p className="text-sm text-center mt-1 truncate" title={filename}>
153+
<p
154+
className="text-sm text-center mt-1 truncate"
155+
title={filename}
156+
>
161157
{filename}
162158
</p>
163159
</CardContent>

0 commit comments

Comments
 (0)