@@ -14,19 +14,28 @@ const flattenObject = (obj, parentKey = "") => {
1414 const fullKey = parentKey ? `${ parentKey } .${ key } ` : key ;
1515 if ( typeof obj [ key ] === "object" && obj [ key ] !== null && ! Array . isArray ( obj [ key ] ) ) {
1616 Object . assign ( flattened , flattenObject ( obj [ key ] , fullKey ) ) ;
17+ } else if ( Array . isArray ( obj [ key ] ) && typeof obj [ key ] [ 0 ] === "string" ) {
18+ flattened [ fullKey ] = obj [ key ] ;
1719 } else if ( Array . isArray ( obj [ key ] ) ) {
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 ) ] )
20+ let testFormatting = getCippFormatting ( obj [ key ] , key , "text" , false , false ) ;
21+ if ( typeof testFormatting === "string" && ! testFormatting . includes ( "[object Object]" ) ) {
22+ flattened [ fullKey ] = testFormatting ;
23+ } else {
24+ flattened [ fullKey ] = obj [ key ]
25+ . map ( ( item ) =>
26+ typeof item === "object"
27+ ? JSON . stringify (
28+ Object . fromEntries (
29+ Object . entries ( flattenObject ( item ) ) . map ( ( [ k , v ] ) => [
30+ k ,
31+ getCippFormatting ( v , k , "text" , false ) ,
32+ ] )
33+ )
2534 )
26- )
27- : getCippFormatting ( item , fullKey , "text" , false )
28- )
29- . join ( ", " ) ;
35+ : getCippFormatting ( item , fullKey , "text" , false , false )
36+ )
37+ . join ( ", " ) ;
38+ }
3039 } else {
3140 flattened [ fullKey ] = obj [ key ] ;
3241 }
@@ -57,6 +66,12 @@ export const CSVExportButton = (props) => {
5766 const formattedRow = { } ;
5867 columnKeys . forEach ( ( key ) => {
5968 const value = row [ key ] ;
69+ // check for string and do not format
70+ if ( typeof value === "string" ) {
71+ formattedRow [ key ] = value ;
72+ return ;
73+ }
74+
6075 // Pass flattened data to the formatter for CSV export
6176 formattedRow [ key ] = getCippFormatting ( value , key , "text" , false ) ;
6277 } ) ;
0 commit comments