Browse Source

fix: use title as field name for import

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

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

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

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

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

Loading…
Cancel
Save