Browse Source

fix(gui-v2): add table name length validator for table create

pull/3117/head
Wing-Kam Wong 2 years ago
parent
commit
df7d58c977
  1. 26
      packages/nc-gui-v2/components/dlg/TableCreate.vue

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

@ -18,7 +18,7 @@ const isAdvanceOptVisible = ref(false)
const { addTab } = useTabs() const { addTab } = useTabs()
const { loadTables } = useProject() const { loadTables, isMysql, isMssql, isPg } = useProject()
const { table, createTable, generateUniqueTitle, tables, project } = useTable(async (table) => { const { table, createTable, generateUniqueTitle, tables, project } = useTable(async (table) => {
await loadTables() await loadTables()
@ -40,7 +40,29 @@ const useForm = Form.useForm
const validators = computed(() => { const validators = computed(() => {
return { return {
title: [validateTableName, validateDuplicateAlias], title: [
validateTableName,
validateDuplicateAlias,
{
validator: (rule: any, value: any) => {
return new Promise<void>((resolve, reject) => {
let tableNameLengthLimit = 255
if (isMysql) {
tableNameLengthLimit = 64
} else if (isPg) {
tableNameLengthLimit = 63
} else if (isMssql) {
tableNameLengthLimit = 128
}
const projectPrefix = project?.value?.prefix || ''
if ((projectPrefix + value).length > tableNameLengthLimit) {
return reject(new Error(`Table name exceeds ${tableNameLengthLimit} characters`))
}
resolve()
})
},
},
],
table_name: [validateTableName], table_name: [validateTableName],
} }
}) })

Loading…
Cancel
Save