-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrequest-workspace-tabs.tsx
More file actions
237 lines (228 loc) · 10.3 KB
/
request-workspace-tabs.tsx
File metadata and controls
237 lines (228 loc) · 10.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
import { createMemo, For, Match, Show, Switch } from 'solid-js';
import type { WorkspaceRequest } from '../../sdk';
import type { RequestBodySummary, RequestDetailsRow } from '../../utils/request-details';
import { toRequestParams } from '../../utils/request-details';
import { REQUEST_WORKSPACE_TABS, type RequestWorkspaceTabId } from './model';
interface RequestWorkspaceTabsProps {
activeTab: RequestWorkspaceTabId;
onTabChange: (tab: RequestWorkspaceTabId) => void;
selectedRequest?: WorkspaceRequest;
requestCount: number;
requestHeaders: RequestDetailsRow[];
requestBodySummary: RequestBodySummary;
requestDetailsLoading: boolean;
requestDetailsError?: string;
}
const TAB_LABELS: Record<RequestWorkspaceTabId, string> = {
params: 'Params',
headers: 'Headers',
body: 'Body'
};
export function RequestWorkspaceTabs(props: RequestWorkspaceTabsProps) {
const requestParams = createMemo(() => {
const request = props.selectedRequest;
if (!request) {
return [];
}
return toRequestParams(request.url);
});
return (
<section
class="border-b border-treq-border-light dark:border-treq-dark-border-light bg-base-100/80"
aria-label="Request workspace details"
>
<div class="flex items-center justify-between gap-3 px-3 pt-2">
<p class="text-xs font-mono uppercase tracking-[0.08em] text-base-content/60">
Request Workspace
</p>
<span class="badge badge-sm border-base-300 bg-base-200/70 font-mono text-[11px]">
{props.requestCount} req
</span>
</div>
<div role="tablist" class="tabs tabs-border px-3 pt-1">
<For each={REQUEST_WORKSPACE_TABS}>
{(tab) => (
<button
type="button"
role="tab"
class="tab tab-sm"
aria-selected={props.activeTab === tab}
classList={{ 'tab-active': props.activeTab === tab }}
onClick={() => props.onTabChange(tab)}
>
{TAB_LABELS[tab]}
</button>
)}
</For>
</div>
<div class="px-3 pb-3 pt-2">
<div class="rounded-box border border-base-300 bg-base-100/70 px-3 py-2 text-sm text-base-content/75">
<Show
when={props.selectedRequest}
fallback={<p>Select a request to view {TAB_LABELS[props.activeTab].toLowerCase()}.</p>}
>
{(request) => (
<Switch>
<Match when={props.activeTab === 'params'}>
<Show
when={requestParams().length > 0}
fallback={
<p>No query params in URL for {request().method.toUpperCase()} requests.</p>
}
>
<div class="overflow-auto rounded-box border border-base-300 bg-base-100/80">
<table class="table table-xs">
<thead>
<tr>
<th class="font-mono uppercase tracking-[0.06em] text-[11px]">Name</th>
<th class="font-mono uppercase tracking-[0.06em] text-[11px]">Value</th>
</tr>
</thead>
<tbody>
<For each={requestParams()}>
{(param) => (
<tr>
<td class="font-mono text-xs text-base-content">{param.key}</td>
<td class="font-mono text-xs text-base-content/80">
{param.value}
</td>
</tr>
)}
</For>
</tbody>
</table>
</div>
</Show>
</Match>
<Match when={props.activeTab === 'headers'}>
<Show
when={!props.requestDetailsLoading}
fallback={<p>Loading request headers…</p>}
>
<Show
when={!props.requestDetailsError}
fallback={<p>{props.requestDetailsError}</p>}
>
<Show
when={props.requestHeaders.length > 0}
fallback={<p>No headers were parsed for this request.</p>}
>
<div class="overflow-auto rounded-box border border-base-300 bg-base-100/80">
<table class="table table-xs">
<thead>
<tr>
<th class="font-mono uppercase tracking-[0.06em] text-[11px]">
Name
</th>
<th class="font-mono uppercase tracking-[0.06em] text-[11px]">
Value
</th>
</tr>
</thead>
<tbody>
<For each={props.requestHeaders}>
{(header) => (
<tr>
<td class="font-mono text-xs text-base-content">
{header.key}
</td>
<td class="font-mono text-xs text-base-content/80">
{header.value}
</td>
</tr>
)}
</For>
</tbody>
</table>
</div>
</Show>
</Show>
</Show>
</Match>
<Match when={props.activeTab === 'body'}>
<Show when={!props.requestDetailsLoading} fallback={<p>Loading request body…</p>}>
<Show
when={!props.requestDetailsError}
fallback={<p>{props.requestDetailsError}</p>}
>
<div class="space-y-2">
<p>{props.requestBodySummary.description}</p>
<Switch>
<Match
when={
props.requestBodySummary.kind === 'inline' &&
props.requestBodySummary.text !== undefined
}
>
<pre class="max-h-52 overflow-auto rounded-box border border-base-300 bg-base-100/80 p-2 font-mono text-xs text-base-content">
{props.requestBodySummary.text}
</pre>
</Match>
<Match when={props.requestBodySummary.kind === 'form-data'}>
<Show
when={(props.requestBodySummary.fields?.length ?? 0) > 0}
fallback={<p>No form-data fields were parsed.</p>}
>
<div class="overflow-auto rounded-box border border-base-300 bg-base-100/80">
<table class="table table-xs">
<thead>
<tr>
<th class="font-mono uppercase tracking-[0.06em] text-[11px]">
Name
</th>
<th class="font-mono uppercase tracking-[0.06em] text-[11px]">
Type
</th>
<th class="font-mono uppercase tracking-[0.06em] text-[11px]">
Value
</th>
</tr>
</thead>
<tbody>
<For each={props.requestBodySummary.fields}>
{(field) => (
<tr>
<td class="font-mono text-xs text-base-content">
{field.name}
</td>
<td class="font-mono text-xs text-base-content/80">
{field.isFile ? 'file' : 'text'}
</td>
<td class="font-mono text-xs text-base-content/80">
{field.isFile
? (field.path ?? field.filename ?? field.value)
: field.value}
</td>
</tr>
)}
</For>
</tbody>
</table>
</div>
</Show>
</Match>
<Match when={props.requestBodySummary.kind === 'file'}>
<Show
when={props.requestBodySummary.filePath}
fallback={<p>No request body file path was parsed.</p>}
>
{(filePath) => (
<div class="rounded-box border border-base-300 bg-base-100/80 p-2">
<p class="font-mono text-xs text-base-content/80">{filePath()}</p>
</div>
)}
</Show>
</Match>
</Switch>
</div>
</Show>
</Show>
</Match>
</Switch>
)}
</Show>
</div>
</div>
</section>
);
}