From a02f9be0c673963ca56339a6cf65152b5d81d462 Mon Sep 17 00:00:00 2001 From: Ivana Huckova <30407135+ivanahuckova@users.noreply.github.com> Date: Tue, 10 Aug 2021 03:01:57 -0400 Subject: [PATCH] Explore: Fix showing of full log context (#37442) * Fix log context * Update to auto values insted of unset * Update comment * Fix redundant left margin for non-wrapped logs * Remove unused css styling * Adjust width and height --- .../src/components/Logs/LogRowContext.tsx | 51 ++++++++++++++----- .../src/components/Logs/LogRowMessage.tsx | 14 ++++- .../src/components/Logs/getLogRowStyles.ts | 3 +- public/app/features/explore/Logs.tsx | 7 +-- 4 files changed, 55 insertions(+), 20 deletions(-) diff --git a/packages/grafana-ui/src/components/Logs/LogRowContext.tsx b/packages/grafana-ui/src/components/Logs/LogRowContext.tsx index 0f1981f4cfa..f5f2a38667d 100644 --- a/packages/grafana-ui/src/components/Logs/LogRowContext.tsx +++ b/packages/grafana-ui/src/components/Logs/LogRowContext.tsx @@ -4,7 +4,7 @@ import { css, cx } from '@emotion/css'; import { Alert } from '../Alert/Alert'; import { LogRowContextRows, LogRowContextQueryErrors, HasMoreContextRows } from './LogRowContextProvider'; -import { useStyles } from '../../themes/ThemeContext'; +import { useStyles, useTheme } from '../../themes/ThemeContext'; import { CustomScrollbar } from '../CustomScrollbar/CustomScrollbar'; import { List } from '../List/List'; import { ClickOutsideWrapper } from '../ClickOutsideWrapper/ClickOutsideWrapper'; @@ -13,18 +13,41 @@ import { LogMessageAnsi } from './LogMessageAnsi'; interface LogRowContextProps { row: LogRowModel; context: LogRowContextRows; + wrapLogMessage: boolean; errors?: LogRowContextQueryErrors; hasMoreContextRows?: HasMoreContextRows; onOutsideClick: () => void; onLoadMoreContext: () => void; } -const getLogRowContextStyles = (theme: GrafanaTheme) => { +const getLogRowContextStyles = (theme: GrafanaTheme, wrapLogMessage?: boolean) => { + /** + * This is workaround for displaying uncropped context when we have unwrapping log messages. + * We are using margins to correctly position context. Because non-wrapped logs have always 1 line of log + * and 1 line of Show/Hide context switch. Therefore correct position can be reliably achieved by margins. + * We also adjust width to 75%. + */ + + const afterContext = wrapLogMessage + ? css` + top: -250px; + ` + : css` + margin-top: -250px; + width: 75%; + `; + + const beforeContext = wrapLogMessage + ? css` + top: 100%; + ` + : css` + margin-top: 40px; + width: 75%; + `; return { commonStyles: css` position: absolute; - width: calc(100% + 20px); - left: -13px; height: 250px; z-index: ${theme.zIndex.dropdown}; overflow: hidden; @@ -32,6 +55,7 @@ const getLogRowContextStyles = (theme: GrafanaTheme) => { box-shadow: 0 0 10px ${theme.colors.dropdownShadow}; border: 1px solid ${theme.colors.bg2}; border-radius: ${theme.border.radius.md}; + width: 100%; `, header: css` height: 30px; @@ -44,6 +68,8 @@ const getLogRowContextStyles = (theme: GrafanaTheme) => { height: 220px; padding: 10px; `, + afterContext, + beforeContext, }; }; @@ -56,7 +82,7 @@ interface LogRowContextGroupHeaderProps { } interface LogRowContextGroupProps extends LogRowContextGroupHeaderProps { rows: Array; - className: string; + className?: string; error?: string; } @@ -122,11 +148,11 @@ export const LogRowContextGroup: React.FunctionComponent +
{/* When displaying "after" context */} {shouldScrollToBottom && !error && }
- +
{!error && ( = ({ onOutsideClick, onLoadMoreContext, hasMoreContextRows, + wrapLogMessage, }) => { useEffect(() => { const handleEscKeyDown = (e: KeyboardEvent): void => { @@ -173,6 +200,8 @@ export const LogRowContext: React.FunctionComponent = ({ document.removeEventListener('keydown', handleEscKeyDown, false); }; }, [onOutsideClick]); + const theme = useTheme(); + const { afterContext, beforeContext } = getLogRowContextStyles(theme, wrapLogMessage); return ( @@ -184,9 +213,7 @@ export const LogRowContext: React.FunctionComponent = ({ rows={context.after} error={errors && errors.after} row={row} - className={css` - top: -250px; - `} + className={afterContext} shouldScrollToBottom canLoadMoreRows={hasMoreContextRows ? hasMoreContextRows.after : false} onLoadMoreContext={onLoadMoreContext} @@ -200,9 +227,7 @@ export const LogRowContext: React.FunctionComponent = ({ row={row} rows={context.before} error={errors && errors.before} - className={css` - top: 100%; - `} + className={beforeContext} /> )}
diff --git a/packages/grafana-ui/src/components/Logs/LogRowMessage.tsx b/packages/grafana-ui/src/components/Logs/LogRowMessage.tsx index c190de58ce7..96bd173f877 100644 --- a/packages/grafana-ui/src/components/Logs/LogRowMessage.tsx +++ b/packages/grafana-ui/src/components/Logs/LogRowMessage.tsx @@ -51,6 +51,10 @@ const getStyles = stylesFactory((theme: GrafanaTheme) => { label: verticalScroll; white-space: pre; `, + contextNewline: css` + display: block; + margin-left: 0px; + `, }; }); @@ -124,12 +128,15 @@ class UnThemedLogRowMessage extends PureComponent { return ( -
+
{contextIsOpen && context && ( { @@ -143,7 +150,10 @@ class UnThemedLogRowMessage extends PureComponent { {renderLogMessage(hasAnsi, restructuredEntry, highlights, highlightClassName)} {showContextToggle?.(row) && ( - + {contextIsOpen ? 'Hide' : 'Show'} context )} diff --git a/packages/grafana-ui/src/components/Logs/getLogRowStyles.ts b/packages/grafana-ui/src/components/Logs/getLogRowStyles.ts index 9fd2b6d2539..0a0b1ebabb7 100644 --- a/packages/grafana-ui/src/components/Logs/getLogRowStyles.ts +++ b/packages/grafana-ui/src/components/Logs/getLogRowStyles.ts @@ -48,13 +48,13 @@ export const getLogRowStyles = stylesFactory((theme: GrafanaTheme, logLevel?: Lo font-family: ${theme.typography.fontFamily.monospace}; font-size: ${theme.typography.size.sm}; width: 100%; - overflow: hidden; `, context: css` label: context; visibility: hidden; white-space: nowrap; position: relative; + margin-left: 10px; `, logsRow: css` label: logs-row; @@ -66,7 +66,6 @@ export const getLogRowStyles = stylesFactory((theme: GrafanaTheme, logLevel?: Lo .log-row-context { visibility: visible; z-index: 1; - margin-left: 10px; text-decoration: underline; &:hover { color: ${theme.palette.yellow}; diff --git a/public/app/features/explore/Logs.tsx b/public/app/features/explore/Logs.tsx index b6850cb76bc..dd4e4874896 100644 --- a/public/app/features/explore/Logs.tsx +++ b/public/app/features/explore/Logs.tsx @@ -283,7 +283,7 @@ export class UnthemedLogs extends PureComponent { forceEscape, } = this.state; - const styles = getStyles(theme); + const styles = getStyles(theme, wrapLogMessage); const hasData = logRows && logRows.length > 0; const hasUnescapedContent = this.checkUnescapedContent(logRows); @@ -420,7 +420,7 @@ export class UnthemedLogs extends PureComponent { export const Logs = withTheme2(UnthemedLogs); -const getStyles = (theme: GrafanaTheme2) => { +const getStyles = (theme: GrafanaTheme2, wrapLogMessage: boolean) => { return { noData: css` > * { @@ -450,7 +450,8 @@ const getStyles = (theme: GrafanaTheme2) => { justify-content: space-between; `, logRows: css` - overflow-x: scroll; + overflow-x: ${wrapLogMessage ? 'unset' : 'scroll'}; + overflow-y: visible; width: 100%; `, infoText: css`