CSV importing and exporting fixes (#8824)
Fixes issue https://github.com/twentyhq/twenty/issues/5793 (and duplicate https://github.com/twentyhq/twenty/issues/8822) - Fix importing multi-select and array fields. - Fix exporting and importing RAW_JSON fields. --------- Co-authored-by: ad-elias <elias@autodiligence.com>
This commit is contained in:
@ -11,28 +11,36 @@ export const useExportProcessRecordsForCSV = (objectNameSingular: string) => {
|
||||
});
|
||||
|
||||
const processRecordsForCSVExport = (records: ObjectRecord[]) => {
|
||||
return records.map((record) => {
|
||||
const currencyFields = objectMetadataItem.fields.filter(
|
||||
(field) => field.type === FieldMetadataType.Currency,
|
||||
);
|
||||
return records.map((record) =>
|
||||
objectMetadataItem.fields.reduce(
|
||||
(processedRecord, field) => {
|
||||
if (!isDefined(record[field.name])) {
|
||||
return processedRecord;
|
||||
}
|
||||
|
||||
const processedRecord = {
|
||||
...record,
|
||||
};
|
||||
|
||||
for (const currencyField of currencyFields) {
|
||||
if (isDefined(record[currencyField.name])) {
|
||||
processedRecord[currencyField.name] = {
|
||||
amountMicros: convertCurrencyMicrosToCurrencyAmount(
|
||||
record[currencyField.name].amountMicros,
|
||||
),
|
||||
currencyCode: record[currencyField.name].currencyCode,
|
||||
} satisfies FieldCurrencyValue;
|
||||
}
|
||||
}
|
||||
|
||||
return processedRecord;
|
||||
});
|
||||
switch (field.type) {
|
||||
case FieldMetadataType.Currency:
|
||||
return {
|
||||
...processedRecord,
|
||||
[field.name]: {
|
||||
amountMicros: convertCurrencyMicrosToCurrencyAmount(
|
||||
record[field.name].amountMicros,
|
||||
),
|
||||
currencyCode: record[field.name].currencyCode,
|
||||
} satisfies FieldCurrencyValue,
|
||||
};
|
||||
case FieldMetadataType.RawJson:
|
||||
return {
|
||||
...processedRecord,
|
||||
[field.name]: JSON.stringify(record[field.name]),
|
||||
};
|
||||
default:
|
||||
return processedRecord;
|
||||
}
|
||||
},
|
||||
{ ...record },
|
||||
),
|
||||
);
|
||||
};
|
||||
|
||||
return { processRecordsForCSVExport };
|
||||
|
||||
Reference in New Issue
Block a user