diff --git a/src/routes/(dashboard)/+page.server.ts b/src/routes/(dashboard)/+page.server.ts index ff7dd03..9b11734 100644 --- a/src/routes/(dashboard)/+page.server.ts +++ b/src/routes/(dashboard)/+page.server.ts @@ -6,18 +6,21 @@ import { deleteSessionTokenCookie } from '$lib/server/session'; import { superValidate } from 'sveltekit-superforms'; import { zod } from 'sveltekit-superforms/adapters'; import { formSchema } from './schema'; +import { getDepartments } from '$lib/server/db/department'; export const load: PageServerLoad = async ({ locals }) => { const { database } = locals; try { const persons = await getPersons(database, 1000, 0); + const departments = await getDepartments(database); return { - persons + persons, + departments }; } catch (err: unknown) { - console.debug(`Failed to get persons: ${(err as Error).message}`); + console.debug(`Failed to get persons or departments: ${(err as Error).message}`); return fail(500, { - message: 'Failed to get persons' + message: 'Failed to get persons or departments' }); } }; diff --git a/src/routes/(dashboard)/columns.ts b/src/routes/(dashboard)/columns.ts index 2478596..ab4a5f4 100644 --- a/src/routes/(dashboard)/columns.ts +++ b/src/routes/(dashboard)/columns.ts @@ -31,6 +31,9 @@ export const columns: ColumnDef[] = [ header: 'Department', meta: { editable: true, + editableChoices: (data) => { + return data.departments.map((val) => val.name); + } } }, { diff --git a/src/routes/(dashboard)/data-table-editable.svelte b/src/routes/(dashboard)/data-table-editable.svelte index 4576203..55fc3db 100644 --- a/src/routes/(dashboard)/data-table-editable.svelte +++ b/src/routes/(dashboard)/data-table-editable.svelte @@ -3,16 +3,19 @@ import type { Person } from '$lib/types/person'; import type { Table } from '@tanstack/table-core'; import { fly } from 'svelte/transition'; + import * as Select from '$lib/components/ui/select'; let { id, value, + choices = null, name, enabled = false, table }: { id: number; value: string; + choices?: string[] | null; name: string; enabled?: boolean; table: Table; @@ -35,9 +38,24 @@ {#if enabled && table.options !== null && table.options.meta?.getEditChanges(id)} -
- -
+ {#if choices === null} +
+ +
+ {:else} +
+ + + {getChangesMap()} + + + {#each choices as choice} + {choice} + {/each} + + +
+ {/if} {:else}
{value} diff --git a/src/table.d.ts b/src/table.d.ts index 8096944..8ec1399 100644 --- a/src/table.d.ts +++ b/src/table.d.ts @@ -5,7 +5,8 @@ declare module '@tanstack/table-core' { editables?: SvelteMap; } interface ColumnMeta { - editable?: boolean + editable?: boolean, + editableChoices?: (data: any) => string[] } interface TableMeta { setEditChanges: (id: number, changes?: PersonEditable) => void,