mirror of
https://github.com/fosrl/pangolin.git
synced 2026-02-16 18:06:39 +00:00
💄 Gave a relooking to the blueprint table
This commit is contained in:
@@ -3,7 +3,15 @@
|
||||
import { ColumnDef } from "@tanstack/react-table";
|
||||
import { DomainsDataTable } from "@app/components/DomainsDataTable";
|
||||
import { Button } from "@app/components/ui/button";
|
||||
import { ArrowRight, ArrowUpDown, MoreHorizontal } from "lucide-react";
|
||||
import {
|
||||
ArrowRight,
|
||||
ArrowUpDown,
|
||||
Globe,
|
||||
LucideIcon,
|
||||
MoreHorizontal,
|
||||
Terminal,
|
||||
Webhook
|
||||
} from "lucide-react";
|
||||
import { useState, useTransition } from "react";
|
||||
import ConfirmDeleteDialog from "@app/components/ConfirmDeleteDialog";
|
||||
import { formatAxiosError } from "@app/lib/api";
|
||||
@@ -16,11 +24,16 @@ import CreateDomainForm from "@app/components/CreateDomainForm";
|
||||
import { useToast } from "@app/hooks/useToast";
|
||||
import { useOrgContext } from "@app/hooks/useOrgContext";
|
||||
import { DataTable } from "./ui/data-table";
|
||||
import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger } from "./ui/dropdown-menu";
|
||||
import {
|
||||
DropdownMenu,
|
||||
DropdownMenuContent,
|
||||
DropdownMenuItem,
|
||||
DropdownMenuTrigger
|
||||
} from "./ui/dropdown-menu";
|
||||
import Link from "next/link";
|
||||
import { ListBlueprintsResponse } from "@server/routers/blueprints";
|
||||
|
||||
export type BlueprintRow = ListBlueprintsResponse['blueprints'][number]
|
||||
export type BlueprintRow = ListBlueprintsResponse["blueprints"][number];
|
||||
|
||||
type Props = {
|
||||
blueprints: BlueprintRow[];
|
||||
@@ -28,14 +41,38 @@ type Props = {
|
||||
};
|
||||
|
||||
export default function BlueprintsTable({ blueprints, orgId }: Props) {
|
||||
|
||||
const t = useTranslations();
|
||||
|
||||
const [isRefreshing, startTransition] = useTransition()
|
||||
const router = useRouter()
|
||||
|
||||
const [isRefreshing, startTransition] = useTransition();
|
||||
const router = useRouter();
|
||||
|
||||
const columns: ColumnDef<BlueprintRow>[] = [
|
||||
{
|
||||
accessorKey: "createdAt",
|
||||
header: ({ column }) => {
|
||||
return (
|
||||
<Button
|
||||
variant="ghost"
|
||||
onClick={() =>
|
||||
column.toggleSorting(column.getIsSorted() === "asc")
|
||||
}
|
||||
>
|
||||
{t("appliedAt")}
|
||||
<ArrowUpDown className="ml-2 size-4" />
|
||||
</Button>
|
||||
);
|
||||
},
|
||||
cell: ({ row }) => {
|
||||
return (
|
||||
<time
|
||||
className="text-muted-foreground"
|
||||
dateTime={row.original.createdAt.toString()}
|
||||
>
|
||||
{new Date(row.original.createdAt).toLocaleString()}
|
||||
</time>
|
||||
);
|
||||
}
|
||||
},
|
||||
{
|
||||
accessorKey: "name",
|
||||
header: ({ column }) => {
|
||||
@@ -47,11 +84,12 @@ export default function BlueprintsTable({ blueprints, orgId }: Props) {
|
||||
}
|
||||
>
|
||||
{t("name")}
|
||||
<ArrowUpDown className="ml-2 h-4 w-4" />
|
||||
<ArrowUpDown className="ml-2 size-4" />
|
||||
</Button>
|
||||
);
|
||||
}
|
||||
},
|
||||
|
||||
{
|
||||
accessorKey: "source",
|
||||
header: ({ column }) => {
|
||||
@@ -63,129 +101,118 @@ export default function BlueprintsTable({ blueprints, orgId }: Props) {
|
||||
}
|
||||
>
|
||||
{t("source")}
|
||||
<ArrowUpDown className="ml-2 size-4" />
|
||||
</Button>
|
||||
);
|
||||
},
|
||||
cell: ({ row }) => {
|
||||
const originalRow = row.original;
|
||||
switch (originalRow.source) {
|
||||
case "API": {
|
||||
return (
|
||||
<Badge variant="secondary">
|
||||
<span className="inline-flex items-center gap-1 ">
|
||||
API
|
||||
<Webhook className="size-4 flex-none" />
|
||||
</span>
|
||||
</Badge>
|
||||
);
|
||||
}
|
||||
case "NEWT": {
|
||||
return (
|
||||
<Badge variant="secondary">
|
||||
<span className="inline-flex items-center gap-1 ">
|
||||
Newt CLI
|
||||
<Terminal className="size-4 flex-none" />
|
||||
</span>
|
||||
</Badge>
|
||||
);
|
||||
}
|
||||
case "UI": {
|
||||
return (
|
||||
<Badge variant="secondary">
|
||||
<span className="inline-flex items-center gap-1 ">
|
||||
Dashboard{" "}
|
||||
<Globe className="size-4 flex-none" />
|
||||
</span>
|
||||
</Badge>
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
accessorKey: "succeeded",
|
||||
header: ({ column }) => {
|
||||
return (
|
||||
<Button
|
||||
variant="ghost"
|
||||
onClick={() =>
|
||||
column.toggleSorting(column.getIsSorted() === "asc")
|
||||
}
|
||||
>
|
||||
{t("status")}
|
||||
<ArrowUpDown className="ml-2 h-4 w-4" />
|
||||
</Button>
|
||||
);
|
||||
},
|
||||
// cell: ({ row }) => {
|
||||
// const originalRow = row.original;
|
||||
// if (
|
||||
// originalRow.type == "newt" ||
|
||||
// originalRow.type == "wireguard"
|
||||
// ) {
|
||||
// if (originalRow.online) {
|
||||
// return (
|
||||
// <span className="text-green-500 flex items-center space-x-2">
|
||||
// <div className="w-2 h-2 bg-green-500 rounded-full"></div>
|
||||
// <span>{t("online")}</span>
|
||||
// </span>
|
||||
// );
|
||||
// } else {
|
||||
// return (
|
||||
// <span className="text-neutral-500 flex items-center space-x-2">
|
||||
// <div className="w-2 h-2 bg-gray-500 rounded-full"></div>
|
||||
// <span>{t("offline")}</span>
|
||||
// </span>
|
||||
// );
|
||||
// }
|
||||
// } else {
|
||||
// return <span>-</span>;
|
||||
// }
|
||||
// }
|
||||
cell: ({ row }) => {
|
||||
const { succeeded } = row.original;
|
||||
if (succeeded) {
|
||||
return <Badge variant="green">{t("success")}</Badge>;
|
||||
} else {
|
||||
return (
|
||||
<Badge variant="red">
|
||||
{t("failed", { fallback: "Failed" })}
|
||||
</Badge>
|
||||
);
|
||||
}
|
||||
}
|
||||
},
|
||||
// {
|
||||
// accessorKey: "nice",
|
||||
// header: ({ column }) => {
|
||||
// return (
|
||||
// <Button
|
||||
// variant="ghost"
|
||||
// onClick={() =>
|
||||
// column.toggleSorting(column.getIsSorted() === "asc")
|
||||
// }
|
||||
// className="hidden md:flex whitespace-nowrap"
|
||||
// >
|
||||
// {t("site")}
|
||||
// <ArrowUpDown className="ml-2 h-4 w-4" />
|
||||
// </Button>
|
||||
// );
|
||||
// },
|
||||
// // cell: ({ row }) => {
|
||||
// // return (
|
||||
// // <div className="hidden md:block whitespace-nowrap">
|
||||
// // {row.original.nice}
|
||||
// // </div>
|
||||
// // );
|
||||
// // }
|
||||
// },
|
||||
// {
|
||||
// id: "actions",
|
||||
// cell: ({ row }) => {
|
||||
// const siteRow = row.original;
|
||||
// return (
|
||||
// <div className="flex items-center justify-end gap-2">
|
||||
// <DropdownMenu>
|
||||
// <DropdownMenuTrigger asChild>
|
||||
// <Button variant="ghost" className="h-8 w-8 p-0">
|
||||
// <span className="sr-only">Open menu</span>
|
||||
// <MoreHorizontal className="h-4 w-4" />
|
||||
// </Button>
|
||||
// </DropdownMenuTrigger>
|
||||
// <DropdownMenuContent align="end">
|
||||
// <Link
|
||||
// className="block w-full"
|
||||
// href="#"
|
||||
// // href={`/${siteRow.orgId}/settings/sites/${siteRow.nice}`}
|
||||
// >
|
||||
// <DropdownMenuItem>
|
||||
// {t("viewSettings")}
|
||||
// </DropdownMenuItem>
|
||||
// </Link>
|
||||
// <DropdownMenuItem
|
||||
// onClick={() => {
|
||||
// // setSelectedSite(siteRow);
|
||||
// // setIsDeleteModalOpen(true);
|
||||
// }}
|
||||
// >
|
||||
// <span className="text-red-500">
|
||||
// {t("delete")}
|
||||
// </span>
|
||||
// </DropdownMenuItem>
|
||||
// </DropdownMenuContent>
|
||||
// </DropdownMenu>
|
||||
{
|
||||
id: "actions",
|
||||
header: ({ column }) => {
|
||||
return (
|
||||
<span className="text-muted-foreground p-3">
|
||||
{t("actions")}
|
||||
</span>
|
||||
);
|
||||
},
|
||||
cell: ({ row }) => {
|
||||
const domain = row.original;
|
||||
|
||||
// <Link
|
||||
// href="#"
|
||||
// // href={`/${siteRow.orgId}/settings/sites/${siteRow.nice}`}
|
||||
// >
|
||||
// <Button variant={"secondary"} size="sm">
|
||||
// {t("edit")}
|
||||
// <ArrowRight className="ml-2 w-4 h-4" />
|
||||
// </Button>
|
||||
// </Link>
|
||||
// </div>
|
||||
// );
|
||||
// }
|
||||
// }
|
||||
return (
|
||||
<Button variant="outline" className="items-center" asChild>
|
||||
<Link href={`#`}>
|
||||
View details{" "}
|
||||
<ArrowRight className="size-4 flex-none" />
|
||||
</Link>
|
||||
</Button>
|
||||
);
|
||||
}
|
||||
}
|
||||
];
|
||||
|
||||
return <DataTable
|
||||
columns={columns}
|
||||
data={blueprints}
|
||||
persistPageSize="blueprint-table"
|
||||
title={t('blueprints')}
|
||||
searchPlaceholder={t('searchBlueprintProgress')}
|
||||
searchColumn="name"
|
||||
onAdd={() => {
|
||||
router.push(`/${orgId}/settings/blueprints/create`);
|
||||
}}
|
||||
addButtonText={t('blueprintAdd')}
|
||||
onRefresh={() => {
|
||||
startTransition(() => router.refresh())
|
||||
}}
|
||||
isRefreshing={isRefreshing}
|
||||
defaultSort={{
|
||||
id: "name",
|
||||
desc: false
|
||||
}}
|
||||
/>
|
||||
}
|
||||
return (
|
||||
<DataTable
|
||||
columns={columns}
|
||||
data={blueprints}
|
||||
persistPageSize="blueprint-table"
|
||||
title={t("blueprints")}
|
||||
searchPlaceholder={t("searchBlueprintProgress")}
|
||||
searchColumn="name"
|
||||
onAdd={() => {
|
||||
router.push(`/${orgId}/settings/blueprints/create`);
|
||||
}}
|
||||
addButtonText={t("blueprintAdd")}
|
||||
onRefresh={() => {
|
||||
startTransition(() => router.refresh());
|
||||
}}
|
||||
isRefreshing={isRefreshing}
|
||||
defaultSort={{
|
||||
id: "name",
|
||||
desc: false
|
||||
}}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user