feat: front-end allow multiple base per project

Signed-off-by: mertmit <mertmit99@gmail.com>
This commit is contained in:
mertmit
2022-09-12 22:42:37 +03:00
parent 1b369417d3
commit 8edb4e4b2c
7 changed files with 46 additions and 22 deletions

View File

@@ -1,4 +1,4 @@
import type { OracleUi, ProjectType, TableType } from 'nocodb-sdk'
import type { BaseType, OracleUi, ProjectType, TableType } from 'nocodb-sdk'
import { SqlUiFactory } from 'nocodb-sdk'
import { isString } from '@vueuse/core'
import {
@@ -35,7 +35,7 @@ const [setup, use] = useInjectionState(() => {
const projectLoadedHook = createEventHook<ProjectType>()
const project = ref<ProjectType>({})
const bases = computed<BaseType[]>(() => project.value?.bases || [])
const tables = ref<TableType[]>([])
const projectMetaInfo = ref<ProjectMetaInfo | undefined>()
@@ -55,15 +55,35 @@ const [setup, use] = useInjectionState(() => {
}
})
const projectBaseType = $computed(() => project.value?.bases?.[0]?.type || ClientType.MYSQL)
const sqlUis = computed(() => {
const temp: Record<string, any> = {}
for (const base of bases.value) {
if (base.id) {
temp[base.id] = SqlUiFactory.create({ client: base.type }) as Exclude<
ReturnType<typeof SqlUiFactory['create']>,
typeof OracleUi
>
}
}
return temp
})
const sqlUi = computed(
() => SqlUiFactory.create({ client: projectBaseType }) as Exclude<ReturnType<typeof SqlUiFactory['create']>, typeof OracleUi>,
)
function getBaseType(baseId: string) {
return bases.value.find((base) => base.id === baseId)?.type || ClientType.MYSQL
}
function isMysql(baseId: string) {
return ['mysql', ClientType.MYSQL].includes(getBaseType(baseId))
}
function isMssql(baseId: string) {
return getBaseType(baseId) === 'mssql'
}
function isPg(baseId: string) {
return getBaseType(baseId) === 'pg'
}
const isMysql = computed(() => ['mysql', ClientType.MYSQL].includes(projectBaseType))
const isMssql = computed(() => projectBaseType === 'mssql')
const isPg = computed(() => projectBaseType === 'pg')
const isSharedBase = computed(() => projectType === 'base')
async function loadProjectMetaInfo(force?: boolean) {
@@ -151,6 +171,7 @@ const [setup, use] = useInjectionState(() => {
return {
project,
bases,
tables,
loadProjectRoles,
loadProject,
@@ -159,7 +180,7 @@ const [setup, use] = useInjectionState(() => {
isMysql,
isMssql,
isPg,
sqlUi,
sqlUis,
isSharedBase,
loadProjectMetaInfo,
projectMetaInfo,