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, disabled: false,
ghostClass: "ghost" ghostClass: "ghost"
}, },
validateTableName,
roleIcon: { roleIcon: {
owner: 'mdi-account-star', owner: 'mdi-account-star',
creator: 'mdi-account-hard-hat', creator: 'mdi-account-hard-hat',
@ -1768,6 +1767,9 @@ export default {
}; };
} }
}, },
validateTableName(v) {
return validateTableName(v, this.$store.getters['project/GtrProjectIsGraphql'])
},
}, },
async created() { async created() {
// this.loadDefaultTabs(); // this.loadDefaultTabs();

4
packages/nc-gui/components/project/spreadsheet/components/editColumn.vue

@ -455,7 +455,6 @@ export default {
value: Boolean value: Boolean
}, },
data: () => ({ data: () => ({
validateColumnName,
valid: false, valid: false,
relationDeleteDlg: false, relationDeleteDlg: false,
newColumn: {}, newColumn: {},
@ -516,6 +515,9 @@ export default {
this.focusInput() this.focusInput()
}, },
methods: { methods: {
validateColumnName(v) {
return validateColumnName(v, this.$store.getters['project/GtrProjectIsGraphql'])
},
onRelColumnSelect(colMeta) { onRelColumnSelect(colMeta) {
Object.assign(this.newColumn, { Object.assign(this.newColumn, {
dt: colMeta.dt, dt: colMeta.dt,

2
packages/nc-gui/components/project/spreadsheet/components/editVirtualColumn.vue

@ -122,7 +122,7 @@ export default {
validateColumnName(v) { validateColumnName(v) {
if (this.column.hm || this.column.mm || this.column.bt || this.column.lk) { return true } 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', 'created_at',
'updated_at'] 'updated_at']
}, },
validateTableName,
valid: false valid: false
} }
}, },
methods: {
validateTableName(v) {
return validateTableName(v, this.$store.getters['project/GtrProjectIsGraphql'])
}
},
computed: { computed: {
dialogShow: { dialogShow: {
get() { get() {

84
packages/nc-gui/helpers/index.js

@ -73,37 +73,77 @@ function GetCaretPosition(ctrl) {
return (CaretPos) return (CaretPos)
} }
export function validateTableName(v) { export function validateTableName(v, isGQL) {
if (!v) { if (!v) {
return 'Table name required' return "Table name required";
}
if (/^[_A-Za-z][_0-9A-Za-z]*$/.test(v)) {
return true
} }
if (/^[^_A-Za-z]/.test(v)) { // GraphQL naming convention
return 'Name should start with an alphabet or _' // http://spec.graphql.org/June2018/#Name
}
const m = v.match(/[^_A-Za-z\d]/g) if (isGQL) {
if (m) { if (/^[_A-Za-z][_0-9A-Za-z]*$/.test(v)) {
return `Following characters are not allowed ${m.map(c => JSON.stringify(c)).join(', ')}` 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) { if (!v) {
return 'Column name required' return "Column name required";
}
if (/^[_A-Za-z][_0-9A-Za-z]*$/.test(v)) {
return true
} }
if (/^[^_A-Za-z]/.test(v)) { // GraphQL naming convention
return 'Name should start with an alphabet or _' // http://spec.graphql.org/June2018/#Name
} if (isGQL) {
const m = v.match(/[^_A-Za-z\d]/g) if (/^[_A-Za-z][_0-9A-Za-z]*$/.test(v)) {
if (m) { return true;
return `Following characters are not allowed ${m.map(c => JSON.stringify(c)).join(', ')}` }
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