Fix issue with qualified table names breaking admin dash row insertions/updates.

This commit is contained in:
Sebastian Jeltsch
2025-06-05 08:54:44 +02:00
parent 385a9ecceb
commit b9756c377a
3 changed files with 14 additions and 13 deletions

View File

@@ -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<T> = [get: () => T, set: (state: T) => void];
@@ -91,7 +92,7 @@ function rowDataToRow(columns: Column[], row: RowData): FormRow {
function renderCell(
context: CellContext<RowData, unknown>,
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[],

View File

@@ -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;
}
}

View File

@@ -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.");