diff --git a/public/app/features/logs/components/panel/LogLineDetails.test.tsx b/public/app/features/logs/components/panel/LogLineDetails.test.tsx index 0333a5cede3..a56166a2c9d 100644 --- a/public/app/features/logs/components/panel/LogLineDetails.test.tsx +++ b/public/app/features/logs/components/panel/LogLineDetails.test.tsx @@ -519,6 +519,36 @@ describe('LogLineDetails', () => { expect(onClickHideField).toHaveBeenCalledWith('key1'); }); + test('Renders JSON field values', async () => { + setup( + undefined, + { labels: { label1: 'value of label1', label2: '{"key1":"value1", "key2": "value2"}' } }, + { prettifyJSON: false } + ); + + expect(screen.getByText('label1')).toBeInTheDocument(); + expect(screen.getByText('value of label1')).toBeInTheDocument(); + expect(screen.getByText('label2')).toBeInTheDocument(); + expect(screen.getByText('{"key1":"value1", "key2": "value2"}')).toBeInTheDocument(); + }); + + test('Renders prettify JSON field values', async () => { + setup( + undefined, + { labels: { label1: 'value of label1', label2: '{"key1":"value1", "key2": "value2"}' } }, + { prettifyJSON: true } + ); + + expect(screen.getByText('label1')).toBeInTheDocument(); + expect(screen.getByText('value of label1')).toBeInTheDocument(); + expect(screen.getByText('label2')).toBeInTheDocument(); + expect(screen.queryByText('{"key1":"value1", "key2": "value2"}')).not.toBeInTheDocument(); + expect(screen.getByText(/key1/)).toBeInTheDocument(); + expect(screen.getByText(/value1/)).toBeInTheDocument(); + expect(screen.getByText(/key2/)).toBeInTheDocument(); + expect(screen.getByText(/value2/)).toBeInTheDocument(); + }); + test('Exposes buttons to reorder displayed fields', async () => { const setDisplayedFields = jest.fn(); const onClickHideField = jest.fn(); diff --git a/public/app/features/logs/components/panel/LogLineDetailsFields.tsx b/public/app/features/logs/components/panel/LogLineDetailsFields.tsx index 3a7d01d10ff..35fd1ff1dac 100644 --- a/public/app/features/logs/components/panel/LogLineDetailsFields.tsx +++ b/public/app/features/logs/components/panel/LogLineDetailsFields.tsx @@ -103,7 +103,7 @@ const getFieldsStyles = (theme: GrafanaTheme2) => ({ fieldsTable: css({ display: 'grid', gap: theme.spacing(1), - gridTemplateColumns: `${theme.spacing(11.5)} minmax(auto, 40%) 1fr`, + gridTemplateColumns: `${theme.spacing(11.5)} fit-content(30%) 1fr`, }), fieldsTableNoActions: css({ display: 'grid', @@ -148,7 +148,7 @@ export const LogLineDetailsField = ({ onClickHideField, onPinLine, pinLineButtonTooltipTitle, - syntaxHighlighting, + prettifyJSON, } = useLogListContext(); const styles = useStyles2(getFieldStyles); @@ -317,7 +317,7 @@ export const LogLineDetailsField = ({