Skip to content

Commit e11392a

Browse files
committed
Refactor RequestHistory and useApiTester components to simplify code; remove unused formatTime function and bodyFormat state, enhancing maintainability
1 parent e86bfa5 commit e11392a

3 files changed

Lines changed: 249 additions & 267 deletions

File tree

spa/src/components/api-tester/RequestHistory.tsx

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,6 @@ function statusColor(status: number): string {
1515
return 'text-rose-600 dark:text-rose-400';
1616
}
1717

18-
function formatTime(ts: number): string {
19-
const d = new Date(ts);
20-
return d.toLocaleTimeString([], { hour: '2-digit', minute: '2-digit', second: '2-digit' });
21-
}
22-
2318
interface RequestHistoryProps {
2419
history: HistoryEntry[];
2520
search: string;
@@ -75,14 +70,11 @@ export function RequestHistory({ history, search, onSearchChange, onSelect, acti
7570
{entry.method}
7671
</span>
7772
<span className="flex-1 text-xs font-mono text-slate-600 dark:text-slate-400 truncate">{entry.path}</span>
78-
<div className="shrink-0 flex flex-col items-end gap-0.5">
79-
{entry.response && (
80-
<span className={`text-[10px] font-semibold ${statusColor(entry.response.status)}`}>
81-
{entry.response.status || 'ERR'}
82-
</span>
83-
)}
84-
<span className="text-[10px] text-slate-400 dark:text-slate-500">{formatTime(entry.timestamp)}</span>
85-
</div>
73+
{entry.response && (
74+
<span className={`shrink-0 text-xs font-semibold ${statusColor(entry.response.status)}`}>
75+
{entry.response.status || 'ERR'}
76+
</span>
77+
)}
8678
</button>
8779
))}
8880
</div>

spa/src/components/api-tester/useApiTester.ts

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,12 @@ export interface KeyValuePair {
99
enabled: boolean;
1010
}
1111

12-
export type BodyFormat = 'json' | 'xml';
13-
1412
export interface RequestState {
1513
method: string;
1614
url: string;
1715
pathParams: KeyValuePair[];
1816
queryParams: KeyValuePair[];
1917
headers: KeyValuePair[];
20-
bodyFormat: BodyFormat;
2118
body: string;
2219
}
2320

@@ -114,7 +111,6 @@ function buildInitialRequest(endpoint: Endpoint, baseUrl: string, spec: OpenApiS
114111
pathParams,
115112
queryParams,
116113
headers,
117-
bodyFormat: 'json',
118114
body,
119115
};
120116
}
@@ -174,7 +170,6 @@ export interface UseApiTesterReturn {
174170
setPathParams: (params: KeyValuePair[]) => void;
175171
setQueryParams: (params: KeyValuePair[]) => void;
176172
setHeaders: (headers: KeyValuePair[]) => void;
177-
setBodyFormat: (format: BodyFormat) => void;
178173
setBody: (body: string) => void;
179174
setHistorySearch: (search: string) => void;
180175
sendRequest: () => Promise<void>;
@@ -214,10 +209,6 @@ export function useApiTester(endpoint: Endpoint, spec: OpenApiSpec): UseApiTeste
214209
setRequest(prev => ({ ...prev, headers }));
215210
}, []);
216211

217-
const setBodyFormat = useCallback((bodyFormat: BodyFormat) => {
218-
setRequest(prev => ({ ...prev, bodyFormat }));
219-
}, []);
220-
221212
const setBody = useCallback((body: string) => {
222213
setRequest(prev => ({ ...prev, body }));
223214
}, []);
@@ -346,7 +337,6 @@ export function useApiTester(endpoint: Endpoint, spec: OpenApiSpec): UseApiTeste
346337
setPathParams,
347338
setQueryParams,
348339
setHeaders,
349-
setBodyFormat,
350340
setBody,
351341
setHistorySearch,
352342
sendRequest,

0 commit comments

Comments
 (0)