@@ -52,7 +52,7 @@ export function useInstrumentVisualization({ params }: UseInstrumentVisualizatio
5252 }
5353 } ) ;
5454
55- const dl = ( option : 'CSV' | 'JSON' | 'TSV' ) => {
55+ const dl = ( option : 'CSV' | 'CSV Long' | ' JSON' | 'TSV' | 'TSV Long ') => {
5656 if ( ! instrument ) {
5757 notifications . addNotification ( { message : t ( 'errors.noInstrumentSelected' ) , type : 'error' } ) ;
5858 return ;
@@ -67,24 +67,26 @@ export function useInstrumentVisualization({ params }: UseInstrumentVisualizatio
6767
6868 const exportRecords = records . map ( ( record ) => omit ( record , [ '__time__' ] ) ) ;
6969
70+ const makeWideRows = ( ) => {
71+ const columnNames = Object . keys ( exportRecords [ 0 ] ! ) ;
72+ return exportRecords . map ( ( item ) => {
73+ const obj : { [ key : string ] : any } = { subjectId : params . subjectId } ;
74+ for ( const key of columnNames ) {
75+ const val = item [ key ] ;
76+ if ( key === '__date__' ) {
77+ obj . Date = toBasicISOString ( val as Date ) ;
78+ continue ;
79+ }
80+ obj [ key ] = typeof val === 'object' ? JSON . stringify ( val ) : val ;
81+ }
82+ return obj ;
83+ } ) ;
84+ } ;
85+
7086 switch ( option ) {
7187 case 'CSV' :
7288 void download ( `${ baseFilename } .csv` , ( ) => {
73- const columnNames = Object . keys ( exportRecords [ 0 ] ! ) ;
74-
75- const rows = exportRecords . map ( ( item ) => {
76- const obj : { [ key : string ] : any } = { } ;
77- obj . subjectId = params . subjectId ;
78- for ( const key of columnNames ) {
79- const val = item [ key ] ;
80- if ( key === '__date__' ) {
81- obj . Date = toBasicISOString ( val as Date ) ;
82- continue ;
83- }
84- obj [ key ] = typeof val === 'object' ? JSON . stringify ( val ) : val ;
85- }
86- return obj ;
87- } ) ;
89+ const rows = makeWideRows ( ) ;
8890
8991 const csv = unparse ( rows , {
9092 delimiter : ',' ,
@@ -107,21 +109,7 @@ export function useInstrumentVisualization({ params }: UseInstrumentVisualizatio
107109 }
108110 case 'TSV' :
109111 void download ( `${ baseFilename } .tsv` , ( ) => {
110- const columnNames = Object . keys ( exportRecords [ 0 ] ! ) ;
111-
112- const rows = exportRecords . map ( ( item ) => {
113- const obj : { [ key : string ] : any } = { } ;
114- obj . subjectId = params . subjectId ;
115- for ( const key of columnNames ) {
116- const val = item [ key ] ;
117- if ( key === '__date__' ) {
118- obj . Date = toBasicISOString ( val as Date ) ;
119- continue ;
120- }
121- obj [ key ] = typeof val === 'object' ? JSON . stringify ( val ) : val ;
122- }
123- return obj ;
124- } ) ;
112+ const rows = makeWideRows ( ) ;
125113
126114 const tsv = unparse ( rows , {
127115 delimiter : '\t' ,
0 commit comments