From 00b108ca046e46ad98ee6ffb2800ee6f73757c47 Mon Sep 17 00:00:00 2001 From: Yury Molodov Date: Fri, 2 Aug 2024 15:48:36 +0200 Subject: [PATCH] vmui/logs: improve UI functionality (#6688) * add a toggle button to the "Group" tab that allows users to expand or collapse all groups at once * introduce the ability to select a key for grouping logs within the "Group" tab * display the number of entries within each log group. * move the Markdown toggle to the general settings panel in the upper left corner. (cherry picked from commit e06a19d85f404984bcae1ea02ea6bf57357c9c70) --- .../GlobalSettings/GlobalSettings.tsx | 5 + .../Configurators/GlobalSettings/style.scss | 9 +- .../MarkdownParsing/SwitchMarkdownParsing.tsx | 35 +++ .../vmui/src/components/Main/Icons/index.tsx | 22 ++ .../vmui/src/components/Table/Table.tsx | 7 +- .../components/TraceQuery/TracingsView.tsx | 10 +- .../vmui/src/contexts/AppContextProvider.tsx | 6 +- .../src/pages/ExploreLogs/ExploreLogs.tsx | 13 +- .../ExploreLogsBody/ExploreLogsBody.tsx | 14 +- .../ExploreLogs/ExploreLogsBody/TableLogs.tsx | 3 +- .../ExploreLogsHeader/ExploreLogsHeader.tsx | 14 +- .../pages/ExploreLogs/GroupLogs/GroupLogs.tsx | 222 ++++++++++++++---- .../ExploreLogs/GroupLogs/GroupLogsItem.tsx | 8 +- .../pages/ExploreLogs/GroupLogs/style.scss | 34 +++ .../src/state/logsPanel/LogsStateContext.tsx | 24 ++ .../vmui/src/state/logsPanel/reducer.ts | 26 ++ docs/VictoriaLogs/CHANGELOG.md | 4 + 17 files changed, 361 insertions(+), 95 deletions(-) create mode 100644 app/vmui/packages/vmui/src/components/Configurators/LogsSettings/MarkdownParsing/SwitchMarkdownParsing.tsx create mode 100644 app/vmui/packages/vmui/src/state/logsPanel/LogsStateContext.tsx create mode 100644 app/vmui/packages/vmui/src/state/logsPanel/reducer.ts diff --git a/app/vmui/packages/vmui/src/components/Configurators/GlobalSettings/GlobalSettings.tsx b/app/vmui/packages/vmui/src/components/Configurators/GlobalSettings/GlobalSettings.tsx index 816eff2ef0..45d482120a 100644 --- a/app/vmui/packages/vmui/src/components/Configurators/GlobalSettings/GlobalSettings.tsx +++ b/app/vmui/packages/vmui/src/components/Configurators/GlobalSettings/GlobalSettings.tsx @@ -13,6 +13,7 @@ import ThemeControl from "../ThemeControl/ThemeControl"; import useDeviceDetect from "../../../hooks/useDeviceDetect"; import useBoolean from "../../../hooks/useBoolean"; import { AppType } from "../../../types/appType"; +import SwitchMarkdownParsing from "../LogsSettings/MarkdownParsing/SwitchMarkdownParsing"; const title = "Settings"; @@ -60,6 +61,10 @@ const GlobalSettings: FC = () => { onClose={handleClose} /> }, + { + show: isLogsApp, + component: + }, { show: true, component: diff --git a/app/vmui/packages/vmui/src/components/Configurators/GlobalSettings/style.scss b/app/vmui/packages/vmui/src/components/Configurators/GlobalSettings/style.scss index 0fc6b63b62..57244eac6d 100644 --- a/app/vmui/packages/vmui/src/components/Configurators/GlobalSettings/style.scss +++ b/app/vmui/packages/vmui/src/components/Configurators/GlobalSettings/style.scss @@ -4,7 +4,7 @@ display: flex; flex-direction: column; align-items: center; - gap: $padding-medium; + gap: $padding-large; width: 600px; padding-bottom: $padding-medium; @@ -39,6 +39,13 @@ margin-bottom: $padding-global; } + &__info { + padding-top: $padding-small; + font-size: $font-size-small; + color: $color-text-secondary; + line-height: 130%; + } + &-url { display: flex; align-items: flex-start; diff --git a/app/vmui/packages/vmui/src/components/Configurators/LogsSettings/MarkdownParsing/SwitchMarkdownParsing.tsx b/app/vmui/packages/vmui/src/components/Configurators/LogsSettings/MarkdownParsing/SwitchMarkdownParsing.tsx new file mode 100644 index 0000000000..8c25945ad9 --- /dev/null +++ b/app/vmui/packages/vmui/src/components/Configurators/LogsSettings/MarkdownParsing/SwitchMarkdownParsing.tsx @@ -0,0 +1,35 @@ +import React, { FC } from "preact/compat"; +import Switch from "../../../Main/Switch/Switch"; +import useDeviceDetect from "../../../../hooks/useDeviceDetect"; +import { useLogsDispatch, useLogsState } from "../../../../state/logsPanel/LogsStateContext"; + +const SwitchMarkdownParsing: FC = () => { + const { isMobile } = useDeviceDetect(); + const { markdownParsing } = useLogsState(); + const dispatch = useLogsDispatch(); + + + const handleChangeMarkdownParsing = (val: boolean) => { + dispatch({ type: "SET_MARKDOWN_PARSING", payload: val }); + }; + + return ( +
+
+ Markdown Parsing for Logs +
+ +
+ Toggle this switch to enable or disable the Markdown formatting for log entries. + Enabling this will parse log texts to Markdown. +
+
+ ); +}; + +export default SwitchMarkdownParsing; diff --git a/app/vmui/packages/vmui/src/components/Main/Icons/index.tsx b/app/vmui/packages/vmui/src/components/Main/Icons/index.tsx index 8f49d37be0..bef8f8c638 100644 --- a/app/vmui/packages/vmui/src/components/Main/Icons/index.tsx +++ b/app/vmui/packages/vmui/src/components/Main/Icons/index.tsx @@ -520,3 +520,25 @@ export const DownloadIcon = () => ( ); + +export const ExpandIcon = () => ( + + + +); + +export const CollapseIcon = () => ( + + + +); diff --git a/app/vmui/packages/vmui/src/components/Table/Table.tsx b/app/vmui/packages/vmui/src/components/Table/Table.tsx index 1a53542b79..e4cf0ad77e 100644 --- a/app/vmui/packages/vmui/src/components/Table/Table.tsx +++ b/app/vmui/packages/vmui/src/components/Table/Table.tsx @@ -6,11 +6,14 @@ import Tooltip from "../Main/Tooltip/Tooltip"; import Button from "../Main/Button/Button"; import { useEffect } from "preact/compat"; +type OrderDir = "asc" | "desc" + interface TableProps { rows: T[]; columns: { title?: string, key: keyof Partial, className?: string }[]; defaultOrderBy: keyof T; copyToClipboard?: keyof T; + defaultOrderDir?: OrderDir; // TODO: Remove when pagination is implemented on the backend. paginationOffset: { startIndex: number; @@ -18,9 +21,9 @@ interface TableProps { } } -const Table = ({ rows, columns, defaultOrderBy, copyToClipboard, paginationOffset }: TableProps) => { +const Table = ({ rows, columns, defaultOrderBy, defaultOrderDir, copyToClipboard, paginationOffset }: TableProps) => { const [orderBy, setOrderBy] = useState(defaultOrderBy); - const [orderDir, setOrderDir] = useState<"asc" | "desc">("desc"); + const [orderDir, setOrderDir] = useState(defaultOrderDir || "desc"); const [copied, setCopied] = useState(null); // const sortedList = useMemo(() => stableSort(rows as [], getComparator(orderDir, orderBy)), diff --git a/app/vmui/packages/vmui/src/components/TraceQuery/TracingsView.tsx b/app/vmui/packages/vmui/src/components/TraceQuery/TracingsView.tsx index ed3c377dc8..12fbe1f9c6 100644 --- a/app/vmui/packages/vmui/src/components/TraceQuery/TracingsView.tsx +++ b/app/vmui/packages/vmui/src/components/TraceQuery/TracingsView.tsx @@ -1,7 +1,7 @@ import React, { FC, useState } from "preact/compat"; import Trace from "./Trace"; import Button from "../Main/Button/Button"; -import { ArrowDownIcon, CodeIcon, DeleteIcon, DownloadIcon } from "../Main/Icons"; +import { CodeIcon, CollapseIcon, DeleteIcon, DownloadIcon, ExpandIcon } from "../Main/Icons"; import "./style.scss"; import NestedNav from "./NestedNav/NestedNav"; import Alert from "../Main/Alert/Alert"; @@ -89,13 +89,7 @@ const TracingsView: FC = ({ traces, jsonEditor = false, onDelete