The insert-database modal called the public bridge /api/v1/tables route, which requires a databaseId and a Baserow user JWT — the modal supplied neither, so the request returned 400 then 501. Add a step 0 to pick a workspace and database (auto-resolved when each lists only one), then list tables via the admin endpoint GET /api/v1/admin/tables?databaseId=X. The client extension is also rewired to .extend() the shared DatabaseView node.
36 lines
1.2 KiB
TypeScript
36 lines
1.2 KiB
TypeScript
import { useQuery } from "@tanstack/react-query";
|
|
import { listTables, type BaserowTableSummary } from "../services/admin-client";
|
|
import type { BridgeTable } from "../types/database-view.types";
|
|
|
|
export const TABLES_QUERY_KEY = ["bridge-admin-tables"] as const;
|
|
|
|
/**
|
|
* Fetch tables of a Baserow database via the bridge admin endpoint.
|
|
*
|
|
* The legacy `GET /api/v1/tables` requires a Baserow user JWT and a databaseId
|
|
* filter — neither was wired into the modal — so we list via the admin client
|
|
* (`GET /api/v1/admin/tables?databaseId=X`) which uses a service-account JWT.
|
|
*
|
|
* The query is disabled until a databaseId is provided.
|
|
*/
|
|
export function useTables(
|
|
databaseId?: number | null,
|
|
bridgeUrl?: string | null,
|
|
) {
|
|
return useQuery<BridgeTable[]>({
|
|
queryKey: [...TABLES_QUERY_KEY, databaseId ?? null, bridgeUrl ?? null],
|
|
queryFn: async () => {
|
|
if (!databaseId) return [];
|
|
const rows = await listTables(databaseId, bridgeUrl);
|
|
return rows.map(
|
|
(t: BaserowTableSummary): BridgeTable => ({
|
|
id: String(t.id),
|
|
name: t.name,
|
|
databaseId: t.database_id,
|
|
}),
|
|
);
|
|
},
|
|
enabled: Boolean(databaseId),
|
|
staleTime: 30_000,
|
|
});
|
|
}
|