check resource type

This commit is contained in:
x032205
2025-11-01 04:17:59 -04:00
parent 7d978443c7
commit 39567116c8
2 changed files with 31 additions and 17 deletions
@@ -1,3 +1,4 @@
import { PamResourceType } from "@app/hooks/api/pam";
import { useState } from "react"; import { useState } from "react";
type TableLog = { type TableLog = {
@@ -6,26 +7,36 @@ type TableLog = {
total_rows?: number; total_rows?: number;
}; };
export const PamSessionLogOutput = ({ content }: { content: string }) => { export const PamSessionLogOutput = ({
content,
resourceType
}: {
content: string;
resourceType: PamResourceType;
}) => {
const [isRawView, setIsRawView] = useState(false); const [isRawView, setIsRawView] = useState(false);
let parsedContent: TableLog | null = null; let parsedContent: TableLog | null = null;
try {
const parsed = JSON.parse(content); if (resourceType === PamResourceType.Postgres || resourceType === PamResourceType.MySQL) {
if ( try {
parsed && const parsed = JSON.parse(content);
typeof parsed === "object" &&
!Array.isArray(parsed) && if (
parsed.data_rows && parsed &&
Array.isArray(parsed.data_rows) && typeof parsed === "object" &&
parsed.data_rows.length > 0 && !Array.isArray(parsed) &&
typeof parsed.data_rows[0] === "object" && parsed.data_rows &&
parsed.data_rows[0] !== null Array.isArray(parsed.data_rows) &&
) { parsed.data_rows.length > 0 &&
parsedContent = parsed; typeof parsed.data_rows[0] === "object" &&
parsed.data_rows[0] !== null
) {
parsedContent = parsed;
}
} catch (error) {
// Not a valid JSON or doesn't match structure, will render as plain text
} }
} catch (error) {
// Not a valid JSON or doesn't match structure, will render as plain text
} }
if (parsedContent) { if (parsedContent) {
@@ -68,7 +68,10 @@ export const PamSessionLogsSection = ({ session }: Props) => {
<div className="h-px w-full bg-mineshaft-400"></div> <div className="h-px w-full bg-mineshaft-400"></div>
</div> </div>
<div className="pt-2 text-bunker-300"> <div className="pt-2 text-bunker-300">
<PamSessionLogOutput content={log.output} /> <PamSessionLogOutput
content={log.output}
resourceType={session.resourceType}
/>
</div> </div>
</> </>
)} )}