Skip to content

Commit 428f442

Browse files
authored
Merge pull request #47 from ryanbas21/feat/inspector-payload-tab
feat(devtools-ui): add Payload tab to inspector panel
2 parents 40c8f67 + f3e7c29 commit 428f442

5 files changed

Lines changed: 82 additions & 7 deletions

File tree

.changeset/add-payload-tab.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@wolfcola/devtools-extension': minor
3+
---
4+
5+
Add Payload tab to inspector panel, separating request/response bodies from the Headers tab into a dedicated tab matching Chrome DevTools naming conventions

packages/devtools-ui/src/panel.css

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -566,6 +566,17 @@ body {
566566
padding: 2px 8px;
567567
}
568568

569+
/* ── Payload Tab ─────────────────────────────────────────── */
570+
.payload-section {
571+
margin-bottom: 8px;
572+
}
573+
.payload-header {
574+
display: flex;
575+
justify-content: space-between;
576+
align-items: center;
577+
margin-bottom: 4px;
578+
}
579+
569580
/* ── JsonTree ────────────────────────────────────────────── */
570581
.jt-sec {
571582
margin-bottom: 14px;

packages/devtools-ui/src/src/Inspector.elm

Lines changed: 54 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,22 @@ viewTabs maybeEvent activeTab maybeDiagnosis =
9292
, tabButton "CORS" CorsTab activeTab
9393
, tabButton "SDK State" SdkStateTab activeTab
9494
]
95+
++ (case maybeEvent of
96+
Just event ->
97+
case event.data of
98+
Network net ->
99+
if net.requestBody /= Nothing || net.responseBody /= Nothing then
100+
[ tabButton "Payload" PayloadTab activeTab ]
101+
102+
else
103+
[]
104+
105+
_ ->
106+
[]
107+
108+
Nothing ->
109+
[]
110+
)
95111
++ (if isSdkEvent then
96112
[ tabButton "Collectors" CollectorsTab activeTab ]
97113

@@ -166,19 +182,35 @@ viewContent maybeEvent activeTab maybeDiagnosis =
166182
Just h -> JsonTree.view "Response Headers" h
167183
Nothing -> viewEmptySection "Response Headers"
168184
]
169-
++ (case net.requestBody of
170-
Just b -> [ JsonTree.view "Request Body" b ]
171-
Nothing -> []
172-
)
185+
)
186+
187+
_ ->
188+
div [ class "insp-empty" ]
189+
[ text "Select a network request to see headers." ]
190+
191+
( Just event, PayloadTab ) ->
192+
case event.data of
193+
Network net ->
194+
div []
195+
((case net.requestBody of
196+
Just b ->
197+
[ viewPayloadSection "Request Body" b ]
198+
199+
Nothing ->
200+
[]
201+
)
173202
++ (case net.responseBody of
174-
Just b -> [ JsonTree.view "Response Body" b ]
175-
Nothing -> []
203+
Just b ->
204+
[ viewPayloadSection "Response Body" b ]
205+
206+
Nothing ->
207+
[]
176208
)
177209
)
178210

179211
_ ->
180212
div [ class "insp-empty" ]
181-
[ text "Select a network request to see headers." ]
213+
[ text "No payload data for this event." ]
182214

183215
( Just event, CookiesTab ) ->
184216
case event.data of
@@ -407,6 +439,21 @@ viewEmptySection label =
407439
]
408440

409441

442+
viewPayloadSection : String -> Decode.Value -> Html Msg
443+
viewPayloadSection label body =
444+
div [ class "payload-section" ]
445+
[ div [ class "payload-header" ]
446+
[ div [ class "sect-hdr", style "margin" "0", style "border" "none", style "padding" "0" ] [ text label ]
447+
, button
448+
[ class "fv-copy-btn"
449+
, onClick (CopyToClipboard (Encode.encode 4 body))
450+
]
451+
[ text "\u{2398}" ]
452+
]
453+
, JsonTree.view "" body
454+
]
455+
456+
410457
viewCookies : NetworkData -> List (Html Msg)
411458
viewCookies net =
412459
let

packages/devtools-ui/src/src/Types.elm

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ type alias OidcSemanticData =
179179
type InspectorTab
180180
= DiagnosisTab
181181
| HeadersTab
182+
| PayloadTab
182183
| CookiesTab
183184
| CorsTab
184185
| SdkStateTab

packages/devtools-ui/src/src/Update.elm

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,17 @@ update msg model =
105105
else
106106
OidcTab
107107

108+
( PayloadTab, Just e ) ->
109+
case e.data of
110+
Network net ->
111+
if net.requestBody == Nothing && net.responseBody == Nothing then
112+
HeadersTab
113+
else
114+
PayloadTab
115+
116+
_ ->
117+
HeadersTab
118+
108119
_ ->
109120
model.activeTab
110121
in

0 commit comments

Comments
 (0)