From 13f08b3f91da4d9e6adca338b28d5a321cfccaae Mon Sep 17 00:00:00 2001 From: Sebastian Jeltsch Date: Sat, 5 Jul 2025 10:15:44 +0200 Subject: [PATCH] Minor brush-up of "add index form" in admin UI. --- .../components/tables/CreateAlterIndex.tsx | 51 ++++++++++--------- 1 file changed, 28 insertions(+), 23 deletions(-) diff --git a/trailbase-assets/js/admin/src/components/tables/CreateAlterIndex.tsx b/trailbase-assets/js/admin/src/components/tables/CreateAlterIndex.tsx index 9ed0e8df..5950fda0 100644 --- a/trailbase-assets/js/admin/src/components/tables/CreateAlterIndex.tsx +++ b/trailbase-assets/js/admin/src/components/tables/CreateAlterIndex.tsx @@ -3,7 +3,7 @@ import type { Accessor } from "solid-js"; import { createForm } from "@tanstack/solid-form"; import { Button } from "@/components/ui/button"; -import { Card, CardContent, CardHeader } from "@/components/ui/card"; +import { Card, CardContent } from "@/components/ui/card"; import { Dialog, DialogContent, @@ -22,7 +22,6 @@ import { buildSelectField, } from "@/components/FormFields"; import { SheetContainer } from "@/components/SafeSheet"; -import { randomName } from "@/lib/name"; import { prettyFormatQualifiedName } from "@/lib/schema"; import type { ColumnOrder } from "@bindings/ColumnOrder"; @@ -84,21 +83,25 @@ export function CreateAlterIndexForm(props: { } }; - const form = createForm(() => ({ - defaultValues: - props.schema ?? - ({ - name: { - name: `_${props.table.name.name}__${randomName()}_index`, - database_schema: props.table.name.database_schema, - }, - table_name: props.table.name.name, - columns: [newDefaultColumn(0)] as ColumnOrder[], - unique: false, - predicate: null, - } as TableIndex), - onSubmit: async ({ value }) => await onSubmit(value, false), - })); + const form = createForm(() => { + const columns: ColumnOrder[] = [newDefaultColumn(0)]; + + return { + defaultValues: + props.schema ?? + ({ + name: { + name: `_${props.table.name.name}__${columns[0].column_name}_index`, + database_schema: props.table.name.database_schema, + }, + table_name: props.table.name.name, + columns, + unique: false, + predicate: null, + } as TableIndex), + onSubmit: async ({ value }) => await onSubmit(value, false), + }; + }); form.useStore((state) => { if (state.isDirty && !state.isSubmitted) { @@ -110,8 +113,10 @@ export function CreateAlterIndexForm(props: { - {original() ? "Alter Index" : "Add New Index"} for " - {prettyFormatQualifiedName(props.table.name)}" Table + {original() ? "Alter Index" : "Add Index"} for{" "} + + {prettyFormatQualifiedName(props.table.name)} + @@ -131,7 +136,7 @@ export function CreateAlterIndexForm(props: { }, }} > - {buildTextFormField({ label: () => "Index name" })} + {buildTextFormField({ label: () => "Index Name" })} {/* columns */} @@ -142,10 +147,10 @@ export function CreateAlterIndexForm(props: { {(_c: Accessor, i) => ( - Index Column {i} + {/* Index Column {i} */} -
+
{buildSelectField( [...props.table.columns.map((c) => c.name)], @@ -165,7 +170,7 @@ export function CreateAlterIndexForm(props: { {buildBoolFormField({ - label: () =>
Nulls first
, + label: () =>
Nulls First
, })}