mirror of
https://github.com/MODSetter/SurfSense.git
synced 2025-09-09 13:54:40 +00:00
Initial formatting using biome
This commit is contained in:
parent
4c8ff48155
commit
758603b275
156 changed files with 23825 additions and 29508 deletions
|
@ -1,55 +1,58 @@
|
|||
import React from "react";
|
||||
import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogTrigger } from "@/components/ui/dialog";
|
||||
import {
|
||||
Dialog,
|
||||
DialogContent,
|
||||
DialogHeader,
|
||||
DialogTitle,
|
||||
DialogTrigger,
|
||||
} from "@/components/ui/dialog";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { FileJson } from "lucide-react";
|
||||
import { JsonView, defaultStyles } from "react-json-view-lite";
|
||||
import "react-json-view-lite/dist/index.css";
|
||||
|
||||
interface JsonMetadataViewerProps {
|
||||
title: string;
|
||||
metadata: any;
|
||||
trigger?: React.ReactNode;
|
||||
title: string;
|
||||
metadata: any;
|
||||
trigger?: React.ReactNode;
|
||||
}
|
||||
|
||||
export function JsonMetadataViewer({ title, metadata, trigger }: JsonMetadataViewerProps) {
|
||||
// Ensure metadata is a valid object
|
||||
const jsonData = React.useMemo(() => {
|
||||
if (!metadata) return {};
|
||||
|
||||
try {
|
||||
// If metadata is a string, try to parse it
|
||||
if (typeof metadata === "string") {
|
||||
return JSON.parse(metadata);
|
||||
}
|
||||
// Otherwise, use it as is
|
||||
return metadata;
|
||||
} catch (error) {
|
||||
console.error("Error parsing JSON metadata:", error);
|
||||
return { error: "Invalid JSON metadata" };
|
||||
}
|
||||
}, [metadata]);
|
||||
// Ensure metadata is a valid object
|
||||
const jsonData = React.useMemo(() => {
|
||||
if (!metadata) return {};
|
||||
|
||||
return (
|
||||
<Dialog>
|
||||
<DialogTrigger asChild>
|
||||
{trigger || (
|
||||
<Button variant="ghost" size="sm" className="flex items-center gap-1">
|
||||
<FileJson size={16} />
|
||||
<span>View Metadata</span>
|
||||
</Button>
|
||||
)}
|
||||
</DialogTrigger>
|
||||
<DialogContent className="max-w-4xl max-h-[80vh] overflow-y-auto">
|
||||
<DialogHeader>
|
||||
<DialogTitle>{title} - Metadata</DialogTitle>
|
||||
</DialogHeader>
|
||||
<div className="mt-4 p-4 bg-muted/30 rounded-md">
|
||||
<JsonView
|
||||
data={jsonData}
|
||||
style={defaultStyles}
|
||||
/>
|
||||
</div>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
);
|
||||
}
|
||||
try {
|
||||
// If metadata is a string, try to parse it
|
||||
if (typeof metadata === "string") {
|
||||
return JSON.parse(metadata);
|
||||
}
|
||||
// Otherwise, use it as is
|
||||
return metadata;
|
||||
} catch (error) {
|
||||
console.error("Error parsing JSON metadata:", error);
|
||||
return { error: "Invalid JSON metadata" };
|
||||
}
|
||||
}, [metadata]);
|
||||
|
||||
return (
|
||||
<Dialog>
|
||||
<DialogTrigger asChild>
|
||||
{trigger || (
|
||||
<Button variant="ghost" size="sm" className="flex items-center gap-1">
|
||||
<FileJson size={16} />
|
||||
<span>View Metadata</span>
|
||||
</Button>
|
||||
)}
|
||||
</DialogTrigger>
|
||||
<DialogContent className="max-w-4xl max-h-[80vh] overflow-y-auto">
|
||||
<DialogHeader>
|
||||
<DialogTitle>{title} - Metadata</DialogTitle>
|
||||
</DialogHeader>
|
||||
<div className="mt-4 p-4 bg-muted/30 rounded-md">
|
||||
<JsonView data={jsonData} style={defaultStyles} />
|
||||
</div>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue