Browse Source

feat(gui-v2): generate default table name

Signed-off-by: Pranav C <pranavxc@gmail.com>
pull/2716/head
Pranav C 2 years ago
parent
commit
ad445aeb66
  1. 9
      packages/nc-gui-v2/components/dlg/TableCreate.vue
  2. 10
      packages/nc-gui-v2/composables/useTableCreate.ts

9
packages/nc-gui-v2/components/dlg/TableCreate.vue

@ -1,7 +1,7 @@
<script setup lang="ts">
import { onMounted } from '@vue/runtime-core'
import useTableCreate from '../../composables/useTableCreate'
import { validateTableName } from '~/utils/validation'
import useProject from '~/composables/useProject'
const { modelValue } = defineProps<{ modelValue?: boolean }>()
@ -18,8 +18,7 @@ const dialogShow = computed({
const valid = ref(false)
const isAdvanceOptVisible = ref(false)
const { table, createTable } = useTableCreate()
const { tables, project } = useProject()
const { table, createTable, generateUniqueTitle, tables, project } = useTableCreate()
const prefix = computed(() => project?.value?.prefix || '')
@ -33,6 +32,10 @@ const validateDuplicate = (v: string) => {
return (tables?.value || []).every((t) => t.table_name.toLowerCase() !== (v || '').toLowerCase()) || 'Duplicate table name'
}
onMounted(() => {
generateUniqueTitle()
})
/* import { validateTableName } from '~/helpers'
export default {

10
packages/nc-gui-v2/composables/useTableCreate.ts

@ -6,7 +6,7 @@ export default (onTableCreate?: (tableMeta: any) => void) => {
table_name: '',
})
const { sqlUi, project } = useProject()
const { sqlUi, project, tables } = useProject()
const { $api } = useNuxtApp()
const createTable = async () => {
@ -39,8 +39,12 @@ export default (onTableCreate?: (tableMeta: any) => void) => {
)
const generateUniqueTitle = () => {
let c = 1
while (tables?.value?.some((t) => t.title === `Sheet${c}`)) {
c++
}
table.title = `Sheet${c}`
}
return { table, createTable }
return { table, createTable, generateUniqueTitle, tables, project }
}

Loading…
Cancel
Save