diff --git a/public/app/features/explore/utils/logs.ts b/public/app/features/explore/utils/logs.ts index 5263867039a..d156da0c080 100644 --- a/public/app/features/explore/utils/logs.ts +++ b/public/app/features/explore/utils/logs.ts @@ -4,4 +4,5 @@ export const SETTINGS_KEYS = { wrapLogMessage: 'grafana.explore.logs.wrapLogMessage', prettifyLogMessage: 'grafana.explore.logs.prettifyLogMessage', logsSortOrder: 'grafana.explore.logs.sortOrder', + logContextWrapLogMessage: 'grafana.explore.logs.logContext.wrapLogMessage', }; diff --git a/public/app/features/logs/components/log-context/LogContextButtons.tsx b/public/app/features/logs/components/log-context/LogContextButtons.tsx index d9c6b419480..a7db0994b75 100644 --- a/public/app/features/logs/components/log-context/LogContextButtons.tsx +++ b/public/app/features/logs/components/log-context/LogContextButtons.tsx @@ -1,12 +1,13 @@ import { css } from '@emotion/css'; -import React from 'react'; +import React, { useCallback } from 'react'; import { SelectableValue } from '@grafana/data'; -import { ButtonGroup, ButtonSelect, useStyles2 } from '@grafana/ui'; +import { reportInteraction } from '@grafana/runtime'; +import { ButtonGroup, ButtonSelect, InlineField, InlineFieldRow, InlineSwitch, useStyles2 } from '@grafana/ui'; const getStyles = () => { return { - logSamplesButton: css` + buttonGroup: css` display: inline-flex; `, }; @@ -24,14 +25,36 @@ export type Props = { option: SelectableValue; onChangeOption: (item: SelectableValue) => void; position?: 'top' | 'bottom'; + + wrapLines?: boolean; + onChangeWrapLines?: (wrapLines: boolean) => void; }; export const LogContextButtons = (props: Props) => { - const { option, onChangeOption } = props; + const { option, onChangeOption, wrapLines, onChangeWrapLines, position } = props; + const internalOnChangeWrapLines = useCallback( + (event: React.FormEvent) => { + if (onChangeWrapLines) { + const state = event.currentTarget.checked; + reportInteraction('grafana_explore_logs_log_context_toggle_lines_clicked', { + state, + }); + onChangeWrapLines(state); + } + }, + [onChangeWrapLines] + ); const styles = useStyles2(getStyles); return ( - + + {position === 'top' && onChangeWrapLines && ( + + + + + + )} ); diff --git a/public/app/features/logs/components/log-context/LogRowContextModal.test.tsx b/public/app/features/logs/components/log-context/LogRowContextModal.test.tsx index 5a4e6e2e5be..6161d600cd2 100644 --- a/public/app/features/logs/components/log-context/LogRowContextModal.test.tsx +++ b/public/app/features/logs/components/log-context/LogRowContextModal.test.tsx @@ -114,7 +114,7 @@ describe('LogRowContextModal', () => { await waitFor(() => expect(getRowContext).toHaveBeenCalledTimes(2)); const tenLinesButton = screen.getByRole('button', { - name: /10 lines/i, + name: /50 lines/i, }); await userEvent.click(tenLinesButton); const twentyLinesButton = screen.getByRole('menuitemradio', { diff --git a/public/app/features/logs/components/log-context/LogRowContextModal.tsx b/public/app/features/logs/components/log-context/LogRowContextModal.tsx index 4f30b7e1657..bcfec8fe92b 100644 --- a/public/app/features/logs/components/log-context/LogRowContextModal.tsx +++ b/public/app/features/logs/components/log-context/LogRowContextModal.tsx @@ -142,10 +142,15 @@ export const LogRowContextModal: React.FunctionComponent({ after: [], before: [] }); - const [limit, setLimit] = useState(LoadMoreOptions[0].value!); + // LoadMoreOptions[2] refers to 50 lines + const defaultLimit = LoadMoreOptions[2]; + const [limit, setLimit] = useState(defaultLimit.value!); const [loadingWidth, setLoadingWidth] = useState(0); - const [loadMoreOption, setLoadMoreOption] = useState>(LoadMoreOptions[0]); + const [loadMoreOption, setLoadMoreOption] = useState>(defaultLimit); const [contextQuery, setContextQuery] = useState(null); + const [wrapLines, setWrapLines] = useState( + store.getBool(SETTINGS_KEYS.logContextWrapLogMessage, store.getBool(SETTINGS_KEYS.wrapLogMessage, true)) + ); const getFullTimeRange = useCallback(() => { const { before, after } = context; @@ -265,7 +270,13 @@ export const LogRowContextModal: React.FunctionComponent
- +
@@ -281,7 +292,7 @@ export const LogRowContextModal: React.FunctionComponent