From cec38a68f6b8c7cc60e798a1f1a2141650a6fb69 Mon Sep 17 00:00:00 2001 From: Bram Date: Mon, 16 Feb 2026 23:44:32 +0100 Subject: [PATCH 1/3] Fix multiple row get requests (#4777) --- .../selectWorkspaceDatabaseTable.js | 68 +++++++- web-frontend/modules/database/pages/table.vue | 157 ++++-------------- web-frontend/modules/database/store/view.js | 2 +- 3 files changed, 99 insertions(+), 128 deletions(-) diff --git a/web-frontend/modules/database/middleware/selectWorkspaceDatabaseTable.js b/web-frontend/modules/database/middleware/selectWorkspaceDatabaseTable.js index 16072046e1..ae71a3ec10 100644 --- a/web-frontend/modules/database/middleware/selectWorkspaceDatabaseTable.js +++ b/web-frontend/modules/database/middleware/selectWorkspaceDatabaseTable.js @@ -1,26 +1,86 @@ import { StoreItemLookupError } from '@baserow/modules/core/errors' import { normalizeError } from '@baserow/modules/database/utils/errors' +import { getDefaultView } from '@baserow/modules/database/utils/view' export default defineNuxtRouteMiddleware(async (to, from) => { - const { $store } = useNuxtApp() + const nuxtApp = useNuxtApp() + const { $store } = nuxtApp const databaseId = parseInt(to.params.databaseId) const tableId = parseInt(to.params.tableId) + const viewId = to.params.viewId ? parseInt(to.params.viewId) : null - // Select the table + let database, table try { - const { database } = await $store.dispatch('table/selectById', { + const result = await $store.dispatch('table/selectById', { databaseId, tableId, }) + database = result.database + table = result.table await $store.dispatch('workspace/selectById', database.workspace.id) } catch (e) { if (e.response === undefined && !(e instanceof StoreItemLookupError)) throw e throw createError({ - statusCode: 404, + statusCode: e.response?.status || 404, message: normalizeError(e).message, fatal: false, }) } + + // Fetch views and fields only if the table has changed because there is no need + // to fetch them if the view or row changes. + if ($store.state.view.tableId !== table.id) { + await $store.dispatch('view/fetchAll', table) + await $store.dispatch('field/fetchAll', table) + } + + // If the viewId is not provided, redirect to the default view. This prevents the + // page component from being created twice. + if (viewId === null) { + const rowId = to.params.rowId ? parseInt(to.params.rowId) : null + const defaultView = getDefaultView( + nuxtApp, + $store, + database.workspace.id, + rowId !== null + ) + + if (defaultView) { + return navigateTo({ + name: to.name, + params: { ...to.params, viewId: defaultView.id }, + query: to.query, + }) + } + } + + // Handle enlarged row modal state by already fetching the row if needed because + // it's provided in the params. + const rowId = to.params.rowId ? parseInt(to.params.rowId) : null + if (rowId) { + const row = await $store.dispatch('rowModalNavigation/fetchRow', { + tableId: table.id, + rowId, + }) + + // If fetch failed, redirect to table without rowId so that the table is still + // visible. + if (!row) { + return navigateTo( + { + name: 'database-table', + params: { ...to.params, rowId: '' }, + query: to.query, + }, + { replace: true } + ) + } + } else { + // If no rowId is provided, then we want to make 100% sure any old rows are + // cleared. This could be the case when a row is open, but the user navigates + // to page without selected row. + await $store.dispatch('rowModalNavigation/clearRow') + } }) diff --git a/web-frontend/modules/database/pages/table.vue b/web-frontend/modules/database/pages/table.vue index 4dbed659e9..70d23e5a47 100644 --- a/web-frontend/modules/database/pages/table.vue +++ b/web-frontend/modules/database/pages/table.vue @@ -27,20 +27,14 @@