Skip to content

Commit c1a6eae

Browse files
authored
Fix field mapping when importing CSV (baserow#4521)
1 parent bedc1b4 commit c1a6eae

File tree

3 files changed

+24
-4
lines changed

3 files changed

+24
-4
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"type": "bug",
3+
"message": "Fix field mapping when importing CSV",
4+
"issue_origin": "github",
5+
"issue_number": 3259,
6+
"domain": "database",
7+
"bullet_points": [],
8+
"created_at": "2026-01-07"
9+
}

web-frontend/modules/database/components/table/ImportFileModal.vue

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@
9898
<SimpleGrid
9999
class="import-modal__preview"
100100
:rows="previewImportData"
101-
:fields="fields"
101+
:fields="sortedFields"
102102
/>
103103
</Tab>
104104
<Tab :title="$t('importFileModal.filePreview')">
@@ -245,6 +245,18 @@ export default {
245245
}
246246
},
247247
computed: {
248+
sortedFields() {
249+
// The sort needs to follow the same sort logic as
250+
// RowHandler.import_rows(...) in the backend
251+
return [...this.fields].sort((a, b) => {
252+
const aPrimary = !!a.primary
253+
const bPrimary = !!b.primary
254+
if (aPrimary !== bPrimary) return aPrimary ? -1 : 1
255+
const orderDiff = (a.order ?? 0) - (b.order ?? 0)
256+
if (orderDiff !== 0) return orderDiff
257+
return a.id - b.id
258+
})
259+
},
248260
isTableCreated() {
249261
if (!this.job?.table_id) {
250262
return false
@@ -281,7 +293,7 @@ export default {
281293
* All writable fields.
282294
*/
283295
writableFields() {
284-
return this.fields.filter((field) =>
296+
return this.sortedFields.filter((field) =>
285297
this.fieldTypes[field.type].canWriteFieldValues(field)
286298
)
287299
},
@@ -353,7 +365,7 @@ export default {
353365
},
354366
availableUpsertFields() {
355367
const selected = Object.values(this.mapping)
356-
return this.fields.filter((field) => {
368+
return this.sortedFields.filter((field) => {
357369
return (
358370
selected.includes(field.id) && this.fieldTypes[field.type].canUpsert()
359371
)

web-frontend/modules/database/store/field.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,6 @@ export const actions = {
264264
const fieldType = $registry.get('field', data.type)
265265
data = populateField(data, $registry)
266266

267-
commit('UPDATE_ITEM', { id: field.id, values: data })
268267
commit('UPDATE_ITEM', { id: field.id, values: data })
269268

270269
// The view might need to do some cleanup regarding the filters and sortings if the

0 commit comments

Comments
 (0)