mirror of
https://github.com/fosrl/pangolin.git
synced 2025-07-28 14:44:55 +02:00
show site link in clients table
This commit is contained in:
parent
1a63669805
commit
9f54f4d81a
5 changed files with 48 additions and 7 deletions
|
@ -118,9 +118,11 @@ export const newts = sqliteTable("newt", {
|
||||||
|
|
||||||
export const clients = sqliteTable("clients", {
|
export const clients = sqliteTable("clients", {
|
||||||
clientId: integer("id").primaryKey({ autoIncrement: true }),
|
clientId: integer("id").primaryKey({ autoIncrement: true }),
|
||||||
siteId: integer("siteId").references(() => sites.siteId, {
|
siteId: integer("siteId")
|
||||||
|
.references(() => sites.siteId, {
|
||||||
onDelete: "cascade"
|
onDelete: "cascade"
|
||||||
}),
|
})
|
||||||
|
.notNull(),
|
||||||
orgId: text("orgId")
|
orgId: text("orgId")
|
||||||
.references(() => orgs.orgId, {
|
.references(() => orgs.orgId, {
|
||||||
onDelete: "cascade"
|
onDelete: "cascade"
|
||||||
|
|
|
@ -42,6 +42,7 @@ function queryClients(orgId: string, accessibleClientIds: number[]) {
|
||||||
clientId: clients.clientId,
|
clientId: clients.clientId,
|
||||||
orgId: clients.orgId,
|
orgId: clients.orgId,
|
||||||
siteId: clients.siteId,
|
siteId: clients.siteId,
|
||||||
|
siteNiceId: sites.niceId,
|
||||||
name: clients.name,
|
name: clients.name,
|
||||||
pubKey: clients.pubKey,
|
pubKey: clients.pubKey,
|
||||||
subnet: clients.subnet,
|
subnet: clients.subnet,
|
||||||
|
@ -49,10 +50,12 @@ function queryClients(orgId: string, accessibleClientIds: number[]) {
|
||||||
megabytesOut: clients.megabytesOut,
|
megabytesOut: clients.megabytesOut,
|
||||||
orgName: orgs.name,
|
orgName: orgs.name,
|
||||||
type: clients.type,
|
type: clients.type,
|
||||||
online: clients.online
|
online: clients.online,
|
||||||
|
siteName: sites.name
|
||||||
})
|
})
|
||||||
.from(clients)
|
.from(clients)
|
||||||
.leftJoin(orgs, eq(clients.orgId, orgs.orgId))
|
.leftJoin(orgs, eq(clients.orgId, orgs.orgId))
|
||||||
|
.innerJoin(sites, eq(clients.siteId, sites.siteId))
|
||||||
.where(
|
.where(
|
||||||
and(
|
and(
|
||||||
inArray(clients.clientId, accessibleClientIds),
|
inArray(clients.clientId, accessibleClientIds),
|
||||||
|
|
|
@ -12,6 +12,7 @@ import { Button } from "@app/components/ui/button";
|
||||||
import {
|
import {
|
||||||
ArrowRight,
|
ArrowRight,
|
||||||
ArrowUpDown,
|
ArrowUpDown,
|
||||||
|
ArrowUpRight,
|
||||||
Check,
|
Check,
|
||||||
MoreHorizontal,
|
MoreHorizontal,
|
||||||
X
|
X
|
||||||
|
@ -28,6 +29,8 @@ import CreateClientFormModal from "./CreateClientsModal";
|
||||||
|
|
||||||
export type ClientRow = {
|
export type ClientRow = {
|
||||||
id: number;
|
id: number;
|
||||||
|
siteId: string;
|
||||||
|
siteName: string;
|
||||||
name: string;
|
name: string;
|
||||||
mbIn: string;
|
mbIn: string;
|
||||||
mbOut: string;
|
mbOut: string;
|
||||||
|
@ -125,6 +128,33 @@ export default function ClientsTable({ clients, orgId }: ClientTableProps) {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
accessorKey: "siteName",
|
||||||
|
header: ({ column }) => {
|
||||||
|
return (
|
||||||
|
<Button
|
||||||
|
variant="ghost"
|
||||||
|
onClick={() =>
|
||||||
|
column.toggleSorting(column.getIsSorted() === "asc")
|
||||||
|
}
|
||||||
|
>
|
||||||
|
Site
|
||||||
|
<ArrowUpDown className="ml-2 h-4 w-4" />
|
||||||
|
</Button>
|
||||||
|
);
|
||||||
|
},
|
||||||
|
cell: ({ row }) => {
|
||||||
|
const r = row.original;
|
||||||
|
return (
|
||||||
|
<Link href={`/${r.orgId}/settings/sites/${r.siteId}`}>
|
||||||
|
<Button variant="outline">
|
||||||
|
{r.siteName}
|
||||||
|
<ArrowUpRight className="ml-2 h-4 w-4" />
|
||||||
|
</Button>
|
||||||
|
</Link>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
},
|
||||||
{
|
{
|
||||||
accessorKey: "online",
|
accessorKey: "online",
|
||||||
header: ({ column }) => {
|
header: ({ column }) => {
|
||||||
|
@ -135,7 +165,7 @@ export default function ClientsTable({ clients, orgId }: ClientTableProps) {
|
||||||
column.toggleSorting(column.getIsSorted() === "asc")
|
column.toggleSorting(column.getIsSorted() === "asc")
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
Online
|
Connectivity
|
||||||
<ArrowUpDown className="ml-2 h-4 w-4" />
|
<ArrowUpDown className="ml-2 h-4 w-4" />
|
||||||
</Button>
|
</Button>
|
||||||
);
|
);
|
||||||
|
@ -146,14 +176,14 @@ export default function ClientsTable({ clients, orgId }: ClientTableProps) {
|
||||||
return (
|
return (
|
||||||
<span className="text-green-500 flex items-center space-x-2">
|
<span className="text-green-500 flex items-center space-x-2">
|
||||||
<div className="w-2 h-2 bg-green-500 rounded-full"></div>
|
<div className="w-2 h-2 bg-green-500 rounded-full"></div>
|
||||||
<span>Online</span>
|
<span>Connected</span>
|
||||||
</span>
|
</span>
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
return (
|
return (
|
||||||
<span className="text-neutral-500 flex items-center space-x-2">
|
<span className="text-neutral-500 flex items-center space-x-2">
|
||||||
<div className="w-2 h-2 bg-gray-500 rounded-full"></div>
|
<div className="w-2 h-2 bg-gray-500 rounded-full"></div>
|
||||||
<span>Offline</span>
|
<span>Disconnected</span>
|
||||||
</span>
|
</span>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -189,8 +189,12 @@ export default function CreateClientForm({
|
||||||
if (res && res.status === 201) {
|
if (res && res.status === 201) {
|
||||||
const data = res.data.data;
|
const data = res.data.data;
|
||||||
|
|
||||||
|
const site = sites.find((site) => site.siteId === data.siteId);
|
||||||
|
|
||||||
onCreate?.({
|
onCreate?.({
|
||||||
name: data.name,
|
name: data.name,
|
||||||
|
siteId: site!.niceId,
|
||||||
|
siteName: site!.name,
|
||||||
id: data.clientId,
|
id: data.clientId,
|
||||||
mbIn: "0 MB",
|
mbIn: "0 MB",
|
||||||
mbOut: "0 MB",
|
mbOut: "0 MB",
|
||||||
|
|
|
@ -36,6 +36,8 @@ export default async function ClientsPage(props: ClientsPageProps) {
|
||||||
const clientRows: ClientRow[] = clients.map((client) => {
|
const clientRows: ClientRow[] = clients.map((client) => {
|
||||||
return {
|
return {
|
||||||
name: client.name,
|
name: client.name,
|
||||||
|
siteName: client.siteName,
|
||||||
|
siteId: client.siteNiceId,
|
||||||
id: client.clientId,
|
id: client.clientId,
|
||||||
mbIn: formatSize(client.megabytesIn || 0),
|
mbIn: formatSize(client.megabytesIn || 0),
|
||||||
mbOut: formatSize(client.megabytesOut || 0),
|
mbOut: formatSize(client.megabytesOut || 0),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue