Browse Source

fix: use title as field name for import

pull/7092/head
mertmit 1 year ago
parent
commit
1340bd0806
  1. 9
      packages/nc-gui/components/template/Editor.vue
  2. 3
      packages/nc-gui/helpers/parsers/CSVTemplateAdapter.ts
  3. 5
      packages/nc-gui/helpers/parsers/ExcelTemplateAdapter.ts
  4. 2
      packages/nc-gui/helpers/parsers/JSONTemplateAdapter.ts

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

@ -131,7 +131,7 @@ const validators = computed(() =>
hasSelectColumn.value[tableIdx] = false
table.columns?.forEach((column, columnIdx) => {
acc[`tables.${tableIdx}.columns.${columnIdx}.column_name`] = [
acc[`tables.${tableIdx}.columns.${columnIdx}.title`] = [
fieldRequiredValidator(),
fieldLengthValidator(),
]
@ -252,6 +252,7 @@ function deleteTableColumn(tableIdx: number, columnKey: number) {
function addNewColumnRow(tableIdx: number, uidt: string) {
data.tables[tableIdx].columns.push({
key: data.tables[tableIdx].columns.length,
title: `title${data.tables[tableIdx].columns.length + 1}`,
column_name: `title${data.tables[tableIdx].columns.length + 1}`,
uidt,
})
@ -275,7 +276,7 @@ function remapColNames(batchData: any[], columns: ColumnType[]) {
// then only col.column_name exists in data, else col.ref_column_name
// for csv, col.column_name always exists in data
// since it streams the data in getData() with the updated col.column_name
const key = col.column_name in data ? col.column_name : col.ref_column_name
const key = col.title in data ? col.title : col.ref_column_name
let d = data[key]
if (col.uidt === UITypes.Date && d) {
let dateFormat
@ -295,7 +296,7 @@ function remapColNames(batchData: any[], columns: ColumnType[]) {
}
return {
...aggObj,
[col.column_name]: d,
[col.title]: d,
}
}, {}),
)
@ -901,7 +902,7 @@ watch(modelRef, async () => {
<template #bodyCell="{ column, record }">
<template v-if="column.key === 'column_name'">
<a-form-item v-bind="validateInfos[`tables.${tableIdx}.columns.${record.key}.${column.key}`]">
<a-input :ref="(el: HTMLInputElement) => (inputRefs[record.key] = el)" v-model:value="record.column_name" />
<a-input :ref="(el: HTMLInputElement) => (inputRefs[record.key] = el)" v-model:value="record.title" />
</a-form-item>
</template>

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

@ -58,6 +58,7 @@ export default class CSVTemplateAdapter {
this.tables[tableIdx] = []
for (const [columnIdx, columnName] of columnNames.entries()) {
let title = ((columnNameRowExist && columnName.toString().trim()) || `Field ${columnIdx + 1}`).trim()
let cn: string = ((columnNameRowExist && columnName.toString().trim()) || `field_${columnIdx + 1}`)
.replace(/[` ~!@#$%^&*()_|+\-=?;:'",.<>\{\}\[\]\\\/]/g, '_')
.trim()
@ -70,6 +71,7 @@ export default class CSVTemplateAdapter {
this.distinctValues[columnIdx] = new Set<string>()
this.columnValues[columnIdx] = []
tableObj.columns.push({
title,
column_name: cn,
ref_column_name: cn,
meta: {},
@ -325,6 +327,7 @@ export default class CSVTemplateAdapter {
}
getTemplate() {
console.log(this)
return this.base
}

5
packages/nc-gui/helpers/parsers/ExcelTemplateAdapter.ts

@ -113,6 +113,10 @@ export default class ExcelTemplateAdapter extends TemplateGenerator {
)
for (let col = 0; col < rows[0].length; col++) {
const title = (
(this.config.firstRowAsHeaders && rows[0] && rows[0][col] && rows[0][col].toString().trim()) ||
`Field ${col + 1}`
).trim()
let cn: string = (
(this.config.firstRowAsHeaders && rows[0] && rows[0][col] && rows[0][col].toString().trim()) ||
`field_${col + 1}`
@ -126,6 +130,7 @@ export default class ExcelTemplateAdapter extends TemplateGenerator {
columnNamePrefixRef[cn] = 0
const column: Record<string, any> = {
title,
column_name: cn,
ref_column_name: cn,
meta: {},

2
packages/nc-gui/helpers/parsers/JSONTemplateAdapter.ts

@ -90,8 +90,10 @@ export default class JSONTemplateAdapter extends TemplateGenerator {
columns.push(...normalizedNestedColumns)
}
} else {
const title = path.join(' ').trim()
const cn = path.join('_').replace(/\W/g, '_').trim()
const column: Record<string, any> = {
title,
column_name: cn,
ref_column_name: cn,
uidt: UITypes.SingleLineText,

Loading…
Cancel
Save