From 1ec0a5c245d874b316be5963335bdc4e5c4961e8 Mon Sep 17 00:00:00 2001 From: Raju Udava <86527202+dstala@users.noreply.github.com> Date: Fri, 18 Feb 2022 22:57:27 +0530 Subject: [PATCH] feat: extended character support for table/column name with REST Signed-off-by: Raju Udava <86527202+dstala@users.noreply.github.com> --- .../nc-gui/components/ProjectTreeView.vue | 4 +- .../spreadsheet/components/editColumn.vue | 4 +- .../components/editVirtualColumn.vue | 2 +- .../components/utils/dlgTableCreate.vue | 6 +- packages/nc-gui/helpers/index.js | 84 ++++++++++++++----- 5 files changed, 74 insertions(+), 26 deletions(-) diff --git a/packages/nc-gui/components/ProjectTreeView.vue b/packages/nc-gui/components/ProjectTreeView.vue index d207a8b22d..532d6fc9ce 100644 --- a/packages/nc-gui/components/ProjectTreeView.vue +++ b/packages/nc-gui/components/ProjectTreeView.vue @@ -751,7 +751,6 @@ export default { disabled: false, ghostClass: "ghost" }, - validateTableName, roleIcon: { owner: 'mdi-account-star', creator: 'mdi-account-hard-hat', @@ -1768,6 +1767,9 @@ export default { }; } }, + validateTableName(v) { + return validateTableName(v, this.$store.getters['project/GtrProjectIsGraphql']) + }, }, async created() { // this.loadDefaultTabs(); diff --git a/packages/nc-gui/components/project/spreadsheet/components/editColumn.vue b/packages/nc-gui/components/project/spreadsheet/components/editColumn.vue index 14e3f1f649..8594c60740 100644 --- a/packages/nc-gui/components/project/spreadsheet/components/editColumn.vue +++ b/packages/nc-gui/components/project/spreadsheet/components/editColumn.vue @@ -455,7 +455,6 @@ export default { value: Boolean }, data: () => ({ - validateColumnName, valid: false, relationDeleteDlg: false, newColumn: {}, @@ -516,6 +515,9 @@ export default { this.focusInput() }, methods: { + validateColumnName(v) { + return validateColumnName(v, this.$store.getters['project/GtrProjectIsGraphql']) + }, onRelColumnSelect(colMeta) { Object.assign(this.newColumn, { dt: colMeta.dt, diff --git a/packages/nc-gui/components/project/spreadsheet/components/editVirtualColumn.vue b/packages/nc-gui/components/project/spreadsheet/components/editVirtualColumn.vue index 0271e7b3f1..99ec4a1dc7 100644 --- a/packages/nc-gui/components/project/spreadsheet/components/editVirtualColumn.vue +++ b/packages/nc-gui/components/project/spreadsheet/components/editVirtualColumn.vue @@ -122,7 +122,7 @@ export default { validateColumnName(v) { if (this.column.hm || this.column.mm || this.column.bt || this.column.lk) { return true } - return validateColumnName(v) + return validateColumnName(v, this.$store.getters['project/GtrProjectIsGraphql']) } } } diff --git a/packages/nc-gui/components/utils/dlgTableCreate.vue b/packages/nc-gui/components/utils/dlgTableCreate.vue index a7a2ebf5b5..80ab06da66 100644 --- a/packages/nc-gui/components/utils/dlgTableCreate.vue +++ b/packages/nc-gui/components/utils/dlgTableCreate.vue @@ -136,10 +136,14 @@ export default { 'created_at', 'updated_at'] }, - validateTableName, valid: false } }, + methods: { + validateTableName(v) { + return validateTableName(v, this.$store.getters['project/GtrProjectIsGraphql']) + } + }, computed: { dialogShow: { get() { diff --git a/packages/nc-gui/helpers/index.js b/packages/nc-gui/helpers/index.js index e338ff38c2..18a7fde719 100644 --- a/packages/nc-gui/helpers/index.js +++ b/packages/nc-gui/helpers/index.js @@ -73,37 +73,77 @@ function GetCaretPosition(ctrl) { return (CaretPos) } -export function validateTableName(v) { +export function validateTableName(v, isGQL) { if (!v) { - return 'Table name required' - } - if (/^[_A-Za-z][_0-9A-Za-z]*$/.test(v)) { - return true + return "Table name required"; } - if (/^[^_A-Za-z]/.test(v)) { - return 'Name should start with an alphabet or _' - } - const m = v.match(/[^_A-Za-z\d]/g) - if (m) { - return `Following characters are not allowed ${m.map(c => JSON.stringify(c)).join(', ')}` + // GraphQL naming convention + // http://spec.graphql.org/June2018/#Name + + if (isGQL) { + if (/^[_A-Za-z][_0-9A-Za-z]*$/.test(v)) { + return true; + } + + if (/^[^_A-Za-z]/.test(v)) { + return "Name should start with an alphabet or _"; + } + const m = v.match(/[^_A-Za-z\d]/g); + if (m) { + return `Following characters are not allowed ${m + .map((c) => JSON.stringify(c)) + .join(", ")}`; + } + } else { + + // exclude . / \ + // rest all characters allowed + // https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/acreldb/n0rfg6x1shw0ppn1cwhco6yn09f7.htm#:~:text=By%20default%2C%20MySQL%20encloses%20column,not%20truncate%20a%20longer%20name. + const m = v.match(/[./\\]/g); + if (m) { + return `Following characters are not allowed ${m + .map((c) => JSON.stringify(c)) + .join(", ")}`; + } + + return true; } } -export function validateColumnName(v) { +export function validateColumnName(v, isGQL) { if (!v) { - return 'Column name required' - } - if (/^[_A-Za-z][_0-9A-Za-z]*$/.test(v)) { - return true + return "Column name required"; } - if (/^[^_A-Za-z]/.test(v)) { - return 'Name should start with an alphabet or _' - } - const m = v.match(/[^_A-Za-z\d]/g) - if (m) { - return `Following characters are not allowed ${m.map(c => JSON.stringify(c)).join(', ')}` + // GraphQL naming convention + // http://spec.graphql.org/June2018/#Name + if (isGQL) { + if (/^[_A-Za-z][_0-9A-Za-z]*$/.test(v)) { + return true; + } + + if (/^[^_A-Za-z]/.test(v)) { + return "Name should start with an alphabet or _"; + } + const m = v.match(/[^_A-Za-z\d]/g); + if (m) { + return `Following characters are not allowed ${m + .map((c) => JSON.stringify(c)) + .join(", ")}`; + } + } else { + // exclude . / \ + // rest all characters allowed + // https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/acreldb/n0rfg6x1shw0ppn1cwhco6yn09f7.htm#:~:text=By%20default%2C%20MySQL%20encloses%20column,not%20truncate%20a%20longer%20name. + const m = v.match(/[./\\]/g); + if (m) { + return `Following characters are not allowed ${m + .map((c) => JSON.stringify(c)) + .join(", ")}`; + } + + return true; } }