fix(CSV export): update the csv export format for multi-select and arrray fields to match the import template format (#16450)
Closes #16432 Multi-Select and Array fields were exported in an incompatible format: **Before**: {"0":"VALUE1","1":"VALUE2"} (object with numeric keys) **After**: ["VALUE1","VALUE2"] (JSON array) This prevented exported CSV files from being re-imported successfully. ### Changes Modified useExportProcessRecordsForCSV hook to stringify Multi-Select and Array fields as JSON arrays before CSV generation --------- Co-authored-by: Etienne <45695613+etiennejouan@users.noreply.github.com>
This commit is contained in:
+80
@@ -9,6 +9,8 @@ jest.mock('@/object-metadata/hooks/useObjectMetadataItem', () => ({
|
||||
fields: [
|
||||
{ type: FieldMetadataType.CURRENCY, name: 'price' },
|
||||
{ type: FieldMetadataType.TEXT, name: 'name' },
|
||||
{ type: FieldMetadataType.MULTI_SELECT, name: 'tags' },
|
||||
{ type: FieldMetadataType.ARRAY, name: 'skills' },
|
||||
],
|
||||
},
|
||||
})),
|
||||
@@ -56,4 +58,82 @@ describe('useExportProcessRecordsForCSV', () => {
|
||||
},
|
||||
]);
|
||||
});
|
||||
|
||||
it('processes records with multi-select and array fields correctly', () => {
|
||||
const { result } = renderHook(() =>
|
||||
useExportProcessRecordsForCSV('someObject'),
|
||||
);
|
||||
|
||||
const records = [
|
||||
{
|
||||
__typename: 'ObjectRecord',
|
||||
id: '1',
|
||||
tags: ['TAG1', 'TAG2'],
|
||||
skills: ['skill1', 'skill2', 'skill3'],
|
||||
name: 'Item 1',
|
||||
},
|
||||
{
|
||||
__typename: 'ObjectRecord',
|
||||
id: '2',
|
||||
tags: ['TAG3'],
|
||||
skills: ['skill4'],
|
||||
name: 'Item 2',
|
||||
},
|
||||
];
|
||||
|
||||
let processedRecords;
|
||||
|
||||
act(() => {
|
||||
processedRecords = result.current.processRecordsForCSVExport(records);
|
||||
});
|
||||
|
||||
expect(processedRecords).toEqual([
|
||||
{
|
||||
__typename: 'ObjectRecord',
|
||||
id: '1',
|
||||
tags: '["TAG1","TAG2"]',
|
||||
skills: '["skill1","skill2","skill3"]',
|
||||
name: 'Item 1',
|
||||
},
|
||||
{
|
||||
__typename: 'ObjectRecord',
|
||||
id: '2',
|
||||
tags: '["TAG3"]',
|
||||
skills: '["skill4"]',
|
||||
name: 'Item 2',
|
||||
},
|
||||
]);
|
||||
});
|
||||
|
||||
it('processes records with empty multi-select and array fields correctly', () => {
|
||||
const { result } = renderHook(() =>
|
||||
useExportProcessRecordsForCSV('someObject'),
|
||||
);
|
||||
|
||||
const records = [
|
||||
{
|
||||
__typename: 'ObjectRecord',
|
||||
id: '1',
|
||||
tags: [],
|
||||
skills: [],
|
||||
name: 'Item 1',
|
||||
},
|
||||
];
|
||||
|
||||
let processedRecords;
|
||||
|
||||
act(() => {
|
||||
processedRecords = result.current.processRecordsForCSVExport(records);
|
||||
});
|
||||
|
||||
expect(processedRecords).toEqual([
|
||||
{
|
||||
__typename: 'ObjectRecord',
|
||||
id: '1',
|
||||
tags: '[]',
|
||||
skills: '[]',
|
||||
name: 'Item 1',
|
||||
},
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
+2
@@ -29,6 +29,8 @@ export const useExportProcessRecordsForCSV = (objectNameSingular: string) => {
|
||||
currencyCode: record[field.name].currencyCode,
|
||||
} satisfies FieldCurrencyValue,
|
||||
};
|
||||
case FieldMetadataType.MULTI_SELECT:
|
||||
case FieldMetadataType.ARRAY:
|
||||
case FieldMetadataType.RAW_JSON:
|
||||
return {
|
||||
...processedRecord,
|
||||
|
||||
Reference in New Issue
Block a user