diff --git a/frontend/src/pages/pam/PamSessionsByIDPage/components/PamSessionLogsSection.tsx b/frontend/src/pages/pam/PamSessionsByIDPage/components/PamSessionLogsSection.tsx index d620cf4cc..9350f6cd9 100644 --- a/frontend/src/pages/pam/PamSessionsByIDPage/components/PamSessionLogsSection.tsx +++ b/frontend/src/pages/pam/PamSessionsByIDPage/components/PamSessionLogsSection.tsx @@ -4,52 +4,7 @@ import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; import { TPamSession } from "@app/hooks/api/pam"; import { PamSessionLogOutput } from "./PamSessionLogOutput"; - -const formatLogContent = (text: string | null | undefined): string => { - if (!text) return ""; - - let lines = text.split("\n"); - - // Find the first and last non-empty lines to trim vertical padding - let firstLineIndex = -1; - for (let i = 0; i < lines.length; i += 1) { - if (lines[i].trim() !== "") { - firstLineIndex = i; - break; - } - } - - if (firstLineIndex === -1) { - return ""; - } - - let lastLineIndex = -1; - for (let i = lines.length - 1; i >= 0; i -= 1) { - if (lines[i].trim() !== "") { - lastLineIndex = i; - break; - } - } - - lines = lines.slice(firstLineIndex, lastLineIndex + 1); - - // Determine the minimum indentation of non-empty lines - const indentations = lines - .filter((line) => line.trim() !== "") - .map((line) => { - const match = line.match(/^\s*/); - return match ? match[0].length : 0; - }); - - const minIndentation = Math.min(...indentations); - - // Remove the common indentation from all lines - if (minIndentation > 0) { - lines = lines.map((line) => line.substring(minIndentation)); - } - - return lines.join("\n"); -}; +import { formatLogContent } from "./PamSessionLogsSection.utils"; type Props = { session: TPamSession; @@ -77,7 +32,6 @@ export const PamSessionLogsSection = ({ session }: Props) => { session.commandLogs.map((log) => { const isExpanded = expandedLogTimestamps.has(log.timestamp); const formattedInput = formatLogContent(log.input); - const formattedOutput = formatLogContent(log.output); return (