Skip to content

Commit 3f55c00

Browse files
feat(compare): add payload type badges to compare request and response sections
1 parent 30c6c71 commit 3f55c00

2 files changed

Lines changed: 62 additions & 14 deletions

File tree

DebugProbe.AspNetCore/Resources/css/debugprobe.css

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,13 @@ pre {
218218
font-size: 12px;
219219
}
220220

221+
.compare-pane-title {
222+
display: flex;
223+
align-items: center;
224+
gap: 10px;
225+
margin-bottom: 6px;
226+
}
227+
221228
/* =========================
222229
Badges
223230
========================= */
@@ -268,12 +275,8 @@ pre {
268275
}
269276

270277
.diff-badge {
271-
min-width: 22px;
272-
height: 22px;
273-
background: #e74c3c;
274-
color: #fff;
275-
font-size: 12px;
276-
font-weight: bold;
278+
background: #4a1717;
279+
color: #ff8a8a;
277280
}
278281

279282
/* =========================

DebugProbe.AspNetCore/Resources/js/debugprobe_compare_renderer.js

Lines changed: 53 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -180,17 +180,19 @@ function renderSideBySideJson(comparison, localJson, remoteJson ) {
180180
<div class="json-compare">
181181
182182
<div>
183-
<b>Local</b>
184-
185-
${comparison.localError ? `<div class="json-error">${comparison.localError}</div>` : ''}
183+
<div class="compare-pane-title">
184+
<b>Local</b>
185+
${renderPayloadBadge(localJson)}
186+
</div>
186187
187188
${renderAlignedJson(comparison.local,localJson)}
188189
</div>
189190
190191
<div>
191-
<b>Remote</b>
192-
193-
${comparison.remoteError ? `<div class="json-error">${comparison.remoteError}</div>` : ''}
192+
<div class="compare-pane-title">
193+
<b>Remote</b>
194+
${renderPayloadBadge(remoteJson)}
195+
</div>
194196
195197
${renderAlignedJson(comparison.remote, remoteJson )}
196198
</div>
@@ -199,6 +201,49 @@ function renderSideBySideJson(comparison, localJson, remoteJson ) {
199201
`;
200202
}
201203

204+
function renderPayloadBadge(value) {
205+
206+
const payloadType = getPayloadType(value);
207+
208+
return `<span class="code-badge ${payloadType.className}">${payloadType.label}</span>`;
209+
}
210+
211+
function getPayloadType(value) {
212+
213+
if (!value || !value.trim()) {
214+
return {
215+
label: 'Empty',
216+
className: 'payload-empty'
217+
};
218+
}
219+
220+
try {
221+
JSON.parse(value);
222+
223+
return {
224+
label: 'JSON',
225+
className: 'payload-json'
226+
};
227+
} catch {
228+
return looksLikeJson(value)
229+
? {
230+
label: 'Invalid JSON',
231+
className: 'payload-invalid-json'
232+
}
233+
: {
234+
label: 'Plain Text',
235+
className: 'payload-text'
236+
};
237+
}
238+
}
239+
240+
function looksLikeJson(value) {
241+
242+
const trimmed = value.trimStart();
243+
244+
return trimmed.startsWith('{') || trimmed.startsWith('[');
245+
}
246+
202247
function renderAccordionSection(title, content, expanded = false, changes = 0) {
203248
return `
204249
<div class="accordion-section">
@@ -211,7 +256,7 @@ function renderAccordionSection(title, content, expanded = false, changes = 0) {
211256
212257
<div class="accordion-meta">
213258
214-
${changes > 0 ? `<span class="diff-badge">${changes}</span>` : ''}
259+
${changes > 0 ? `<span class="code-badge diff-badge">${changes}</span>` : ''}
215260
216261
<span class="accordion-toggle">
217262
${expanded ? '-' : '+'}
@@ -288,4 +333,4 @@ function escapeHtml(value) {
288333
.replace(/>/g, '&gt;')
289334
.replace(/"/g, '&quot;')
290335
.replace(/'/g, '&#39;');
291-
}
336+
}

0 commit comments

Comments
 (0)