+
@@ -16,15 +16,18 @@ import DashboardContent from '@baserow/modules/dashboard/components/DashboardCon
definePageMeta({
layout: 'app',
- middleware: ['dashboardLoading'],
+ middleware: [
+ 'settings',
+ 'authenticated',
+ 'workspacesAndApplications',
+ 'dashboardLoading',
+ ],
})
const store = useStore()
const route = useRoute()
-const router = useRouter()
const { $hasPermission, $realtime } = useNuxtApp()
-// Fetch dashboard data
const {
data,
pending,
@@ -49,12 +52,15 @@ const {
dashboard,
}
} catch (e) {
- console.error('Error loading dashboard:', e)
throw createError({ statusCode: 404, message: 'Dashboard not found.' })
}
}
)
+if (fetchError.value) {
+ throw fetchError.value
+}
+
const dashboard = computed(() => data.value?.dashboard)
const workspace = computed(() => data.value?.workspace)
@@ -71,7 +77,9 @@ onMounted(() => {
forEditing,
})
- $realtime.subscribe('dashboard', { dashboard_id: dashboard.value.id })
+ if (dashboard.value) {
+ $realtime.subscribe('dashboard', { dashboard_id: dashboard.value.id })
+ }
})
// Cleanup
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 @@