From 4f2e7cac3aaa687e0f0e5bc1ead18fffc0492f9e Mon Sep 17 00:00:00 2001 From: Dexter Date: Fri, 16 Jun 2023 17:39:11 +0200 Subject: [PATCH] Fixing creating new roles --- src/lib/Form/RoleSelector.svelte | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/src/lib/Form/RoleSelector.svelte b/src/lib/Form/RoleSelector.svelte index 1012e70..55569dd 100644 --- a/src/lib/Form/RoleSelector.svelte +++ b/src/lib/Form/RoleSelector.svelte @@ -9,6 +9,8 @@ export let refetch: () => void; // export let options = []; + let newRole = ''; + $: allRoles = graphql(` query AllRoles { roles: auth_person_role(distinct_on: role) { @@ -66,7 +68,13 @@ ({ role }) => !currentRoles.find((currentRole) => currentRole.role === role) ); - let roleSelect: string; + let filterText = ''; + let value: string = ''; + let items: { value: string; label: string; created: boolean }[] = []; + $: if (possibleRoles) { + items = possibleRoles.map(({ role }) => ({ value: role, label: role })); + } + async function handleSelect(event) { const role = event.detail.value.toLowerCase(); @@ -74,22 +82,29 @@ if (!currentRoles.some((currentRole) => role === currentRole.role)) { await createRole.mutate({ personId: person.id, role }, { metadata: { isBoard: true } }); } - roleSelect = ''; + value = ''; await refetch(); } + + function handleFilter(e) { + if (e.detail.length === 0 && filterText.length > 0) { + const prev = items.filter((i) => !i.created); + items = [...prev, { value: filterText, label: filterText, created: true }]; + } + }
{#if !readonly} - +
+ {item.created ? 'Add new: ' : ''} + {item.label} +
+ {/if} {#if roles}