diff --git a/trailbase-assets/js/admin/src/components/tables/TablePane.tsx b/trailbase-assets/js/admin/src/components/tables/TablePane.tsx index 84a07b84..36fbbc70 100644 --- a/trailbase-assets/js/admin/src/components/tables/TablePane.tsx +++ b/trailbase-assets/js/admin/src/components/tables/TablePane.tsx @@ -69,6 +69,7 @@ import type { Table } from "@bindings/Table"; import type { TableIndex } from "@bindings/TableIndex"; import type { TableTrigger } from "@bindings/TableTrigger"; import type { View } from "@bindings/View"; +import { QualifiedName } from "@bindings/QualifiedName"; export type SimpleSignal = [get: () => T, set: (state: T) => void]; @@ -91,7 +92,7 @@ function rowDataToRow(columns: Column[], row: RowData): FormRow { function renderCell( context: CellContext, - tableName: string, + tableName: QualifiedName, columns: Column[], pkIndex: number, cell: { @@ -195,13 +196,14 @@ function Image(props: { url: string; mime: string }) { } function imageUrl(opts: { - tableName: string; + tableName: QualifiedName; pkCol: string; pkVal: string; fileColName: string; index?: number; }): string { - const uri = `/table/${opts.tableName}/files?pk_column=${opts.pkCol}&pk_value=${opts.pkVal}&file_column_name=${opts.fileColName}`; + const tableName: string = prettyFormatQualifiedName(opts.tableName); + const uri = `/table/${tableName}/files?pk_column=${opts.pkCol}&pk_value=${opts.pkVal}&file_column_name=${opts.fileColName}`; const index = opts.index; if (index) { return `${uri}&file_index=${index}`; @@ -452,7 +454,7 @@ async function buildTableState( const pkColumnIndex = findPrimaryKeyColumnIndex(response.columns); const columnDefs = buildColumnDefs( - selected.name.name, + selected.name, tableType(selected), pkColumnIndex, response.columns, @@ -467,7 +469,7 @@ async function buildTableState( } function buildColumnDefs( - tableName: string, + tableName: QualifiedName, tableType: TableType, pkColumn: number, columns: Column[], diff --git a/trailbase-assets/js/admin/src/components/tables/TablesPage.tsx b/trailbase-assets/js/admin/src/components/tables/TablesPage.tsx index eb5ed5f9..d0ae39dc 100644 --- a/trailbase-assets/js/admin/src/components/tables/TablesPage.tsx +++ b/trailbase-assets/js/admin/src/components/tables/TablesPage.tsx @@ -36,17 +36,15 @@ import { QualifiedName } from "@bindings/QualifiedName"; function pickInitiallySelectedTable( tables: (Table | View)[], - tableName: string | undefined, + qualifiedTableName: string, ): Table | View | undefined { if (tables.length === 0) { return undefined; } - if (tableName) { - for (const table of tables) { - if (tableName === prettyFormatQualifiedName(table.name)) { - return table; - } + for (const table of tables) { + if (qualifiedTableName === prettyFormatQualifiedName(table.name)) { + return table; } } diff --git a/trailbase-assets/js/admin/src/lib/row.ts b/trailbase-assets/js/admin/src/lib/row.ts index d5b394db..76089545 100644 --- a/trailbase-assets/js/admin/src/lib/row.ts +++ b/trailbase-assets/js/admin/src/lib/row.ts @@ -20,7 +20,8 @@ export async function insertRow(table: Table, row: FormRow) { row: processedRow, }; - const response = await adminFetch(`/table/${table.name}`, { + const tableName: string = prettyFormatQualifiedName(table.name); + const response = await adminFetch(`/table/${tableName}`, { method: "POST", body: JSON.stringify(request), }); @@ -29,7 +30,7 @@ export async function insertRow(table: Table, row: FormRow) { } export async function updateRow(table: Table, row: FormRow) { - const tableName = table.name; + const tableName: string = prettyFormatQualifiedName(table.name); const primaryKeyColumIndex = findPrimaryKeyColumnIndex(table.columns); if (primaryKeyColumIndex < 0) { throw Error("No primary key column found.");