Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<i class="iconoir-book-stack assistant__sources-icon"></i>
<span class="assistant__sources-label">
{{
$tc('assistantMessageSources.sources', sources.length, {
$t('assistantMessageSources.sources', sources.length, {
count: sources.length,
})
}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ export default defineNuxtRouteMiddleware(async (to, from) => {
const fromDashboardId = parseIntOrNull(from?.params?.dashboardId)
const differentDashboardId = fromDashboardId !== toDashboardId

if (!from || differentDashboardId) {
// If it's the first page or the server side rendered page, then always put the
// dashboard in the loading state for the correct animation.
if (import.meta.server || !from || differentDashboardId) {
await store.dispatch('dashboardApplication/setLoading', true)
}
})
20 changes: 14 additions & 6 deletions web-frontend/modules/dashboard/pages/dashboard.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template>
<div v-if="dashboard" class="dashboard-app">
<div class="dashboard-app">
<DashboardHeader :dashboard="dashboard" />
<DashboardContent :dashboard="dashboard" />
</div>
Expand All @@ -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,
Expand All @@ -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)

Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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')
}
})
Loading
Loading