@ -145,7 +145,11 @@ 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 } .title ` ] = [ fieldRequiredValidator ( ) , fieldLengthValidator ( ) ]
acc [ ` tables. ${ tableIdx } .columns. ${ columnIdx } .title ` ] = [
fieldRequiredValidator ( ) ,
fieldLengthValidator ( ) ,
reservedFieldNameValidator ( ) ,
]
acc [ ` tables. ${ tableIdx } .columns. ${ columnIdx } .uidt ` ] = [ fieldRequiredValidator ( ) ]
acc [ ` tables. ${ tableIdx } .columns. ${ columnIdx } .uidt ` ] = [ fieldRequiredValidator ( ) ]
if ( isSelect ( column ) ) {
if ( isSelect ( column ) ) {
hasSelectColumn . value [ tableIdx ] = true
hasSelectColumn . value [ tableIdx ] = true
@ -237,6 +241,10 @@ function parseTemplate({ tables = [], ...rest }: Props['baseTemplate']) {
... rest ,
... rest ,
columns : [
columns : [
... columns . map ( ( c : any , idx : number ) => {
... columns . map ( ( c : any , idx : number ) => {
if ( ! importDataOnly && c . column _name ? . toLowerCase ( ) === 'id' ) {
const cn = populateUniqueColumnName ( 'id' , [ ] , columns )
c . column _name = cn
}
c . key = idx
c . key = idx
return c
return c
} ) ,
} ) ,
@ -282,6 +290,9 @@ function remapColNames(batchData: any[], columns: ColumnType[]) {
const dateFormatMap : Record < number , string > = { }
const dateFormatMap : Record < number , string > = { }
return batchData . map ( ( data ) =>
return batchData . map ( ( data ) =>
( columns || [ ] ) . reduce ( ( aggObj , col : Record < string , any > ) => {
( columns || [ ] ) . reduce ( ( aggObj , col : Record < string , any > ) => {
/ / w e r e n a m i n g e x i s t i n g i d c o l u m n a n d u s i n g o u r o w n a u t o i n c r e m e n t i d
if ( col . uidt === UITypes . ID ) return aggObj
/ / f o r e x c e l & j s o n , i f t h e c o l u m n n a m e i s c h a n g e d i n T e m p l a t e E d i t o r ,
/ / f o r e x c e l & j s o n , i f t h e c o l u m n n a m e i s c h a n g e d i n T e m p l a t e E d i t o r ,
/ / t h e n o n l y c o l . c o l u m n _ n a m e e x i s t s i n d a t a , e l s e c o l . r e f _ c o l u m n _ n a m e
/ / t h e n o n l y c o l . c o l u m n _ n a m e e x i s t s i n d a t a , e l s e c o l . r e f _ c o l u m n _ n a m e
/ / f o r c s v , c o l . c o l u m n _ n a m e a l w a y s e x i s t s i n d a t a
/ / f o r c s v , c o l . c o l u m n _ n a m e a l w a y s e x i s t s i n d a t a
@ -570,6 +581,7 @@ async function importTemplate() {
await $api . dbTableColumn . primaryColumnSet ( createdTable . columns [ 0 ] . id as string )
await $api . dbTableColumn . primaryColumnSet ( createdTable . columns [ 0 ] . id as string )
}
}
}
}
/ / b u l k i n s e r t d a t a
/ / b u l k i n s e r t d a t a
if ( importData ) {
if ( importData ) {
const offset = maxRowsToParse
const offset = maxRowsToParse
@ -623,7 +635,7 @@ function mapDefaultColumns() {
srcDestMapping . value = { }
srcDestMapping . value = { }
for ( let i = 0 ; i < data . tables . length ; i ++ ) {
for ( let i = 0 ; i < data . tables . length ; i ++ ) {
for ( const col of importColumns [ i ] ) {
for ( const col of importColumns [ i ] ) {
const o = { srcCn : col . column _name , destCn : '' , enabled : true }
const o = { srcCn : col . column _name , srcTitle : col . title , destCn : '' , enabled : true }
if ( columns . value ) {
if ( columns . value ) {
const tableColumn = columns . value . find ( ( c ) => c . column _name === col . column _name )
const tableColumn = columns . value . find ( ( c ) => c . column _name === col . column _name )
if ( tableColumn ) {
if ( tableColumn ) {
@ -712,6 +724,20 @@ const setErrorState = (errorsFields: any[]) => {
formError . value = errorMap
formError . value = errorMap
}
}
function populateUniqueColumnName ( cn : string , draftCn : string [ ] = [ ] , columns : ColumnType [ ] ) {
let c = 2
let columnName = ` ${ cn } ${ 1 } `
while (
draftCn . includes ( columnName ) ||
columns ? . some ( ( c ) => {
return c . column _name === columnName || c . title === columnName
} )
) {
columnName = ` ${ cn } ${ c ++ } `
}
return columnName
}
watch ( formRef , ( ) => {
watch ( formRef , ( ) => {
setTimeout ( async ( ) => {
setTimeout ( async ( ) => {
try {
try {
@ -801,8 +827,8 @@ watch(modelRef, async () => {
< template # bodyCell = "{ column, record }" >
< template # bodyCell = "{ column, record }" >
< template v-if ="column.key === 'source_column'" >
< template v-if ="column.key === 'source_column'" >
< NcTooltip class = "truncate inline-block" >
< NcTooltip class = "truncate inline-block" >
< template # title > { { record . srcCn } } < / template >
< template # title > { { record . srcTitle } } < / template >
{ { record . srcCn } }
{ { record . srcTitle } }
< / NcTooltip >
< / NcTooltip >
< / template >
< / template >
@ -917,17 +943,29 @@ 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}.title`]"
class = "nc-table-field-name"
>
< a -input
< a -input
: ref = "(el: HTMLInputElement) => (inputRefs[record.key] = el)"
: ref = "(el: HTMLInputElement) => (inputRefs[record.key] = el)"
v - model : value = "record.title"
v - model : value = "record.title"
class = "!rounded-md"
class = "!rounded-md"
/ >
>
< template # suffix >
< NcTooltip v-if ="formError?.[`tables.${tableIdx}.columns.${record.key}.title`]" class="flex" >
< template # title
> { { formError ? . [ ` tables. ${ tableIdx } .columns. ${ record . key } .title ` ] . join ( '\n' ) } }
< / template >
< GeneralIcon icon = "info" class = "h-4 w-4 text-red-500 flex-none" / >
< / NcTooltip >
< / template >
< / a - i n p u t >
< / a - f o r m - i t e m >
< / a - f o r m - i t e m >
< / template >
< / template >
< template v -else -if = " column.key = = = ' uidt ' " >
< template v -else -if = " column.key = = = ' uidt ' " >
< a -form -item v-bind ="validateInfos[`tables.${tableIdx}.columns.${record.key}.${column.key}`]" >
< a -form -item v-bind ="validateInfos[`tables.${tableIdx}.columns.${record.key}.uidt `]" >
< NcTooltip :disabled ="importDataOnly" >
< NcTooltip :disabled ="importDataOnly" >
< template # title >
< template # title >
{ { $t ( 'tooltip.useFieldEditMenuToConfigFieldType' ) } }
{ { $t ( 'tooltip.useFieldEditMenuToConfigFieldType' ) } }
@ -1014,4 +1052,9 @@ watch(modelRef, async () => {
@ apply flex ;
@ apply flex ;
}
}
}
}
. nc - table - field - name {
: deep ( . ant - form - item - explain ) {
@ apply hidden ;
}
}
< / style >
< / style >