Table: JSON Cell should try to convert strings to JSON (#26024)

This commit is contained in:
Ryan McKinley 2020-07-03 01:23:32 -07:00 committed by GitHub
parent 634d8d60d6
commit 3acc2a6ac2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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'}>