From fdc3cdde39badd675673710bc3eb97988692ae06 Mon Sep 17 00:00:00 2001 From: Aarnav Tale Date: Sun, 17 Mar 2024 23:24:40 -0400 Subject: [PATCH] feat: add basic machine page --- src/lib/components/Attribute.svelte | 32 +++++++++++ src/lib/components/Link.svelte | 2 +- src/lib/types/Machine.ts | 6 +-- src/routes/machines/+page.svelte | 10 ++-- src/routes/machines/[id]/+page.svelte | 78 +++++++++++++++++++++++++++ src/routes/machines/[id]/+page.ts | 17 ++++++ 6 files changed, 137 insertions(+), 8 deletions(-) create mode 100644 src/lib/components/Attribute.svelte create mode 100644 src/routes/machines/[id]/+page.svelte create mode 100644 src/routes/machines/[id]/+page.ts diff --git a/src/lib/components/Attribute.svelte b/src/lib/components/Attribute.svelte new file mode 100644 index 0000000..73f248b --- /dev/null +++ b/src/lib/components/Attribute.svelte @@ -0,0 +1,32 @@ + + +
+
+ {key} +
+ {#if copyable} + + {:else} +
+ {value} +
+ {/if} +
diff --git a/src/lib/components/Link.svelte b/src/lib/components/Link.svelte index 5cfc580..43934fb 100644 --- a/src/lib/components/Link.svelte +++ b/src/lib/components/Link.svelte @@ -12,7 +12,7 @@ href={`${base}${to}`} class={clsx( "flex items-center gap-x-2 p-2 border-b-2 text-sm", - $page.url.pathname === `${base}${to}` + $page.url.pathname.startsWith(`${base}${to}`) ? "border-white" : "border-transparent", )} diff --git a/src/lib/types/Machine.ts b/src/lib/types/Machine.ts index 4eb273a..b1241b3 100644 --- a/src/lib/types/Machine.ts +++ b/src/lib/types/Machine.ts @@ -17,9 +17,9 @@ export type Machine = { createdAt: Date; registerMethod: 'REGISTER_METHOD_UNSPECIFIED' - | 'REGISTER_METHOD_AUTH_KEY' - | 'REGISTER_METHOD_CLI' - | 'REGISTER_METHOD_OIDC' + | 'REGISTER_METHOD_AUTH_KEY' + | 'REGISTER_METHOD_CLI' + | 'REGISTER_METHOD_OIDC' forcedTags: string[]; invalidTags: string[]; diff --git a/src/routes/machines/+page.svelte b/src/routes/machines/+page.svelte index 0022180..3e73dcb 100644 --- a/src/routes/machines/+page.svelte +++ b/src/routes/machines/+page.svelte @@ -36,10 +36,12 @@ {#each $query.data as machine} -

{machine.givenName}

- {machine.name} + +

{machine.givenName}

+ {machine.name} +
{#each machine.ipAddresses as ip, i} diff --git a/src/routes/machines/[id]/+page.svelte b/src/routes/machines/[id]/+page.svelte new file mode 100644 index 0000000..2cb32e8 --- /dev/null +++ b/src/routes/machines/[id]/+page.svelte @@ -0,0 +1,78 @@ + + + + + {$query.isSuccess ? `${$query.data.givenName} - Machines` : "Machines"} + + + +{#if $query.isLoading} +

Loading...

+{:else if $query.isError} +

Error: {$query.error.message}

+{:else if $query.isSuccess} +
+ +

+ {$query.data.givenName} +

+ +
+
+ + + + + + + + + +
+
+{/if} diff --git a/src/routes/machines/[id]/+page.ts b/src/routes/machines/[id]/+page.ts new file mode 100644 index 0000000..7d5eba5 --- /dev/null +++ b/src/routes/machines/[id]/+page.ts @@ -0,0 +1,17 @@ +import { pull } from "$lib/api"; +import type { Machine } from "$lib/types"; +import type { PageLoad } from './$types'; + +export async function load({ parent, params }: Parameters[0]) { + const { queryClient } = await parent(); + + await queryClient.prefetchQuery({ + queryKey: [`machines/${params.id}`], + queryFn: async () => { + const data = await pull<{ node: Machine }>(`v1/node/${params.id}`); + return data.node; + }, + }); + + return { id: params.id } +}