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
31 changes: 4 additions & 27 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 34 additions & 0 deletions src/__tests__/setup.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,39 @@
import "@testing-library/jest-dom/vitest";

// Some runners expose a partial localStorage object when the native backing
// file is unavailable. Tests need the full Storage surface.
if (typeof window.localStorage?.clear !== "function") {
const store = new Map<string, string>();
const storage: Storage = {
get length() {
return store.size;
},
clear() {
store.clear();
},
getItem(key: string) {
return store.has(key) ? store.get(key)! : null;
},
key(index: number) {
return Array.from(store.keys())[index] ?? null;
},
removeItem(key: string) {
store.delete(key);
},
setItem(key: string, value: string) {
store.set(key, String(value));
},
};
Object.defineProperty(window, "localStorage", {
configurable: true,
value: storage,
});
Object.defineProperty(globalThis, "localStorage", {
configurable: true,
value: storage,
});
}

// matchMedia polyfill for jsdom
if (!window.matchMedia) {
window.matchMedia = (query: string) => ({
Expand Down
21 changes: 16 additions & 5 deletions src/components/ConversionDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
} from "./ui/dialog";
import { Checkbox } from "./ui/checkbox";
import { Label } from "./ui/label";
import { Copy, Download } from "lucide-react";
import { Copy, Download, AlertCircle } from "lucide-react";
import { copyToClipboard, downloadFile } from "../utils/clipboard";
import type { ConversionType } from "../hooks/useConversionDialog";

Expand All @@ -17,6 +17,7 @@ export interface ConversionDialogProps {
onOpenChange: (open: boolean) => void;
conversionType: ConversionType | string;
conversionOutput: string;
conversionValid?: boolean;
clearEnvAfterDownload?: boolean;
onClearEnvChange?: (checked: boolean) => void;
onToast?: (message: { title: string; description?: string; variant?: "default" | "success" | "error" }) => void;
Expand Down Expand Up @@ -51,6 +52,7 @@ export function ConversionDialog({
onOpenChange,
conversionType,
conversionOutput,
conversionValid = true,
clearEnvAfterDownload = false,
onClearEnvChange,
onToast,
Expand All @@ -60,14 +62,15 @@ export function ConversionDialog({
const mimeType = CONVERSION_MIME_TYPES[conversionType] || "text/plain";

const handleCopy = async () => {
if (!conversionValid) return;
try {
await copyToClipboard(conversionOutput);
onToast?.({
title: "Copied to clipboard",
description: `${title} has been copied to your clipboard.`,
variant: "success",
});
} catch (error) {
} catch {
onToast?.({
title: "Failed to copy",
description: "Could not copy to clipboard. Please try again.",
Expand All @@ -77,14 +80,15 @@ export function ConversionDialog({
};

const handleDownload = () => {
if (!conversionValid) return;
try {
downloadFile(conversionOutput, filename, mimeType);
onToast?.({
title: "Download started",
description: `Downloading ${filename}`,
variant: "success",
});
} catch (error) {
} catch {
onToast?.({
title: "Download failed",
description: "Could not download file. Please try again.",
Expand All @@ -100,6 +104,13 @@ export function ConversionDialog({
<DialogTitle>{title}</DialogTitle>
</DialogHeader>

{!conversionValid && (
<div className="flex items-center gap-2 rounded-md border border-destructive/50 bg-destructive/10 p-3 text-sm text-destructive">
<AlertCircle className="h-4 w-4" />
Output is blocked until validation errors are fixed.
</div>
)}

<div className="flex-1 overflow-auto">
<pre className="p-4 bg-muted rounded-md text-sm font-mono whitespace-pre-wrap break-all">
{conversionOutput}
Expand All @@ -120,11 +131,11 @@ export function ConversionDialog({
)}

<DialogFooter className="flex-row justify-end gap-2">
<Button variant="outline" onClick={handleCopy}>
<Button variant="outline" onClick={handleCopy} disabled={!conversionValid}>
<Copy className="h-4 w-4 mr-2" />
Copy
</Button>
<Button onClick={handleDownload}>
<Button onClick={handleDownload} disabled={!conversionValid}>
<Download className="h-4 w-4 mr-2" />
Download
</Button>
Expand Down
2 changes: 1 addition & 1 deletion src/components/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export function Header({ onOpenMarket }: HeaderProps) {
</a>
<a
className="icon-btn"
href="https://github.com/hhftechnologies/Dock-Dploy"
href="https://github.com/hhftechnology/Dock-Dploy"
target="_blank"
rel="noreferrer"
aria-label="GitHub"
Expand Down
Loading
Loading