From ecd1d637711c65a2e70046043323cc83a13954ff Mon Sep 17 00:00:00 2001 From: Wing-Kam Wong Date: Fri, 12 Aug 2022 18:15:03 +0800 Subject: [PATCH] refactor(gui-v2): make table name validator promise based --- .../nc-gui-v2/components/dlg/TableRename.vue | 26 ++++++++++--------- 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/packages/nc-gui-v2/components/dlg/TableRename.vue b/packages/nc-gui-v2/components/dlg/TableRename.vue index 2b89e802a4..7bdcc2f25f 100644 --- a/packages/nc-gui-v2/components/dlg/TableRename.vue +++ b/packages/nc-gui-v2/components/dlg/TableRename.vue @@ -56,18 +56,20 @@ const validators = computed(() => { }, }, { - validator: (rule: any, value: any, callback: (errMsg?: string) => void) => { - if (/^\s+|\s+$/.test(value)) { - callback('Leading or trailing whitespace not allowed in table name') - } - if ( - !(tables?.value || []).every( - (t) => t.id === tableMeta.id || t.table_name.toLowerCase() !== (value || '').toLowerCase(), - ) - ) { - callback('Duplicate table alias') - } - callback() + validator: (rule: any, value: any) => { + return new Promise((resolve, reject) => { + if (/^\s+|\s+$/.test(value)) { + return reject(new Error('Leading or trailing whitespace not allowed in table name')) + } + if ( + !(tables?.value || []).every( + (t) => t.id === tableMeta.id || t.table_name.toLowerCase() !== (value || '').toLowerCase(), + ) + ) { + return reject(new Error('Duplicate table alias')) + } + resolve() + }) }, }, ],