diff --git a/client/src/components/DynamicJsonForm.tsx b/client/src/components/DynamicJsonForm.tsx index f5b0d63..bd77639 100644 --- a/client/src/components/DynamicJsonForm.tsx +++ b/client/src/components/DynamicJsonForm.tsx @@ -3,33 +3,9 @@ import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; import { Label } from "@/components/ui/label"; import JsonEditor from "./JsonEditor"; -import { updateValueAtPath, JsonObject } from "@/utils/jsonPathUtils"; +import { updateValueAtPath } from "@/utils/jsonUtils"; import { generateDefaultValue, formatFieldLabel } 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, JsonObject } from "@/utils/jsonUtils"; interface DynamicJsonFormProps { schema: JsonSchemaType; diff --git a/client/src/components/JsonView.tsx b/client/src/components/JsonView.tsx index 46a267d..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; @@ -14,21 +15,6 @@ interface JsonViewProps { isError?: 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 }; - } -} - const JsonView = memo( ({ data, @@ -129,16 +115,7 @@ const JsonNode = memo( 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", @@ -146,7 +123,8 @@ const JsonNode = memo( 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 diff --git a/client/src/components/Sidebar.tsx b/client/src/components/Sidebar.tsx index 4633d64..e3e2118 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 = ({ ) : ( { @@ -448,14 +481,19 @@ const Sidebar = ({ {loggingSupported && connectionStatus === "connected" && (
- +