Skip to content

Commit 50b6afb

Browse files
fix(tabular-editor): disable nested-field parsing (#1164)
Replace the watch([tableRef, schemaFields]) + initializeTable() combo with a self-stopping watchEffect that initializes the Tabulator table exactly once. PapaParse warnings (e.g. ragged rows) are now logged as warning: the parsed data is still loaded into the table. Only the PapaParse error callback or a synchronous exception falls back to an empty table. Disable Tabulator's nestedFieldSeparator so schema field names containing dots (e.g. note_c2.1) are treated as flat keys. Without this, Tabulator tries to traverse dotted field names as object paths and can throw "Cannot assign to read only property" when the parent value is a primitive string.
1 parent c4ac40d commit 50b6afb

1 file changed

Lines changed: 42 additions & 38 deletions

File tree

‎components/Datasets/TabularEditor.client.vue‎

Lines changed: 42 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -327,47 +327,17 @@ async function validateData() {
327327
}
328328
}
329329
330-
async function initializeTable() {
331-
await nextTick()
332-
333-
if (!tableRef.value) {
334-
console.error('tableRef.value est null')
335-
return
336-
}
337-
let tableData: RowData[] = []
338-
if (uploadedFile.value) {
339-
try {
340-
paparse.parse<RowData, File>(uploadedFile.value, {
341-
header: true,
342-
complete: function (results) {
343-
tableData = results.data.map((r, i) => {
344-
return { id: i, ...r }
345-
})
346-
makeTable(tableData, true)
347-
uploadedFile.value = null
348-
},
349-
})
350-
}
351-
catch (error) {
352-
console.error('Erreur lors du chargement du fichier:', error)
353-
customErrors.value = [t('Erreur lors du chargement du fichier CSV')]
354-
tableData = createEmptyRows(1)
355-
makeTable(tableData)
356-
}
357-
}
358-
else {
359-
tableData = createEmptyRows(1)
360-
makeTable(tableData)
361-
}
362-
}
363-
364330
async function makeTable(data: Array<RowData>, shouldValidate = false) {
365331
if (!tableRef.value) {
366332
return
367333
}
334+
335+
table?.destroy()
336+
368337
table = new Tabulator(tableRef.value, {
369338
data: data,
370339
layout: 'fitData',
340+
nestedFieldSeparator: false,
371341
columns: getColumns(),
372342
rowContextMenu: [
373343
{
@@ -518,11 +488,45 @@ function generateFile() {
518488
519489
defineExpose({ generateFile })
520490
521-
watch([tableRef, schemaFields], () => {
522-
if (tableRef.value && schemaFields.value.length > 0) {
523-
initializeTable()
491+
const stopInit = watchEffect(() => {
492+
if (!tableRef.value || schemaFields.value.length === 0) return
493+
494+
stopInit()
495+
496+
if (uploadedFile.value) {
497+
let handled = false
498+
try {
499+
paparse.parse<RowData, File>(uploadedFile.value, {
500+
header: true,
501+
complete: (results) => {
502+
if (handled) return
503+
if (results.errors.length > 0) {
504+
console.warn('PapaParse a rencontré des avertissements:', results.errors)
505+
}
506+
const tableData = results.data.map((r, i) => ({ id: i, ...r }))
507+
makeTable(tableData, true)
508+
},
509+
error: (error) => {
510+
if (handled) return
511+
handled = true
512+
console.error('Erreur lors du chargement du fichier:', error)
513+
customErrors.value = [t('Erreur lors du chargement du fichier CSV')]
514+
makeTable(createEmptyRows(1))
515+
},
516+
})
517+
}
518+
catch (error) {
519+
if (handled) return
520+
handled = true
521+
console.error('Erreur lors du chargement du fichier:', error)
522+
customErrors.value = [t('Erreur lors du chargement du fichier CSV')]
523+
makeTable(createEmptyRows(1))
524+
}
525+
}
526+
else {
527+
makeTable(createEmptyRows(1))
524528
}
525-
}, { immediate: true })
529+
}, { flush: 'post' })
526530
527531
watch(validationReport, () => {
528532
if (validationReport.value && !validationReport.value.report?.valid && validationReport.value.report?.errors) {

0 commit comments

Comments
 (0)