opnsense connections page ui improvements

This commit is contained in:
Yuri Tatishchev 2024-11-02 01:53:11 -07:00
parent 922e4c0580
commit d526839bfa
Signed by: CaZzzer
GPG Key ID: E0EBF441EA424369
13 changed files with 244 additions and 34 deletions

BIN
bun.lockb

Binary file not shown.

View File

@ -0,0 +1,35 @@
<script lang="ts">
import { Checkbox as CheckboxPrimitive } from "bits-ui";
import Check from "lucide-svelte/icons/check";
import Minus from "lucide-svelte/icons/minus";
import { cn } from "$lib/utils.js";
type $$Props = CheckboxPrimitive.Props;
type $$Events = CheckboxPrimitive.Events;
let className: $$Props["class"] = undefined;
export let checked: $$Props["checked"] = false;
export { className as class };
</script>
<CheckboxPrimitive.Root
class={cn(
"border-primary ring-offset-background focus-visible:ring-ring data-[state=checked]:bg-primary data-[state=checked]:text-primary-foreground peer box-content h-4 w-4 shrink-0 rounded-sm border focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 data-[disabled=true]:cursor-not-allowed data-[disabled=true]:opacity-50",
className
)}
bind:checked
{...$$restProps}
on:click
>
<CheckboxPrimitive.Indicator
class={cn("flex h-4 w-4 items-center justify-center text-current")}
let:isChecked
let:isIndeterminate
>
{#if isChecked}
<Check class="h-3.5 w-3.5" />
{:else if isIndeterminate}
<Minus class="h-3.5 w-3.5" />
{/if}
</CheckboxPrimitive.Indicator>
</CheckboxPrimitive.Root>

View File

@ -0,0 +1,6 @@
import Root from "./checkbox.svelte";
export {
Root,
//
Root as Checkbox,
};

View File

@ -0,0 +1,28 @@
import Root from "./table.svelte";
import Body from "./table-body.svelte";
import Caption from "./table-caption.svelte";
import Cell from "./table-cell.svelte";
import Footer from "./table-footer.svelte";
import Head from "./table-head.svelte";
import Header from "./table-header.svelte";
import Row from "./table-row.svelte";
export {
Root,
Body,
Caption,
Cell,
Footer,
Head,
Header,
Row,
//
Root as Table,
Body as TableBody,
Caption as TableCaption,
Cell as TableCell,
Footer as TableFooter,
Head as TableHead,
Header as TableHeader,
Row as TableRow,
};

View File

@ -0,0 +1,13 @@
<script lang="ts">
import type { HTMLAttributes } from "svelte/elements";
import { cn } from "$lib/utils.js";
type $$Props = HTMLAttributes<HTMLTableSectionElement>;
let className: $$Props["class"] = undefined;
export { className as class };
</script>
<tbody class={cn("[&_tr:last-child]:border-0", className)} {...$$restProps}>
<slot />
</tbody>

View File

@ -0,0 +1,13 @@
<script lang="ts">
import type { HTMLAttributes } from "svelte/elements";
import { cn } from "$lib/utils.js";
type $$Props = HTMLAttributes<HTMLTableCaptionElement>;
let className: $$Props["class"] = undefined;
export { className as class };
</script>
<caption class={cn("text-muted-foreground mt-4 text-sm", className)} {...$$restProps}>
<slot />
</caption>

View File

@ -0,0 +1,18 @@
<script lang="ts">
import type { HTMLTdAttributes } from "svelte/elements";
import { cn } from "$lib/utils.js";
type $$Props = HTMLTdAttributes;
let className: $$Props["class"] = undefined;
export { className as class };
</script>
<td
class={cn("p-4 align-middle [&:has([role=checkbox])]:pr-0", className)}
{...$$restProps}
on:click
on:keydown
>
<slot />
</td>

View File

@ -0,0 +1,13 @@
<script lang="ts">
import type { HTMLAttributes } from "svelte/elements";
import { cn } from "$lib/utils.js";
type $$Props = HTMLAttributes<HTMLTableSectionElement>;
let className: $$Props["class"] = undefined;
export { className as class };
</script>
<tfoot class={cn("bg-muted/50 text-primary-foreground font-medium", className)} {...$$restProps}>
<slot />
</tfoot>

View File

@ -0,0 +1,19 @@
<script lang="ts">
import type { HTMLThAttributes } from "svelte/elements";
import { cn } from "$lib/utils.js";
type $$Props = HTMLThAttributes;
let className: $$Props["class"] = undefined;
export { className as class };
</script>
<th
class={cn(
"text-muted-foreground h-12 px-4 text-left align-middle font-medium [&:has([role=checkbox])]:pr-0",
className
)}
{...$$restProps}
>
<slot />
</th>

View File

@ -0,0 +1,14 @@
<script lang="ts">
import type { HTMLAttributes } from "svelte/elements";
import { cn } from "$lib/utils.js";
type $$Props = HTMLAttributes<HTMLTableSectionElement>;
let className: $$Props["class"] = undefined;
export { className as class };
</script>
<!-- svelte-ignore a11y-no-noninteractive-element-interactions -->
<thead class={cn("[&_tr]:border-b", className)} {...$$restProps} on:click on:keydown>
<slot />
</thead>

View File

@ -0,0 +1,23 @@
<script lang="ts">
import type { HTMLAttributes } from "svelte/elements";
import { cn } from "$lib/utils.js";
type $$Props = HTMLAttributes<HTMLTableRowElement> & {
"data-state"?: unknown;
};
let className: $$Props["class"] = undefined;
export { className as class };
</script>
<tr
class={cn(
"hover:bg-muted/50 data-[state=selected]:bg-muted border-b transition-colors",
className
)}
{...$$restProps}
on:click
on:keydown
>
<slot />
</tr>

View File

@ -0,0 +1,15 @@
<script lang="ts">
import type { HTMLTableAttributes } from "svelte/elements";
import { cn } from "$lib/utils.js";
type $$Props = HTMLTableAttributes;
let className: $$Props["class"] = undefined;
export { className as class };
</script>
<div class="relative w-full overflow-auto">
<table class={cn("w-full caption-bottom text-sm", className)} {...$$restProps}>
<slot />
</table>
</div>

View File

@ -2,8 +2,13 @@
import type { PageData } from './$types'; import type { PageData } from './$types';
import { invalidate } from '$app/navigation'; import { invalidate } from '$app/navigation';
import { onMount } from 'svelte'; import { onMount } from 'svelte';
import * as Table from '$lib/components/ui/table';
import { Checkbox } from '$lib/components/ui/checkbox';
import { Label } from '$lib/components/ui/label';
const { data }: { data: PageData } = $props(); const { data }: { data: PageData } = $props();
let showOnlyActive = $state(false);
const peerRows = $derived(data.peers.rows.filter((peer) => showOnlyActive ? peer['latest-handshake'] : true));
onMount(() => { onMount(() => {
// refresh every 5 seconds // refresh every 5 seconds
@ -30,37 +35,45 @@
<title>Connections</title> <title>Connections</title>
</svelte:head> </svelte:head>
<table> <Checkbox id="showOnlyActive" bind:checked={showOnlyActive} />
<thead> <Label for="showOnlyActive">Show only active connections</Label>
<tr>
<th>Public Key</th> {#if peerRows.length === 0}
<th>Endpoint</th> <p>No active connections</p>
<th>Allowed IPs</th>
<th>Latest Handshake</th> {:else}
<th>RX</th> <Table.Root class="bg-accent rounded-xl">
<th>TX</th> <Table.Header>
<th>Persistent Keepalive</th> <Table.Head>Name</Table.Head>
<th>Name</th> <Table.Head>Public Key</Table.Head>
<th>Interface Name</th> <Table.Head>Endpoint</Table.Head>
</tr> <Table.Head>Allowed IPs</Table.Head>
</thead> <Table.Head>Latest Handshake</Table.Head>
<tbody> <Table.Head>RX</Table.Head>
{#each data.peers.rows as peer} <Table.Head>TX</Table.Head>
<tr> <Table.Head>Persistent Keepalive</Table.Head>
<td>{peer['public-key'].substring(0, 10)}</td> <Table.Head>Interface Name</Table.Head>
<td>{peer.endpoint}</td> </Table.Header>
<td>{peer['allowed-ips']}</td> <Table.Body>
{#if peer['latest-handshake']} {#each peerRows as peer}
<td>{new Date(peer['latest-handshake'] * 1000)}</td> <Table.Row class="border-y-2 border-background">
{:else} <Table.Cell>{peer.name}</Table.Cell>
<td>Never</td> <Table.Cell>{peer['public-key'].substring(0, 10)}</Table.Cell>
{/if} <Table.Cell>{peer.endpoint}</Table.Cell>
<td>{getSize(peer['transfer-rx'])}</td> <Table.Cell>{peer['allowed-ips']}</Table.Cell>
<td>{getSize(peer['transfer-tx'])}</td> {#if peer['latest-handshake']}
<td>{peer['persistent-keepalive']}</td> <Table.Cell>{new Date(peer['latest-handshake'] * 1000).toLocaleString()}</Table.Cell>
<td>{peer.name}</td> <Table.Cell>{getSize(peer['transfer-rx'])}</Table.Cell>
<td>{peer.ifname}</td> <Table.Cell>{getSize(peer['transfer-tx'])}</Table.Cell>
</tr> {:else}
{/each} <Table.Cell>Never</Table.Cell>
</tbody> <Table.Cell>--</Table.Cell>
</table> <Table.Cell>--</Table.Cell>
{/if}
<Table.Cell>{peer['persistent-keepalive']}</Table.Cell>
<Table.Cell>{peer.ifname}</Table.Cell>
</Table.Row>
{/each}
</Table.Body>
</Table.Root>
{/if}