@@ -15,13 +15,18 @@ const flattenObject = (obj, parentKey = "") => {
15
15
if ( typeof obj [ key ] === "object" && obj [ key ] !== null && ! Array . isArray ( obj [ key ] ) ) {
16
16
Object . assign ( flattened , flattenObject ( obj [ key ] , fullKey ) ) ;
17
17
} else if ( Array . isArray ( obj [ key ] ) ) {
18
- obj [ key ] . forEach ( ( item , index ) => {
19
- if ( typeof item === "object" && item !== null ) {
20
- Object . assign ( flattened , flattenObject ( item , `${ fullKey } [${ index } ]` ) ) ;
21
- } else {
22
- flattened [ `${ fullKey } [${ index } ]` ] = item ;
23
- }
24
- } ) ;
18
+ // Handle arrays of objects by applying the formatter on each property
19
+ flattened [ fullKey ] = obj [ key ]
20
+ . map ( ( item ) =>
21
+ typeof item === "object"
22
+ ? JSON . stringify (
23
+ Object . fromEntries (
24
+ Object . entries ( flattenObject ( item ) ) . map ( ( [ k , v ] ) => [ k , getCippFormatting ( v , k , "text" , false ) ] )
25
+ )
26
+ )
27
+ : getCippFormatting ( item , fullKey , "text" , false )
28
+ )
29
+ . join ( ", " ) ;
25
30
} else {
26
31
flattened [ fullKey ] = obj [ key ] ;
27
32
}
@@ -52,6 +57,7 @@ export const CSVExportButton = (props) => {
52
57
const formattedRow = { } ;
53
58
columnKeys . forEach ( ( key ) => {
54
59
const value = row [ key ] ;
60
+ // Pass flattened data to the formatter for CSV export
55
61
formattedRow [ key ] = getCippFormatting ( value , key , "text" , false ) ;
56
62
} ) ;
57
63
return formattedRow ;
0 commit comments