@@ -36,13 +36,11 @@ export function useInstrumentVisualization({ params }: UseInstrumentVisualizatio
3636 const [ minDate , setMinDate ] = useState < Date | null > ( null ) ;
3737 const [ instrumentId , setInstrumentId ] = useState < null | string > ( null ) ;
3838
39- function splitFirstDollar ( str : string ) {
40- const match = / ^ ( .* ?) \$ ( .* ) $ / . exec ( str ) ;
41- if ( ! match ) {
42- return [ str , str ] ;
43- }
44- const [ , before , after ] = match ;
45- return [ before , after ] ;
39+ function afterFirstDollar ( str : string ) {
40+ const match = / \$ ( .* ) / . exec ( str ) ;
41+ if ( ! match ) return str ;
42+ if ( ! match [ 1 ] ) return str ;
43+ return match [ 1 ] ;
4644 }
4745
4846 const instrument = useInstrument ( instrumentId ) as AnyUnilingualScalarInstrument ;
@@ -80,8 +78,8 @@ export function useInstrumentVisualization({ params }: UseInstrumentVisualizatio
8078 const columnNames = Object . keys ( exportRecords [ 0 ] ! ) ;
8179 return exportRecords . map ( ( item ) => {
8280 const obj : { [ key : string ] : any } = {
83- GroupID : splitFirstDollar ( params . subjectId ) [ 0 ] ,
84- subjectId : splitFirstDollar ( params . subjectId ) [ 1 ]
81+ GroupID : currentGroup ? currentGroup . id : 'root' ,
82+ subjectId : afterFirstDollar ( params . subjectId )
8583 } ;
8684 for ( const key of columnNames ) {
8785 const val = item [ key ] ;
@@ -111,10 +109,10 @@ export function useInstrumentVisualization({ params }: UseInstrumentVisualizatio
111109 objVal . forEach ( ( arrayItem ) => {
112110 Object . entries ( arrayItem as object ) . forEach ( ( [ arrKey , arrItem ] ) => {
113111 longRecord . push ( {
114- GroupID : splitFirstDollar ( params . subjectId ) [ 0 ] ,
112+ GroupID : currentGroup ? currentGroup . id : 'root' ,
115113 // eslint-disable-next-line perfectionist/sort-objects
116114 Date : toBasicISOString ( date ) ,
117- SubjectID : splitFirstDollar ( params . subjectId ) [ 1 ] ,
115+ SubjectID : afterFirstDollar ( params . subjectId ) ,
118116 Variable : `${ objKey } -${ arrKey } ` ,
119117 // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, perfectionist/sort-objects
120118 Value : arrItem
@@ -123,10 +121,10 @@ export function useInstrumentVisualization({ params }: UseInstrumentVisualizatio
123121 } ) ;
124122 } else {
125123 longRecord . push ( {
126- GroupID : splitFirstDollar ( params . subjectId ) [ 0 ] ,
124+ GroupID : currentGroup ? currentGroup . id : 'root' ,
127125 // eslint-disable-next-line perfectionist/sort-objects
128126 Date : toBasicISOString ( date ) ,
129- SubjectID : splitFirstDollar ( params . subjectId ) [ 1 ] ,
127+ SubjectID : afterFirstDollar ( params . subjectId ) ,
130128 Value : objVal ,
131129 Variable : objKey
132130 } ) ;
0 commit comments