Browse Source

feat: front-end allow multiple base per project

Signed-off-by: mertmit <mertmit99@gmail.com>
pull/3573/head
mertmit 2 years ago
parent
commit
8edb4e4b2c
  1. 6
      packages/nc-gui/components/smartsheet/column/AdvancedOptions.vue
  2. 4
      packages/nc-gui/components/smartsheet/column/LinkedToAnotherRecordOptions.vue
  3. 4
      packages/nc-gui/components/template/Editor.vue
  4. 7
      packages/nc-gui/composables/useColumnCreateStore.ts
  5. 41
      packages/nc-gui/composables/useProject.ts
  6. 3
      packages/nc-gui/composables/useSmartsheetStore.ts
  7. 3
      packages/nc-gui/composables/useTable.ts

6
packages/nc-gui/components/smartsheet/column/AdvancedOptions.vue

@ -1,6 +1,6 @@
<script setup lang="ts"> <script setup lang="ts">
import { UITypes } from 'nocodb-sdk' import { UITypes } from 'nocodb-sdk'
import { computed, useColumnCreateStoreOrThrow, useProject, useVModel } from '#imports' import { computed, useColumnCreateStoreOrThrow, useVModel } from '#imports'
const props = defineProps<{ const props = defineProps<{
value: any value: any
@ -10,9 +10,7 @@ const emit = defineEmits(['update:value'])
const vModel = useVModel(props, 'value', emit) const vModel = useVModel(props, 'value', emit)
const { sqlUi } = useProject() const { onAlter, onDataTypeChange, validateInfos, sqlUi } = useColumnCreateStoreOrThrow()
const { onAlter, onDataTypeChange, validateInfos } = useColumnCreateStoreOrThrow()
// todo: 2nd argument of `getDataTypeListForUiType` is missing! // todo: 2nd argument of `getDataTypeListForUiType` is missing!
const dataTypes = computed(() => sqlUi.value.getDataTypeListForUiType(vModel.value as { uidt: UITypes }, '' as any)) const dataTypes = computed(() => sqlUi.value.getDataTypeListForUiType(vModel.value as { uidt: UITypes }, '' as any))

4
packages/nc-gui/components/smartsheet/column/LinkedToAnotherRecordOptions.vue

@ -14,9 +14,9 @@ const vModel = useVModel(props, 'value', emit)
const meta = $(inject(MetaInj, ref())) const meta = $(inject(MetaInj, ref()))
const { setAdditionalValidations, validateInfos, onDataTypeChange } = useColumnCreateStoreOrThrow() const { setAdditionalValidations, validateInfos, onDataTypeChange, sqlUi } = useColumnCreateStoreOrThrow()
const { tables, sqlUi } = $(useProject()) const { tables } = $(useProject())
setAdditionalValidations({ setAdditionalValidations({
childId: [{ required: true, message: 'Required' }], childId: [{ required: true, message: 'Required' }],

4
packages/nc-gui/components/template/Editor.vue

@ -64,7 +64,9 @@ const { $api } = useNuxtApp()
const { addTab } = useTabs() const { addTab } = useTabs()
const { sqlUi, project, loadTables } = useProject() const { sqlUis, project, loadTables } = useProject()
const sqlUi = ref(meta.value?.base_id ? sqlUis.value[meta.value?.base_id] : sqlUis.value[0])
const hasSelectColumn = ref<boolean[]>([]) const hasSelectColumn = ref<boolean[]>([])

7
packages/nc-gui/composables/useColumnCreateStore.ts

@ -27,8 +27,7 @@ interface ValidationsObj {
const [useProvideColumnCreateStore, useColumnCreateStore] = createInjectionState( const [useProvideColumnCreateStore, useColumnCreateStore] = createInjectionState(
(meta: Ref<TableType | undefined>, column: Ref<ColumnType | undefined>) => { (meta: Ref<TableType | undefined>, column: Ref<ColumnType | undefined>) => {
const { sqlUi } = useProject() const { sqlUis } = useProject()
const { $api } = useNuxtApp() const { $api } = useNuxtApp()
const { getMeta } = useMetas() const { getMeta } = useMetas()
@ -37,7 +36,9 @@ const [useProvideColumnCreateStore, useColumnCreateStore] = createInjectionState
const { $e } = useNuxtApp() const { $e } = useNuxtApp()
const isEdit = computed(() => !!column.value?.id) const sqlUi = ref(meta.value?.base_id ? sqlUis.value[meta.value?.base_id] : sqlUis.value[0])
const isEdit = computed(() => !!column?.value?.id)
const idType = null const idType = null

41
packages/nc-gui/composables/useProject.ts

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

3
packages/nc-gui/composables/useSmartsheetStore.ts

@ -13,8 +13,9 @@ const [useProvideSmartsheetStore, useSmartsheetStore] = useInjectionState(
initialFilters?: Ref<FilterType[]>, initialFilters?: Ref<FilterType[]>,
) => { ) => {
const { $api } = useNuxtApp() const { $api } = useNuxtApp()
const { sqlUis } = useProject()
const { sqlUi } = useProject() const sqlUi = ref(meta.value?.base_id ? sqlUis.value[meta.value?.base_id] : sqlUis.value[0])
const cellRefs = ref<HTMLTableDataCellElement[]>([]) const cellRefs = ref<HTMLTableDataCellElement[]>([])

3
packages/nc-gui/composables/useTable.ts

@ -32,8 +32,9 @@ export function useTable(onTableCreate?: (tableMeta: TableType) => void) {
const { loadTables } = useProject() const { loadTables } = useProject()
const { closeTab } = useTabs() const { closeTab } = useTabs()
const { sqlUis, project, tables } = useProject()
const { sqlUi, project, tables } = useProject() const sqlUi = ref(sqlUis.value[0])
const createTable = async () => { const createTable = async () => {
if (!sqlUi?.value) return if (!sqlUi?.value) return

Loading…
Cancel
Save