Browse Source

feat(gui-v2): add table name length validator

pull/3117/head
Wing-Kam Wong 2 years ago
parent
commit
db0385cb8a
  1. 22
      packages/nc-gui-v2/components/dlg/TableRename.vue

22
packages/nc-gui-v2/components/dlg/TableRename.vue

@ -24,8 +24,7 @@ const dialogShow = computed({
}) })
const { updateTab } = useTabs() const { updateTab } = useTabs()
const { loadTables } = useProject() const { loadTables, tables, project, isMysql, isMssql, isPg } = useProject()
const { tables } = useProject()
const inputEl = $ref<any>() const inputEl = $ref<any>()
let loading = $ref(false) let loading = $ref(false)
@ -37,6 +36,25 @@ const validators = computed(() => {
return { return {
title: [ title: [
validateTableName, validateTableName,
{
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()
})
},
},
{ {
validator: (rule: any, value: any, callback: (errMsg?: string) => void) => { validator: (rule: any, value: any, callback: (errMsg?: string) => void) => {
if (/^\s+|\s+$/.test(value)) { if (/^\s+|\s+$/.test(value)) {

Loading…
Cancel
Save