mirror of
https://github.com/trailbaseio/trailbase.git
synced 2026-01-21 09:10:42 -06:00
Fix issue with qualified table names breaking admin dash row insertions/updates.
This commit is contained in:
@@ -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[],
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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.");
|
||||
|
||||
Reference in New Issue
Block a user