diff --git a/packages/nc-gui-v2/components/dashboard/TreeView.vue b/packages/nc-gui-v2/components/dashboard/TreeView.vue
index ba44e7bc09..e13eadd331 100644
--- a/packages/nc-gui-v2/components/dashboard/TreeView.vue
+++ b/packages/nc-gui-v2/components/dashboard/TreeView.vue
@@ -1,14 +1,10 @@
diff --git a/packages/nc-gui-v2/composables/index.ts b/packages/nc-gui-v2/composables/index.ts
index e3cc4c88c0..92931e7baf 100644
--- a/packages/nc-gui-v2/composables/index.ts
+++ b/packages/nc-gui-v2/composables/index.ts
@@ -10,7 +10,7 @@ export * from './useHasMany'
export * from './useManyToMany'
export * from './useMetas'
export * from './useProject'
-export * from './useTableCreate'
+export * from './useTable'
export * from './useTabs'
export * from './useViewColumns'
export * from './useViewData'
@@ -18,6 +18,5 @@ export * from './useViewFilters'
export * from './useViews'
export * from './useViewSorts'
export * from './useVirtualCell'
-export * from './useDeleteTable'
export * from './useColumnCreateStore'
export * from './useSmartsheetStore'
diff --git a/packages/nc-gui-v2/composables/useDeleteTable.ts b/packages/nc-gui-v2/composables/useTable.ts
similarity index 58%
rename from packages/nc-gui-v2/composables/useDeleteTable.ts
rename to packages/nc-gui-v2/composables/useTable.ts
index 33e2c46aee..c30a5cdd3c 100644
--- a/packages/nc-gui-v2/composables/useDeleteTable.ts
+++ b/packages/nc-gui-v2/composables/useTable.ts
@@ -2,16 +2,59 @@ import { Modal } from 'ant-design-vue'
import type { LinkToAnotherRecordType, TableType } from 'nocodb-sdk'
import { UITypes } from 'nocodb-sdk'
import { useToast } from 'vue-toastification'
-import { useTabs } from '#imports'
+import { useProject } from './useProject'
import { TabType } from '~/composables/useTabs'
-import { extractSdkResponseErrorMsg } from '~/utils/errorUtils'
+import { extractSdkResponseErrorMsg } from '~/utils'
+import { useNuxtApp } from '#app'
+
+export function useTable(onTableCreate?: (tableMeta: TableType) => void) {
+ const table = reactive<{ title: string; table_name: string; columns: string[] }>({
+ title: '',
+ table_name: '',
+ columns: ['id', 'title', 'created_at', 'updated_at'],
+ })
-export function useDeleteTable() {
const { $e, $api } = useNuxtApp()
const toast = useToast()
const { getMeta, removeMeta } = useMetas()
const { loadTables } = useProject()
const { closeTab } = useTabs()
+ const { sqlUi, project, tables } = useProject()
+
+ const createTable = async () => {
+ if (!sqlUi?.value) return
+ const columns = sqlUi?.value?.getNewTableColumns().filter((col) => {
+ if (col.column_name === 'id' && table.columns.includes('id_ag')) {
+ Object.assign(col, sqlUi?.value?.getDataTypeForUiType({ uidt: UITypes.ID }, 'AG'))
+ col.dtxp = sqlUi?.value?.getDefaultLengthForDatatype(col.dt)
+ col.dtxs = sqlUi?.value?.getDefaultScaleForDatatype(col.dt)
+ return true
+ }
+ return table.columns.includes(col.column_name)
+ })
+
+ const tableMeta = await $api.dbTable.create(project?.value?.id as string, {
+ ...table,
+ columns,
+ })
+
+ onTableCreate?.(tableMeta)
+ }
+
+ watch(
+ () => table.title,
+ (title) => {
+ table.table_name = `${project?.value?.prefix || ''}${title}`
+ },
+ )
+
+ const generateUniqueTitle = () => {
+ let c = 1
+ while (tables?.value?.some((t) => t.title === `Sheet${c}`)) {
+ c++
+ }
+ table.title = `Sheet${c}`
+ }
const deleteTable = (table: TableType) => {
$e('c:table:delete')
@@ -65,5 +108,5 @@ export function useDeleteTable() {
})
}
- return { deleteTable }
+ return { table, createTable, generateUniqueTitle, tables, project, deleteTable }
}
diff --git a/packages/nc-gui-v2/composables/useTableCreate.ts b/packages/nc-gui-v2/composables/useTableCreate.ts
deleted file mode 100644
index 581ea88463..0000000000
--- a/packages/nc-gui-v2/composables/useTableCreate.ts
+++ /dev/null
@@ -1,52 +0,0 @@
-import type { TableType } from 'nocodb-sdk'
-import { UITypes } from 'nocodb-sdk'
-import { useProject } from './useProject'
-import { useNuxtApp } from '#app'
-
-export function useTableCreate(onTableCreate?: (tableMeta: TableType) => void) {
- const table = reactive<{ title: string; table_name: string; columns: string[] }>({
- title: '',
- table_name: '',
- columns: ['id', 'title', 'created_at', 'updated_at'],
- })
-
- const { sqlUi, project, tables } = useProject()
- const { $api } = useNuxtApp()
-
- const createTable = async () => {
- if (!sqlUi?.value) return
- const columns = sqlUi?.value?.getNewTableColumns().filter((col) => {
- if (col.column_name === 'id' && table.columns.includes('id_ag')) {
- Object.assign(col, sqlUi?.value?.getDataTypeForUiType({ uidt: UITypes.ID }, 'AG'))
- col.dtxp = sqlUi?.value?.getDefaultLengthForDatatype(col.dt)
- col.dtxs = sqlUi?.value?.getDefaultScaleForDatatype(col.dt)
- return true
- }
- return table.columns.includes(col.column_name)
- })
-
- const tableMeta = await $api.dbTable.create(project?.value?.id as string, {
- ...table,
- columns,
- })
-
- onTableCreate?.(tableMeta)
- }
-
- watch(
- () => table.title,
- (title) => {
- table.table_name = `${project?.value?.prefix || ''}${title}`
- },
- )
-
- const generateUniqueTitle = () => {
- let c = 1
- while (tables?.value?.some((t) => t.title === `Sheet${c}`)) {
- c++
- }
- table.title = `Sheet${c}`
- }
-
- return { table, createTable, generateUniqueTitle, tables, project }
-}