Browse Source

Merge pull request #6639 from nocodb/nc-fix/import-various

fix: import various
pull/6641/head
mertmit 1 year ago committed by GitHub
parent
commit
2f47d9434c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      packages/nc-gui/components/template/Editor.vue
  2. 1
      packages/nc-gui/helpers/parsers/CSVTemplateAdapter.ts
  3. 38
      packages/nocodb/src/modules/jobs/jobs/at-import/at-import.processor.ts

2
packages/nc-gui/components/template/Editor.vue

@ -434,7 +434,7 @@ async function importTemplate() {
let input = row[col.srcCn]
// parse potential boolean values
if (v.uidt === UITypes.Checkbox) {
input = input.replace(/["']/g, '').toLowerCase().trim()
input = input ? input.replace(/["']/g, '').toLowerCase().trim() : 'false'
if (input === 'false' || input === 'no' || input === 'n') {
input = '0'
} else if (input === 'true' || input === 'yes' || input === 'y') {

1
packages/nc-gui/helpers/parsers/CSVTemplateAdapter.ts

@ -224,7 +224,6 @@ export default class CSVTemplateAdapter {
const data = (row.data as [])[columnIdx] === '' ? null : (row.data as [])[columnIdx]
if (column.uidt === UITypes.Checkbox) {
rowData[column.column_name] = getCheckboxValue(data)
rowData[column.column_name] = data
} else if (column.uidt === UITypes.SingleSelect || column.uidt === UITypes.MultiSelect) {
rowData[column.column_name] = (data || '').toString().trim() || null
} else {

38
packages/nocodb/src/modules/jobs/jobs/at-import/at-import.processor.ts

@ -314,11 +314,11 @@ export class AtImportProcessor {
const nc_getSanitizedColumnName = (table, name) => {
let col_name = nc_sanitizeName(name);
// truncate to 60 chars if character if exceeds above 60
col_name = col_name?.slice(0, 60);
// truncate to 50 chars if character if exceeds above 50
col_name = col_name?.slice(0, 50);
// for knex, replace . with _
const col_alias = name.trim().replace(/\./g, '_');
let col_alias = name.trim().replace(/\./g, '_');
// check if already a column exists with same name?
const duplicateTitle = table.columns.find(
@ -327,14 +327,38 @@ export class AtImportProcessor {
const duplicateColumn = table.columns.find(
(x) => x.column_name?.toLowerCase() === col_name?.toLowerCase(),
);
if (duplicateTitle) {
if (enableErrorLogs) console.log(`## Duplicate title ${col_alias}`);
let tempAlias = col_alias;
let suffix = 1;
while (
table.columns.find(
(x) => x.title?.toLowerCase() === tempAlias?.toLowerCase(),
)
) {
tempAlias = col_alias;
tempAlias += `_${suffix++}`;
}
col_alias = tempAlias;
}
if (duplicateColumn) {
let tempName = col_name;
let suffix = 1;
while (
table.columns.find(
(x) => x.column_name?.toLowerCase() === tempName?.toLowerCase(),
)
) {
tempName = col_name;
tempName += `_${suffix++}`;
}
col_name = tempName;
}
return {
// kludge: error observed in Nc with space around column-name
title: col_alias + (duplicateTitle ? '_2' : ''),
column_name: col_name + (duplicateColumn ? '_2' : ''),
title: col_alias,
column_name: col_name,
};
};

Loading…
Cancel
Save