|
|
@ -58,7 +58,12 @@ export function useTableNew(param: { onTableCreate?: (tableMeta: TableType) => v |
|
|
|
const tables = computed(() => baseTables.value.get(param.baseId) || []) |
|
|
|
const tables = computed(() => baseTables.value.get(param.baseId) || []) |
|
|
|
const base = computed(() => bases.value.get(param.baseId)) |
|
|
|
const base = computed(() => bases.value.get(param.baseId)) |
|
|
|
|
|
|
|
|
|
|
|
const openTable = async (table: TableType) => { |
|
|
|
const openTable = async ( |
|
|
|
|
|
|
|
table: TableType & { |
|
|
|
|
|
|
|
isMetaLoading?: boolean |
|
|
|
|
|
|
|
isViewsLoading?: boolean |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
) => { |
|
|
|
if (!table.base_id) return |
|
|
|
if (!table.base_id) return |
|
|
|
|
|
|
|
|
|
|
|
let base = bases.value.get(table.base_id) |
|
|
|
let base = bases.value.get(table.base_id) |
|
|
@ -82,24 +87,49 @@ export function useTableNew(param: { onTableCreate?: (tableMeta: TableType) => v |
|
|
|
baseIdOrBaseId = route.value.params.baseId as string |
|
|
|
baseIdOrBaseId = route.value.params.baseId as string |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
await getMeta(table.id as string, (route.value.params?.viewId as string) !== table.id) |
|
|
|
const navigateToTable = async () => { |
|
|
|
|
|
|
|
if (openedViewsTab.value === 'view') { |
|
|
|
|
|
|
|
await navigateTo({ |
|
|
|
|
|
|
|
path: `/${workspaceIdOrType}/${baseIdOrBaseId}/${table?.id}`, |
|
|
|
|
|
|
|
query: route.value.query, |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
await loadViews({ tableId: table.id as string }) |
|
|
|
table.isViewsLoading = true |
|
|
|
|
|
|
|
|
|
|
|
const views = viewsByTable.value.get(table.id as string) ?? [] |
|
|
|
try { |
|
|
|
if (openedViewsTab.value !== 'view' && views.length && views[0].id) { |
|
|
|
await loadViews({ tableId: table.id as string }) |
|
|
|
// find the default view and navigate to it, if not found navigate to the first one
|
|
|
|
|
|
|
|
const defaultView = views.find((v) => v.is_default) || views[0] |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
await navigateTo({ |
|
|
|
const views = viewsByTable.value.get(table.id as string) ?? [] |
|
|
|
path: `/${workspaceIdOrType}/${baseIdOrBaseId}/${table?.id}/${defaultView.id}/${openedViewsTab.value}`, |
|
|
|
if (openedViewsTab.value !== 'view' && views.length && views[0].id) { |
|
|
|
query: route.value.query, |
|
|
|
// find the default view and navigate to it, if not found navigate to the first one
|
|
|
|
}) |
|
|
|
const defaultView = views.find((v) => v.is_default) || views[0] |
|
|
|
} else |
|
|
|
|
|
|
|
await navigateTo({ |
|
|
|
await navigateTo({ |
|
|
|
path: `/${workspaceIdOrType}/${baseIdOrBaseId}/${table?.id}`, |
|
|
|
path: `/${workspaceIdOrType}/${baseIdOrBaseId}/${table?.id}/${defaultView.id}/${openedViewsTab.value}`, |
|
|
|
query: route.value.query, |
|
|
|
query: route.value.query, |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} catch (e) { |
|
|
|
|
|
|
|
console.error(e) |
|
|
|
|
|
|
|
} finally { |
|
|
|
|
|
|
|
table.isViewsLoading = false |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const loadTableMeta = async () => { |
|
|
|
|
|
|
|
table.isMetaLoading = true |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
await getMeta(table.id as string) |
|
|
|
|
|
|
|
} catch (e) { |
|
|
|
|
|
|
|
console.error(e) |
|
|
|
|
|
|
|
} finally { |
|
|
|
|
|
|
|
table.isMetaLoading = false |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
await Promise.all([navigateToTable(), loadTableMeta()]) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const createTable = async () => { |
|
|
|
const createTable = async () => { |
|
|
|