11import { useMemo } from 'react' ;
2+ import { flatten } from 'flat' ;
23import type { ResponseJSON } from '@hyperdx/common-utils/dist/clickhouse' ;
34import { SourceKind , TSource } from '@hyperdx/common-utils/dist/types' ;
45import { Box } from '@mantine/core' ;
@@ -23,7 +24,7 @@ export function useRowData({
2324 const severityTextExpr =
2425 source . severityTextExpression || source . statusCodeExpression ;
2526
26- return useQueriedChartConfig (
27+ const queryResult = useQueriedChartConfig (
2728 {
2829 connection : source . connection ,
2930 select : [
@@ -112,6 +113,36 @@ export function useRowData({
112113 enabled : rowId != null ,
113114 } ,
114115 ) ;
116+
117+ // Normalize resource and event attributes to always use flat keys for both JSON and Map columns
118+ const normalizedData = useMemo ( ( ) => {
119+ if ( ! queryResult . data ?. data ?. [ 0 ] ) {
120+ return queryResult . data ;
121+ }
122+
123+ const row = queryResult . data . data [ 0 ] ;
124+ const normalizedRow = { ...row } ;
125+
126+ if ( row . __hdx_resource_attributes ) {
127+ normalizedRow . __hdx_resource_attributes = flatten (
128+ row . __hdx_resource_attributes ,
129+ ) ;
130+ }
131+
132+ if ( row . __hdx_event_attributes ) {
133+ normalizedRow . __hdx_event_attributes = flatten ( row . __hdx_event_attributes ) ;
134+ }
135+
136+ return {
137+ ...queryResult . data ,
138+ data : [ normalizedRow ] ,
139+ } ;
140+ } , [ queryResult . data ] ) ;
141+
142+ return {
143+ ...queryResult ,
144+ data : normalizedData ,
145+ } ;
115146}
116147
117148export function getJSONColumnNames ( meta : ResponseJSON [ 'meta' ] | undefined ) {
0 commit comments