Browse Source

feat: extended character support for table/column name with REST

Signed-off-by: Raju Udava <86527202+dstala@users.noreply.github.com>
pull/1329/head
Raju Udava 3 years ago
parent
commit
1ec0a5c245
  1. 4
      packages/nc-gui/components/ProjectTreeView.vue
  2. 4
      packages/nc-gui/components/project/spreadsheet/components/editColumn.vue
  3. 2
      packages/nc-gui/components/project/spreadsheet/components/editVirtualColumn.vue
  4. 6
      packages/nc-gui/components/utils/dlgTableCreate.vue
  5. 84
      packages/nc-gui/helpers/index.js

4
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();

4
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,

2
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'])
}
}
}

6
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() {

84
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;
}
}

Loading…
Cancel
Save