fix(database-view): resolve default Grid view on insert
After createTable, fetch the auto-created views via the new GET /admin/tables/:tableId/views endpoint and use the Grid view id when inserting the embed node. Previously viewId was an empty string, so the renderer always rendered 'No rows found in this view'.
This commit is contained in:
parent
3c1b7a094d
commit
a23f836358
2 changed files with 24 additions and 4 deletions
|
|
@ -164,6 +164,16 @@ export async function deleteField(
|
|||
await api.delete(`/api/v1/admin/fields/${fieldId}`);
|
||||
}
|
||||
|
||||
export async function listViews(
|
||||
tableId: number,
|
||||
bridgeUrl?: string | null,
|
||||
): Promise<Array<{ id: number; name: string; type: string }>> {
|
||||
const api = getBridgeClient(resolveBridgeUrl(bridgeUrl));
|
||||
return unwrap<Array<{ id: number; name: string; type: string }>>(
|
||||
api.get(`/api/v1/admin/tables/${tableId}/views`),
|
||||
);
|
||||
}
|
||||
|
||||
export async function createView(
|
||||
tableId: number,
|
||||
payload: { name: string; type: 'grid' | 'gallery' | 'kanban' | 'calendar' | 'timeline' | 'form' },
|
||||
|
|
|
|||
|
|
@ -31,6 +31,7 @@ import {
|
|||
createDatabase,
|
||||
createTable,
|
||||
createField,
|
||||
listViews,
|
||||
} from "../services/admin-client";
|
||||
|
||||
type Step = "name" | "fields" | "creating";
|
||||
|
|
@ -184,15 +185,24 @@ export function CreateDatabaseModal({
|
|||
await createField(table.id, payload as never, bridgeUrl);
|
||||
}
|
||||
|
||||
// Step 4: insert the new table as a Tiptap node into the editor.
|
||||
// We don't have a viewId here yet — Baserow auto-creates a default Grid
|
||||
// view at table creation. We let the rendererfetch the first view.
|
||||
// Step 4: resolve the auto-created Grid view of the new table, then
|
||||
// insert the embed node with a real viewId (without it the renderer
|
||||
// shows "No rows found in this view").
|
||||
const views = await listViews(table.id, bridgeUrl);
|
||||
const defaultView =
|
||||
views.find((v) => v.type === "grid") ?? views[0] ?? null;
|
||||
if (!defaultView) {
|
||||
throw new Error(
|
||||
"Table creee mais aucune vue par defaut trouvee. Reessayez ou contactez un admin.",
|
||||
);
|
||||
}
|
||||
|
||||
editor
|
||||
.chain()
|
||||
.focus()
|
||||
.insertDatabaseView({
|
||||
tableId: String(table.id),
|
||||
viewId: "",
|
||||
viewId: String(defaultView.id),
|
||||
viewType: "grid",
|
||||
bridgeUrl: bridgeUrl ?? null,
|
||||
})
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue