mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Table: JSON Cell should try to convert strings to JSON (#26024)
This commit is contained in:
parent
634d8d60d6
commit
3acc2a6ac2
@ -3,6 +3,7 @@ import { css, cx } from 'emotion';
|
||||
import { TableCellProps } from './types';
|
||||
import { Tooltip } from '../Tooltip/Tooltip';
|
||||
import { JSONFormatter } from '../JSONFormatter/JSONFormatter';
|
||||
import { isString } from 'lodash';
|
||||
|
||||
export const JSONViewCell: FC<TableCellProps> = props => {
|
||||
const { field, cell, tableStyles } = props;
|
||||
@ -16,8 +17,16 @@ export const JSONViewCell: FC<TableCellProps> = props => {
|
||||
font-family: monospace;
|
||||
`;
|
||||
|
||||
const displayValue = JSON.stringify(cell.value);
|
||||
const content = <JSONTooltip value={cell.value} />;
|
||||
let value = cell.value;
|
||||
let displayValue = value;
|
||||
if (isString(value)) {
|
||||
try {
|
||||
value = JSON.parse(value);
|
||||
} catch {} // ignore errors
|
||||
} else {
|
||||
displayValue = JSON.stringify(value);
|
||||
}
|
||||
const content = <JSONTooltip value={value} />;
|
||||
return (
|
||||
<div className={cx(txt, tableStyles.tableCell)}>
|
||||
<Tooltip placement="auto" content={content} theme={'info'}>
|
||||
|
Loading…
Reference in New Issue
Block a user