From df7d58c97746af9d107ec1eb52bde0e72949ba42 Mon Sep 17 00:00:00 2001 From: Wing-Kam Wong Date: Fri, 12 Aug 2022 19:12:19 +0800 Subject: [PATCH] fix(gui-v2): add table name length validator for table create --- .../nc-gui-v2/components/dlg/TableCreate.vue | 26 +++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/packages/nc-gui-v2/components/dlg/TableCreate.vue b/packages/nc-gui-v2/components/dlg/TableCreate.vue index 596eb44adc..91a6b8176d 100644 --- a/packages/nc-gui-v2/components/dlg/TableCreate.vue +++ b/packages/nc-gui-v2/components/dlg/TableCreate.vue @@ -18,7 +18,7 @@ const isAdvanceOptVisible = ref(false) const { addTab } = useTabs() -const { loadTables } = useProject() +const { loadTables, isMysql, isMssql, isPg } = useProject() const { table, createTable, generateUniqueTitle, tables, project } = useTable(async (table) => { await loadTables() @@ -40,7 +40,29 @@ const useForm = Form.useForm const validators = computed(() => { return { - title: [validateTableName, validateDuplicateAlias], + title: [ + validateTableName, + validateDuplicateAlias, + { + 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() + }) + }, + }, + ], table_name: [validateTableName], } })