From d1d654ebac2d51e3841675faeb56480e440f622f Mon Sep 17 00:00:00 2001
From: Wolfgang Müller
Date: Tue, 5 Mar 2024 18:08:09 +0100
Subject: Initial commit

---
 frontend/src/lib/forms/TagForm.svelte | 42 +++++++++++++++++++++++++++++++++++
 1 file changed, 42 insertions(+)
 create mode 100644 frontend/src/lib/forms/TagForm.svelte

(limited to 'frontend/src/lib/forms/TagForm.svelte')

diff --git a/frontend/src/lib/forms/TagForm.svelte b/frontend/src/lib/forms/TagForm.svelte
new file mode 100644
index 0000000..6cc2227
--- /dev/null
+++ b/frontend/src/lib/forms/TagForm.svelte
@@ -0,0 +1,42 @@
+<script lang="ts">
+	import type { TagInput } from '$gql/Mutations';
+	import { namespaceList } from '$gql/Queries';
+	import type { OmitIdentifiers } from '$gql/Utils';
+	import type { FullTag } from '$gql/graphql';
+	import Labelled from '$lib/components/Labelled.svelte';
+	import Select from '$lib/components/Select.svelte';
+	import { getContextClient } from '@urql/svelte';
+	import { createEventDispatcher } from 'svelte';
+
+	const client = getContextClient();
+	const dispatch = createEventDispatcher<{ submit: TagInput }>();
+
+	export let tag: OmitIdentifiers<FullTag>;
+
+	$: namespaceQuery = namespaceList(client);
+	$: namespaces = $namespaceQuery.data?.namespaces.edges;
+
+	function submit() {
+		dispatch('submit', {
+			name: tag.name,
+			description: tag.description,
+			namespaces: { ids: tag.namespaces.map((n) => n.id) }
+		});
+	}
+</script>
+
+<form on:submit|preventDefault={submit}>
+	<div class="grid-labels">
+		<Labelled label="Name" let:id>
+			<!-- svelte-ignore a11y-autofocus -->
+			<input autofocus required {id} bind:value={tag.name} />
+		</Labelled>
+		<Labelled label="Description" let:id>
+			<textarea rows={3} {id} bind:value={tag.description} />
+		</Labelled>
+		<Labelled label="Namespaces" let:id>
+			<Select multi object {id} options={namespaces} bind:value={tag.namespaces} />
+		</Labelled>
+	</div>
+	<slot />
+</form>
-- 
cgit v1.2.3-2-gb3c3

