Browse Source

fix: unified default value for select columns

Re #2766

Signed-off-by: mertmit <mertmit99@gmail.com>
pull/2751/head
mertmit 2 years ago
parent
commit
718499846a
  1. 10
      packages/nc-gui/components/project/spreadsheet/components/EditColumn.vue
  2. 35
      packages/nocodb/src/lib/meta/api/columnApis.ts

10
packages/nc-gui/components/project/spreadsheet/components/EditColumn.vue

@ -399,7 +399,7 @@
<v-textarea
v-model="newColumn.cdf"
:label="$t('placeholder.defaultValue')"
:hint="sqlUi.getDefaultValueForDatatype(newColumn.dt)"
:hint="defaultValueHint"
persistent-hint
rows="3"
outlined
@ -586,6 +586,14 @@ export default {
isDate() {
return this.newColumn && this.newColumn.uidt === UITypes.Date;
},
defaultValueHint() {
if (this.newColumn.uidt === UITypes.MultiSelect) {
return 'eg : a,b,c';
} else if (this.newColumn.uidt === UITypes.SingleSelect) {
return 'eg : a';
}
return this.sqlUi.getDefaultValueForDatatype(this.newColumn.dt);
},
},
watch: {
column() {

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

@ -513,7 +513,25 @@ export async function columnAdd(req: Request, res: Response<TableType>) {
if ([UITypes.SingleSelect, UITypes.MultiSelect].includes(colBody.uidt)) {
const dbDriver = NcConnectionMgrv2.get(base);
const driverType = dbDriver.clientType();
const optionTitles = colBody.colOptions.options.map(el => el.title);
// Handle default values
if (colBody.cdf) {
if (colBody.uidt === UITypes.SingleSelect) {
if (!optionTitles.includes(colBody.cdf)) {
NcError.badRequest(`Default value '${colBody.cdf}' is not a select option.`);
}
} else {
for (const cdf of colBody.cdf.split(',')) {
if (!optionTitles.includes(cdf)) {
NcError.badRequest(`Default value '${cdf}' is not a select option.`);
}
}
}
if (driverType === 'pg') {
colBody.cdf = `'${colBody.cdf}'`;
}
}
// Restrict duplicates
const titles = colBody.colOptions.options.map(el => el.title)
if (titles
@ -745,6 +763,21 @@ export async function columnUpdate(req: Request, res: Response<TableType>) {
op.title = op.title.replace(/^'/, '').replace(/'$/, '')
}
// Handle default values
if (colBody.cdf) {
if (driverType === 'mysql' || driverType === 'mysql2') {
} else if (driverType === 'pg') {
} else if (driverType === 'mssql') {
} else if (driverType === 'sqlite3') {
}
}
// Restrict duplicates
const titles = colBody.colOptions.options.map(el => el.title)
if (titles

Loading…
Cancel
Save