Logs: Cell format value on inspect should use Code view for arrays, objects, and JSON strings (#115037)

This commit is contained in:
Liza Detrick
2025-12-19 19:52:02 +01:00
committed by GitHub
parent 471d6f5236
commit 14c595f206
@@ -1,3 +1,4 @@
import { isPlainObject } from 'lodash';
import { useCallback } from 'react';
import * as React from 'react';
@@ -63,7 +64,18 @@ export function CellActions({
tooltip={t('grafana-ui.table.cell-inspect', 'Inspect value')}
onClick={() => {
if (setInspectCell) {
setInspectCell({ value: cell.value, mode: previewMode });
let mode = TableCellInspectorMode.text;
let inspectValue = cell.value;
try {
const parsed = typeof inspectValue === 'string' ? JSON.parse(inspectValue) : inspectValue;
if (Array.isArray(parsed) || isPlainObject(parsed)) {
inspectValue = JSON.stringify(parsed, null, 2);
mode = TableCellInspectorMode.code;
}
} catch {
// do nothing
}
setInspectCell({ value: inspectValue, mode });
}
}}
{...commonButtonProps}