mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
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>
This commit is contained in:
parent
85af6d2718
commit
0a572cae4b
@ -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…
Reference in New Issue
Block a user