mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Table: Cell inspector auto-detecting JSON (#81152)
* set inspect mode to json if no errors parsing json
This commit is contained in:
parent
a138ce668d
commit
a81d3b1d22
@ -14,9 +14,18 @@ interface TableCellInspectModalProps {
|
||||
export function TableCellInspectModal({ value, onDismiss, mode }: TableCellInspectModalProps) {
|
||||
let displayValue = value;
|
||||
if (isString(value)) {
|
||||
try {
|
||||
value = JSON.parse(value);
|
||||
} catch {} // ignore errors
|
||||
const trimmedValue = value.trim();
|
||||
// Exclude numeric strings like '123' from being displayed in code/JSON mode
|
||||
if (trimmedValue[0] === '{' || trimmedValue[0] === '[' || mode === 'code') {
|
||||
try {
|
||||
value = JSON.parse(value);
|
||||
mode = 'code';
|
||||
} catch {
|
||||
mode = 'text';
|
||||
} // ignore errors
|
||||
} else {
|
||||
mode = 'text';
|
||||
}
|
||||
} else {
|
||||
displayValue = JSON.stringify(value, null, ' ');
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user