mirror of
https://github.com/khairul169/garage-webui.git
synced 2025-04-28 06:49:32 +07:00
feat: update layout, add copy key
This commit is contained in:
parent
f503b261f5
commit
fb02d273c2
@ -20,6 +20,10 @@
|
|||||||
@apply bg-base-100;
|
@apply bg-base-100;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.card-body {
|
||||||
|
@apply p-4 md:p-8;
|
||||||
|
}
|
||||||
|
|
||||||
.dropdown-content {
|
.dropdown-content {
|
||||||
@apply z-10;
|
@apply z-10;
|
||||||
}
|
}
|
||||||
|
@ -45,7 +45,7 @@ const Sidebar = () => {
|
|||||||
className={cn(
|
className={cn(
|
||||||
"h-12 flex items-center px-6",
|
"h-12 flex items-center px-6",
|
||||||
isActive &&
|
isActive &&
|
||||||
"bg-primary text-primary-content hover:bg-primary/60 focus:bg-primary"
|
"bg-primary text-primary-content hover:bg-primary/60 focus:bg-primary focus:text-primary-content"
|
||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
<page.icon size={18} />
|
<page.icon size={18} />
|
||||||
|
@ -45,7 +45,8 @@ const Header = ({ onSidebarOpen }: HeaderProps) => {
|
|||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<header className="bg-base-100 px-4 h-16 md:px-8 md:h-20 flex flex-row items-center gap-4">
|
<header className="bg-base-100 px-4 md:px-8">
|
||||||
|
<div className="container h-16 md:h-20 flex flex-row items-center gap-4">
|
||||||
{page?.prev ? (
|
{page?.prev ? (
|
||||||
<Button
|
<Button
|
||||||
href={page.prev}
|
href={page.prev}
|
||||||
@ -65,9 +66,12 @@ const Header = ({ onSidebarOpen }: HeaderProps) => {
|
|||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
<h1 className="text-xl flex-1 truncate">{page?.title || "Dashboard"}</h1>
|
<h1 className="text-xl flex-1 truncate">
|
||||||
|
{page?.title || "Dashboard"}
|
||||||
|
</h1>
|
||||||
|
|
||||||
{page?.actions}
|
{page?.actions}
|
||||||
|
</div>
|
||||||
</header>
|
</header>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
@ -42,7 +42,13 @@ export const ToggleField = <T extends FieldValues>({
|
|||||||
title={title}
|
title={title}
|
||||||
className={className}
|
className={className}
|
||||||
render={(field) => (
|
render={(field) => (
|
||||||
<Toggle {...props} {...field} className={inputClassName} />
|
<Toggle
|
||||||
|
{...props}
|
||||||
|
{...field}
|
||||||
|
className={inputClassName}
|
||||||
|
checked={field.value || false}
|
||||||
|
onChange={(e) => field.onChange(e.target.checked)}
|
||||||
|
/>
|
||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
|
@ -22,3 +22,12 @@ export const readableBytes = (bytes?: number | null, divider = 1024) => {
|
|||||||
export const handleError = (err: unknown) => {
|
export const handleError = (err: unknown) => {
|
||||||
toast.error((err as Error)?.message || "Unknown error");
|
toast.error((err as Error)?.message || "Unknown error");
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const copyToClipboard = async (text: string) => {
|
||||||
|
try {
|
||||||
|
await navigator.clipboard.writeText(text);
|
||||||
|
toast.success("Copied to clipboard");
|
||||||
|
} catch (err) {
|
||||||
|
handleError(err);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
@ -10,8 +10,8 @@ type Props = {
|
|||||||
const BucketCard = ({ data }: Props) => {
|
const BucketCard = ({ data }: Props) => {
|
||||||
return (
|
return (
|
||||||
<div className="card card-body p-6">
|
<div className="card card-body p-6">
|
||||||
<div className="grid grid-cols-2 md:grid-cols-3 items-start gap-4 p-2 pb-0">
|
<div className="grid grid-cols-2 items-start gap-4 p-2 pb-0">
|
||||||
<div className="flex flex-row items-start gap-x-3 col-span-2 md:col-span-1">
|
<div className="flex flex-row items-start gap-x-3 col-span-2">
|
||||||
<ArchiveIcon size={28} className="shrink-0" />
|
<ArchiveIcon size={28} className="shrink-0" />
|
||||||
|
|
||||||
<p className="text-xl font-medium truncate">
|
<p className="text-xl font-medium truncate">
|
||||||
@ -38,7 +38,7 @@ const BucketCard = ({ data }: Props) => {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="mt-1 flex flex-row justify-end gap-4">
|
<div className="flex flex-row justify-end gap-4">
|
||||||
<Button href={`/buckets/${data.id}`}>Manage</Button>
|
<Button href={`/buckets/${data.id}`}>Manage</Button>
|
||||||
{/* <Button color="primary">Browse</Button> */}
|
{/* <Button color="primary">Browse</Button> */}
|
||||||
</div>
|
</div>
|
||||||
|
@ -3,9 +3,24 @@ import { useBuckets } from "./hooks";
|
|||||||
import { Input } from "react-daisyui";
|
import { Input } from "react-daisyui";
|
||||||
import BucketCard from "./components/bucket-card";
|
import BucketCard from "./components/bucket-card";
|
||||||
import CreateBucketDialog from "./components/create-bucket-dialog";
|
import CreateBucketDialog from "./components/create-bucket-dialog";
|
||||||
|
import { useMemo, useState } from "react";
|
||||||
|
|
||||||
const BucketsPage = () => {
|
const BucketsPage = () => {
|
||||||
const { data } = useBuckets();
|
const { data } = useBuckets();
|
||||||
|
const [search, setSearch] = useState("");
|
||||||
|
|
||||||
|
const items = useMemo(() => {
|
||||||
|
if (!search?.length) {
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
const q = search.toLowerCase();
|
||||||
|
return data?.filter(
|
||||||
|
(bucket) =>
|
||||||
|
bucket.id.includes(q) ||
|
||||||
|
bucket.globalAliases.find((alias) => alias.includes(q))
|
||||||
|
);
|
||||||
|
}, [data, search]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="container">
|
<div className="container">
|
||||||
@ -13,13 +28,17 @@ const BucketsPage = () => {
|
|||||||
|
|
||||||
<div>
|
<div>
|
||||||
<div className="flex flex-col sm:flex-row items-stretch sm:items-center gap-2">
|
<div className="flex flex-col sm:flex-row items-stretch sm:items-center gap-2">
|
||||||
<Input placeholder="Search..." />
|
<Input
|
||||||
|
placeholder="Search..."
|
||||||
|
value={search}
|
||||||
|
onChange={(e) => setSearch(e.target.value)}
|
||||||
|
/>
|
||||||
<div className="flex-1" />
|
<div className="flex-1" />
|
||||||
<CreateBucketDialog />
|
<CreateBucketDialog />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="grid grid-cols-1 lg:grid-cols-2 gap-4 md:gap-8 items-stretch mt-4 md:mt-8">
|
<div className="grid grid-cols-1 lg:grid-cols-2 gap-4 md:gap-8 items-stretch mt-4 md:mt-8">
|
||||||
{data?.map((bucket) => (
|
{items?.map((bucket) => (
|
||||||
<BucketCard key={bucket.id} data={bucket} />
|
<BucketCard key={bucket.id} data={bucket} />
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
|
@ -1,14 +1,18 @@
|
|||||||
import Button from "@/components/ui/button";
|
import Button from "@/components/ui/button";
|
||||||
import Page from "@/context/page-context";
|
import Page from "@/context/page-context";
|
||||||
import { Trash } from "lucide-react";
|
import { Copy, Eye, Trash } from "lucide-react";
|
||||||
import { Card, Input, Table } from "react-daisyui";
|
import { Card, Input, Table } from "react-daisyui";
|
||||||
import { useKeys, useRemoveKey } from "./hooks";
|
import { useKeys, useRemoveKey } from "./hooks";
|
||||||
import CreateKeyDialog from "./components/create-key-dialog";
|
import CreateKeyDialog from "./components/create-key-dialog";
|
||||||
import { toast } from "sonner";
|
import { toast } from "sonner";
|
||||||
import { handleError } from "@/lib/utils";
|
import { copyToClipboard, handleError } from "@/lib/utils";
|
||||||
|
import { useCallback, useMemo, useState } from "react";
|
||||||
|
import api from "@/lib/api";
|
||||||
|
|
||||||
const KeysPage = () => {
|
const KeysPage = () => {
|
||||||
const { data, refetch } = useKeys();
|
const { data, refetch } = useKeys();
|
||||||
|
const [search, setSearch] = useState("");
|
||||||
|
const [secretKeys, setSecretKeys] = useState<Record<string, string>>({});
|
||||||
|
|
||||||
const removeKey = useRemoveKey({
|
const removeKey = useRemoveKey({
|
||||||
onSuccess: () => {
|
onSuccess: () => {
|
||||||
@ -18,18 +22,45 @@ const KeysPage = () => {
|
|||||||
onError: handleError,
|
onError: handleError,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const fetchSecretKey = useCallback(async (id: string) => {
|
||||||
|
try {
|
||||||
|
const result = await api.get("/v1/key", {
|
||||||
|
params: { id, showSecretKey: "true" },
|
||||||
|
});
|
||||||
|
if (!result?.secretAccessKey) {
|
||||||
|
throw new Error("Failed to fetch secret key");
|
||||||
|
}
|
||||||
|
setSecretKeys((prev) => ({ ...prev, [id]: result.secretAccessKey }));
|
||||||
|
} catch (err) {
|
||||||
|
handleError(err);
|
||||||
|
}
|
||||||
|
}, []);
|
||||||
|
|
||||||
const onRemove = (id: string) => {
|
const onRemove = (id: string) => {
|
||||||
if (window.confirm("Are you sure you want to remove this key?")) {
|
if (window.confirm("Are you sure you want to remove this key?")) {
|
||||||
removeKey.mutate(id);
|
removeKey.mutate(id);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const items = useMemo(() => {
|
||||||
|
if (!search?.length) {
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
const q = search.toLowerCase();
|
||||||
|
return data?.filter((item) => item.id.includes(q) || item.name.includes(q));
|
||||||
|
}, [data, search]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="container">
|
<div className="container">
|
||||||
<Page title="Keys" />
|
<Page title="Keys" />
|
||||||
|
|
||||||
<div className="flex flex-col sm:flex-row items-stretch sm:items-center gap-2">
|
<div className="flex flex-col sm:flex-row items-stretch sm:items-center gap-2">
|
||||||
<Input placeholder="Search..." />
|
<Input
|
||||||
|
placeholder="Search..."
|
||||||
|
value={search}
|
||||||
|
onChange={(e) => setSearch(e.target.value)}
|
||||||
|
/>
|
||||||
<div className="flex-1" />
|
<div className="flex-1" />
|
||||||
<CreateKeyDialog />
|
<CreateKeyDialog />
|
||||||
</div>
|
</div>
|
||||||
@ -39,17 +70,51 @@ const KeysPage = () => {
|
|||||||
<Table zebra>
|
<Table zebra>
|
||||||
<Table.Head>
|
<Table.Head>
|
||||||
<span>#</span>
|
<span>#</span>
|
||||||
<span>Key ID</span>
|
|
||||||
<span>Name</span>
|
<span>Name</span>
|
||||||
|
<span>Key ID</span>
|
||||||
|
<span>Secret Key</span>
|
||||||
<span />
|
<span />
|
||||||
</Table.Head>
|
</Table.Head>
|
||||||
|
|
||||||
<Table.Body>
|
<Table.Body>
|
||||||
{data?.map((key, idx) => (
|
{items?.map((key, idx) => (
|
||||||
<Table.Row key={key.id}>
|
<Table.Row key={key.id}>
|
||||||
<span>{idx + 1}</span>
|
<span>{idx + 1}</span>
|
||||||
<span className="truncate">{key.id}</span>
|
|
||||||
<span>{key.name}</span>
|
<span>{key.name}</span>
|
||||||
|
<div className="flex flex-row items-center">
|
||||||
|
<p className="truncate max-w-20" title={key.id}>
|
||||||
|
{key.id}
|
||||||
|
</p>
|
||||||
|
<Button
|
||||||
|
size="sm"
|
||||||
|
icon={Copy}
|
||||||
|
onClick={() => copyToClipboard(key.id)}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
{!secretKeys[key.id] ? (
|
||||||
|
<Button
|
||||||
|
icon={Eye}
|
||||||
|
size="sm"
|
||||||
|
onClick={() => fetchSecretKey(key.id)}
|
||||||
|
>
|
||||||
|
View
|
||||||
|
</Button>
|
||||||
|
) : (
|
||||||
|
<div className="flex flex-row items-center">
|
||||||
|
<p
|
||||||
|
className="font-mono max-w-20 truncate"
|
||||||
|
title={secretKeys[key.id]}
|
||||||
|
>
|
||||||
|
{secretKeys[key.id]}
|
||||||
|
</p>
|
||||||
|
<Button
|
||||||
|
size="sm"
|
||||||
|
icon={Copy}
|
||||||
|
onClick={() => copyToClipboard(secretKeys[key.id])}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
<span>
|
<span>
|
||||||
<Button
|
<Button
|
||||||
color="ghost"
|
color="ghost"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user