diff --git a/client/src/components/DynamicJsonForm.tsx b/client/src/components/DynamicJsonForm.tsx index 70270e3..fa04467 100644 --- a/client/src/components/DynamicJsonForm.tsx +++ b/client/src/components/DynamicJsonForm.tsx @@ -2,33 +2,9 @@ import { useState, useEffect, useCallback, useRef } from "react"; import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; import JsonEditor from "./JsonEditor"; -import { updateValueAtPath } from "@/utils/jsonPathUtils"; +import { updateValueAtPath } from "@/utils/jsonUtils"; import { generateDefaultValue } from "@/utils/schemaUtils"; - -export type JsonValue = - | string - | number - | boolean - | null - | undefined - | JsonValue[] - | { [key: string]: JsonValue }; - -export type JsonSchemaType = { - type: - | "string" - | "number" - | "integer" - | "boolean" - | "array" - | "object" - | "null"; - description?: string; - required?: boolean; - default?: JsonValue; - properties?: Record; - items?: JsonSchemaType; -}; +import type { JsonValue, JsonSchemaType } from "@/utils/jsonUtils"; interface DynamicJsonFormProps { schema: JsonSchemaType; diff --git a/client/src/components/JsonView.tsx b/client/src/components/JsonView.tsx index b59f3cc..3fcbf8e 100644 --- a/client/src/components/JsonView.tsx +++ b/client/src/components/JsonView.tsx @@ -1,9 +1,10 @@ import { useState, memo, useMemo, useCallback, useEffect } from "react"; -import { JsonValue } from "./DynamicJsonForm"; +import type { JsonValue } from "@/utils/jsonUtils"; import clsx from "clsx"; import { Copy, CheckCheck } from "lucide-react"; import { Button } from "@/components/ui/button"; import { useToast } from "@/hooks/use-toast"; +import { getDataType, tryParseJson } from "@/utils/jsonUtils"; interface JsonViewProps { data: unknown; @@ -11,21 +12,7 @@ interface JsonViewProps { initialExpandDepth?: number; className?: string; withCopyButton?: boolean; -} - -function tryParseJson(str: string): { success: boolean; data: JsonValue } { - const trimmed = str.trim(); - if ( - !(trimmed.startsWith("{") && trimmed.endsWith("}")) && - !(trimmed.startsWith("[") && trimmed.endsWith("]")) - ) { - return { success: false, data: str }; - } - try { - return { success: true, data: JSON.parse(str) }; - } catch { - return { success: false, data: str }; - } + isError?: boolean; } const JsonView = memo( @@ -35,6 +22,7 @@ const JsonView = memo( initialExpandDepth = 3, className, withCopyButton = true, + isError = false, }: JsonViewProps) => { const { toast } = useToast(); const [copied, setCopied] = useState(false); @@ -100,6 +88,7 @@ const JsonView = memo( name={name} depth={0} initialExpandDepth={initialExpandDepth} + isError={isError} /> @@ -114,28 +103,28 @@ interface JsonNodeProps { name?: string; depth: number; initialExpandDepth: number; + isError?: boolean; } const JsonNode = memo( - ({ data, name, depth = 0, initialExpandDepth }: JsonNodeProps) => { + ({ + data, + name, + depth = 0, + initialExpandDepth, + isError = false, + }: JsonNodeProps) => { const [isExpanded, setIsExpanded] = useState(depth < initialExpandDepth); - - const getDataType = (value: JsonValue): string => { - if (Array.isArray(value)) return "array"; - if (value === null) return "null"; - return typeof value; - }; - - const dataType = getDataType(data); - - const typeStyleMap: Record = { + const [typeStyleMap] = useState>({ number: "text-blue-600", boolean: "text-amber-600", null: "text-purple-600", undefined: "text-gray-600", - string: "text-green-600 break-all whitespace-pre-wrap", + string: "text-green-600 group-hover:text-green-500", + error: "text-red-600 group-hover:text-red-500", default: "text-gray-700", - }; + }); + const dataType = getDataType(data); const renderCollapsible = (isArray: boolean) => { const items = isArray @@ -236,7 +225,14 @@ const JsonNode = memo( {name}: )} -
"{value}"
+
+              "{value}"
+            
); } @@ -250,8 +246,8 @@ const JsonNode = memo( )}
 setIsExpanded(!isExpanded)}
             title={isExpanded ? "Click to collapse" : "Click to expand"}
diff --git a/client/src/components/Sidebar.tsx b/client/src/components/Sidebar.tsx
index 4633d64..a53d337 100644
--- a/client/src/components/Sidebar.tsx
+++ b/client/src/components/Sidebar.tsx
@@ -103,14 +103,19 @@ const Sidebar = ({
       
- + setCommand(e.target.value)} @@ -132,8 +140,14 @@ const Sidebar = ({ />
- + setArgs(e.target.value)} @@ -144,8 +158,11 @@ const Sidebar = ({ ) : ( <>
- + setSseUrl(e.target.value)} @@ -157,6 +174,7 @@ const Sidebar = ({ variant="outline" onClick={() => setShowBearerToken(!showBearerToken)} className="flex items-center w-full" + aria-expanded={showBearerToken} > {showBearerToken ? ( @@ -167,8 +185,14 @@ const Sidebar = ({ {showBearerToken && (
- + setBearerToken(e.target.value)} @@ -187,6 +211,7 @@ const Sidebar = ({ onClick={() => setShowEnvVars(!showEnvVars)} className="flex items-center w-full" data-testid="env-vars-button" + aria-expanded={showEnvVars} > {showEnvVars ? ( @@ -201,6 +226,7 @@ const Sidebar = ({
{ @@ -243,6 +269,7 @@ const Sidebar = ({
setShowConfig(!showConfig)} className="flex items-center w-full" data-testid="config-button" + aria-expanded={showConfig} > {showConfig ? ( @@ -325,7 +353,10 @@ const Sidebar = ({ return (
-
{typeof configItem.value === "number" ? ( - + @@ -375,6 +407,7 @@ const Sidebar = ({ ) : ( { @@ -398,7 +431,13 @@ const Sidebar = ({
{connectionStatus === "connected" && (
- @@ -448,14 +487,19 @@ const Sidebar = ({ {loggingSupported && connectionStatus === "connected" && (
- +