Browse Source

Merge pull request #3245 from nocodb/fix/mysql-trim-enum-set

fix: trailing space issue for enum/set options
pull/3246/head
mertmit 2 years ago committed by GitHub
parent
commit
7da0231f82
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 44
      packages/nocodb/src/lib/meta/api/columnApis.ts
  2. 8
      packages/nocodb/src/lib/models/Column.ts

44
packages/nocodb/src/lib/meta/api/columnApis.ts

@ -558,6 +558,13 @@ export async function columnAdd(req: Request, res: Response<TableType>) {
}
}
// Trim end of enum/set
if (colBody.dt === 'enum' || colBody.dt === 'set') {
for (const opt of colBody.colOptions.options) {
opt.title = opt.title.trimEnd()
}
}
if (colBody.uidt === UITypes.SingleSelect) {
colBody.dtxp = (colBody.colOptions?.options.length)
? `${colBody.colOptions.options.map(o => `'${o.title.replace(/'/gi, '\'\'')}'`).join(',')}`
@ -720,21 +727,6 @@ export async function columnUpdate(req: Request, res: Response<TableType>) {
) {
colBody = getColumnPropsFromUIDT(colBody, base);
if (colBody.uidt === UITypes.SingleSelect) {
colBody.dtxp = (colBody.colOptions?.options.length)
? `${colBody.colOptions.options.map(o => `'${o.title.replace(/'/gi, '\'\'')}'`).join(',')}`
: '';
} else if (colBody.uidt === UITypes.MultiSelect){
colBody.dtxp = (colBody.colOptions?.options.length)
? `${colBody.colOptions.options.map((o) => {
if(o.title.includes(',')) {
NcError.badRequest('Illegal char(\',\') for MultiSelect');
}
return `'${o.title.replace(/'/gi, '\'\'')}'`;
}).join(',')}`
: '';
}
const baseModel = await Model.getBaseModelSQL({
id: table.id,
dbDriver: NcConnectionMgrv2.get(base)
@ -809,6 +801,28 @@ export async function columnUpdate(req: Request, res: Response<TableType>) {
}
}
// Trim end of enum/set
if (colBody.dt === 'enum' || colBody.dt === 'set') {
for (const opt of colBody.colOptions.options) {
opt.title = opt.title.trimEnd()
}
}
if (colBody.uidt === UITypes.SingleSelect) {
colBody.dtxp = (colBody.colOptions?.options.length)
? `${colBody.colOptions.options.map(o => `'${o.title.replace(/'/gi, '\'\'')}'`).join(',')}`
: '';
} else if (colBody.uidt === UITypes.MultiSelect){
colBody.dtxp = (colBody.colOptions?.options.length)
? `${colBody.colOptions.options.map((o) => {
if(o.title.includes(',')) {
NcError.badRequest('Illegal char(\',\') for MultiSelect');
}
return `'${o.title.replace(/'/gi, '\'\'')}'`;
}).join(',')}`
: '';
}
// Handle option delete
for (const option of column.colOptions.options.filter(oldOp => colBody.colOptions.options.find(newOp => newOp.id === oldOp.id) ? false : true)) {
if (!supportedDrivers.includes(driverType) && column.uidt === UITypes.MultiSelect) {

8
packages/nocodb/src/lib/models/Column.ts

@ -246,6 +246,10 @@ export default class Column<T = any> implements ColumnType {
}
} else {
for (const [i, option] of column.colOptions.options.entries() || [].entries()) {
// Trim end of enum/set
if (column.dt === 'enum' || column.dt === 'set') {
option.title = option.title.trimEnd();
}
await SelectOption.insert(
{
...option,
@ -274,6 +278,10 @@ export default class Column<T = any> implements ColumnType {
}
} else {
for (const [i, option] of column.colOptions.options.entries() || [].entries()) {
// Trim end of enum/set
if (column.dt === 'enum' || column.dt === 'set') {
option.title = option.title.trimEnd();
}
await SelectOption.insert(
{
...option,

Loading…
Cancel
Save