From db0385cb8aab2a34e233454607f59152ac62b3e2 Mon Sep 17 00:00:00 2001 From: Wing-Kam Wong Date: Fri, 12 Aug 2022 18:13:55 +0800 Subject: [PATCH] feat(gui-v2): add table name length validator --- .../nc-gui-v2/components/dlg/TableRename.vue | 22 +++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/packages/nc-gui-v2/components/dlg/TableRename.vue b/packages/nc-gui-v2/components/dlg/TableRename.vue index 3b58660782..2b89e802a4 100644 --- a/packages/nc-gui-v2/components/dlg/TableRename.vue +++ b/packages/nc-gui-v2/components/dlg/TableRename.vue @@ -24,8 +24,7 @@ const dialogShow = computed({ }) const { updateTab } = useTabs() -const { loadTables } = useProject() -const { tables } = useProject() +const { loadTables, tables, project, isMysql, isMssql, isPg } = useProject() const inputEl = $ref() let loading = $ref(false) @@ -37,6 +36,25 @@ const validators = computed(() => { return { title: [ validateTableName, + { + validator: (rule: any, value: any) => { + return new Promise((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) => { if (/^\s+|\s+$/.test(value)) {