From cb8c45456b5a81f9aa582ef05e2d760a861ec46b Mon Sep 17 00:00:00 2001 From: "jeetul.samaiya" Date: Mon, 1 Sep 2025 12:15:37 +0530 Subject: [PATCH] refactor: improve code formatting and readability across multiple files --- client/src/App.tsx | 5 +- client/src/components/CustomHeaders.tsx | 55 +++++++++++++------ client/src/components/ui/switch.tsx | 4 +- .../hooks/__tests__/useConnection.test.tsx | 22 ++++---- client/src/lib/types/customHeaders.ts | 27 +++++---- server/src/index.ts | 8 ++- 6 files changed, 79 insertions(+), 42 deletions(-) diff --git a/client/src/App.tsx b/client/src/App.tsx index ff44759e..17c50435 100644 --- a/client/src/App.tsx +++ b/client/src/App.tsx @@ -74,7 +74,10 @@ import ElicitationTab, { PendingElicitationRequest, ElicitationResponse, } from "./components/ElicitationTab"; -import { CustomHeaders, migrateFromLegacyAuth } from "./lib/types/customHeaders"; +import { + CustomHeaders, + migrateFromLegacyAuth, +} from "./lib/types/customHeaders"; const CONFIG_LOCAL_STORAGE_KEY = "inspectorConfig_v1"; diff --git a/client/src/components/CustomHeaders.tsx b/client/src/components/CustomHeaders.tsx index 9196480e..35b12212 100644 --- a/client/src/components/CustomHeaders.tsx +++ b/client/src/components/CustomHeaders.tsx @@ -4,7 +4,11 @@ import { Input } from "@/components/ui/input"; import { Textarea } from "@/components/ui/textarea"; import { Switch } from "@/components/ui/switch"; import { Plus, Trash2, Eye, EyeOff } from "lucide-react"; -import { CustomHeaders as CustomHeadersType, CustomHeader, createEmptyHeader } from "@/lib/types/customHeaders"; +import { + CustomHeaders as CustomHeadersType, + CustomHeader, + createEmptyHeader, +} from "@/lib/types/customHeaders"; interface CustomHeadersProps { headers: CustomHeadersType; @@ -12,13 +16,21 @@ interface CustomHeadersProps { className?: string; } -const CustomHeaders = ({ headers, onChange, className }: CustomHeadersProps) => { +const CustomHeaders = ({ + headers, + onChange, + className, +}: CustomHeadersProps) => { const [isJsonMode, setIsJsonMode] = useState(false); const [jsonValue, setJsonValue] = useState(""); const [jsonError, setJsonError] = useState(null); const [visibleValues, setVisibleValues] = useState>(new Set()); - const updateHeader = (index: number, field: keyof CustomHeader, value: string | boolean) => { + const updateHeader = ( + index: number, + field: keyof CustomHeader, + value: string | boolean, + ) => { const newHeaders = [...headers]; newHeaders[index] = { ...newHeaders[index], [field]: value }; onChange(newHeaders); @@ -58,16 +70,22 @@ const CustomHeaders = ({ headers, onChange, className }: CustomHeadersProps) => const switchToFormMode = () => { try { const parsed = JSON.parse(jsonValue); - if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) { + if ( + typeof parsed !== "object" || + parsed === null || + Array.isArray(parsed) + ) { setJsonError("JSON must be an object with string key-value pairs"); return; } - const newHeaders: CustomHeadersType = Object.entries(parsed).map(([name, value]) => ({ - name, - value: String(value), - enabled: true, - })); + const newHeaders: CustomHeadersType = Object.entries(parsed).map( + ([name, value]) => ({ + name, + value: String(value), + enabled: true, + }), + ); onChange(newHeaders); setJsonError(null); @@ -86,7 +104,9 @@ const CustomHeaders = ({ headers, onChange, className }: CustomHeadersProps) => return (
-

Custom Headers (JSON)

+

+ Custom Headers (JSON) +