Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.
TypeScript acmeagentsai-agentscertificate-managementdevsecopsenvironment-variableskubernetesopen-sourcepampkipostgresprivate-caprivileged-access-managementsecret-managementsecret-managersecretssecrets-managementsecuritysecurity-toolsvault
Move formatLogContent to a utils file
x0322057d978443c7e0
diff --git a/frontend/src/pages/pam/PamSessionsByIDPage/components/PamSessionLogsSection.tsx b/frontend/src/pages/pam/PamSessionsByIDPage/components/PamSessionLogsSection.tsxindex d620cf4cc3..9350f6cd91 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 (<button@@ -114,7 +68,7 @@ export const PamSessionLogsSection = ({ session }: Props) => {<div className="h-px w-full bg-mineshaft-400"></div></div><div className="pt-2 text-bunker-300">- <PamSessionLogOutput content={formattedOutput} />+ <PamSessionLogOutput content={log.output} /></div></>)}diff --git a/frontend/src/pages/pam/PamSessionsByIDPage/components/PamSessionLogsSection.utils.ts b/frontend/src/pages/pam/PamSessionsByIDPage/components/PamSessionLogsSection.utils.tsnew file mode 100644index 0000000000..4696331fb7--- /dev/null+++ b/frontend/src/pages/pam/PamSessionsByIDPage/components/PamSessionLogsSection.utils.ts@@ -0,0 +1,46 @@+// This function trims top and bottom empty padding, as well as moves all relative text to the left while still respecting indentation+export 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");+};