Explore: fix object value parsing for downloading traces as csv (#44492)

* Explore: fix object value parsing for downloading traces as csv

Signed-off-by: tharun <rajendrantharun@live.com>

* add replacer function to fix circular objects

Signed-off-by: tharun <rajendrantharun@live.com>
pull/45821/head
Tharun Rajendran 3 years ago committed by GitHub
parent 85af6d2718
commit 0a572cae4b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      packages/grafana-data/src/field/displayProcessor.test.ts
  2. 16
      packages/grafana-data/src/field/displayProcessor.ts

@ -460,7 +460,7 @@ describe('getRawDisplayProcessor', () => {
${'a string'} | ${'a string'}
${null} | ${'null'}
${undefined} | ${'undefined'}
${{ value: 0, label: 'a label' }} | ${'[object Object]'}
${{ value: 0, label: 'a label' }} | ${'{"value":0,"label":"a label"}'}
`('when called with value:{$value}', ({ value, expected }) => {
const result = processor(value);

@ -11,6 +11,7 @@ import { KeyValue, TimeZone } from '../types';
import { getScaleCalculator } from './scale';
import { GrafanaTheme2 } from '../themes/types';
import { anyToNumber } from '../utils/anyToNumber';
import { getFieldTypeFromValue } from '../dataframe/processDataFrame';
interface DisplayProcessorOptions {
field: Partial<Field>;
@ -168,7 +169,20 @@ function toStringProcessor(value: any): DisplayValue {
export function getRawDisplayProcessor(): DisplayProcessor {
return (value: any) => ({
text: `${value}`,
text: getFieldTypeFromValue(value) === 'other' ? `${JSON.stringify(value, getCircularReplacer())}` : `${value}`,
numeric: null as unknown as number,
});
}
const getCircularReplacer = () => {
const seen = new WeakSet();
return (_key: any, value: object | null) => {
if (typeof value === 'object' && value !== null) {
if (seen.has(value)) {
return;
}
seen.add(value);
}
return value;
};
};

Loading…
Cancel
Save