Skip to content

Commit 01aa580

Browse files
committed
Add config for max number of rows for json before scrollinga
1 parent 57c2dc0 commit 01aa580

3 files changed

Lines changed: 68 additions & 4 deletions

File tree

debug-db-base/src/main/assets/custom.css

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ body.addb-sidebar-compact #table-list .list-group-item {
7878
:root {
7979
--addb-max-col-width: 480px;
8080
--addb-sticky-header-top: 50px;
81+
--addb-json-max-lines: 10;
8182
}
8283

8384
body.addb-sticky-header #parent-data-div .dataTables_scrollHead {
@@ -128,6 +129,14 @@ body.addb-json-mode-wrapped #parent-data-div table.dataTable td.addb-json-cell {
128129
vertical-align: top;
129130
}
130131

132+
body.addb-json-mode-wrapped #parent-data-div table.dataTable td.addb-json-cell .addb-json-text {
133+
display: block;
134+
line-height: 1.25;
135+
max-height: calc(var(--addb-json-max-lines) * 1.25em);
136+
overflow-y: auto;
137+
padding-right: 6px;
138+
}
139+
131140
body.addb-json-mode-pretty #parent-data-div table.dataTable td.addb-json-cell {
132141
white-space: pre;
133142
font-family: Menlo, Monaco, Consolas, "Courier New", monospace;
@@ -143,6 +152,11 @@ body.addb-max-col-width.addb-json-mode-pretty #parent-data-div table.dataTable t
143152

144153
body.addb-json-mode-pretty #parent-data-div table.dataTable td.addb-json-cell .addb-json-tree {
145154
display: inline-block;
155+
line-height: 1.25;
156+
max-height: calc(var(--addb-json-max-lines) * 1.25em);
157+
overflow-y: auto;
158+
overflow-x: visible;
159+
padding-right: 6px;
146160
}
147161

148162
#parent-data-div table.dataTable td.addb-json-cell .addb-json-line {

debug-db-base/src/main/assets/index.html

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,15 @@
260260
</select>
261261
<p class="help-block">Applies to cells that contain valid JSON objects/arrays.</p>
262262
</div>
263+
264+
<div class="form-group">
265+
<label for="addb-json-max-lines">Max JSON lines (before scrolling)</label>
266+
<div class="input-group addb-max-width-input">
267+
<input type="number" class="form-control" id="addb-json-max-lines" placeholder="e.g. 10" min="1" max="200" step="1">
268+
<span class="input-group-addon">lines</span>
269+
</div>
270+
<p class="help-block">Limits row height when JSON is wrapped or pretty-printed.</p>
271+
</div>
263272
</div>
264273

265274
<div class="addb-customize-category display-none" data-category="paging">

debug-db-base/src/main/assets/ui-customization.js

Lines changed: 45 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
wrapLongText: false,
1818
maxColumnWidthPx: null, // number | null
1919
jsonMode: "raw", // raw | wrapped | pretty
20+
jsonMaxLines: 10, // number (limits cell height when JSON is shown)
2021
stickyHeader: false,
2122
pageLength: 10 // 10 | 25 | 50 | 100
2223
};
@@ -112,6 +113,16 @@
112113
}
113114
}
114115

116+
var jsonMaxLinesRaw = raw.jsonMaxLines;
117+
if (jsonMaxLinesRaw === "" || jsonMaxLinesRaw === null || typeof jsonMaxLinesRaw === "undefined") {
118+
settings.jsonMaxLines = DEFAULT_SETTINGS.jsonMaxLines;
119+
} else {
120+
var parsedJsonMaxLines = parseInt(jsonMaxLinesRaw, 10);
121+
if (!isNaN(parsedJsonMaxLines)) {
122+
settings.jsonMaxLines = clampInt(parsedJsonMaxLines, 1, 200);
123+
}
124+
}
125+
115126
return settings;
116127
}
117128

@@ -206,6 +217,15 @@
206217
}
207218
}
208219

220+
function applyJsonMaxLines(settings) {
221+
var jsonMaxLines =
222+
typeof settings.jsonMaxLines === "number" && settings.jsonMaxLines > 0
223+
? settings.jsonMaxLines
224+
: DEFAULT_SETTINGS.jsonMaxLines;
225+
226+
document.documentElement.style.setProperty("--addb-json-max-lines", String(jsonMaxLines));
227+
}
228+
209229
function looksLikeJson(value) {
210230
if (typeof value !== "string") return false;
211231
var trimmed = value.trim();
@@ -372,6 +392,26 @@
372392
}, 0);
373393
}
374394

395+
function renderWrappedJsonCell(td, jsonText) {
396+
if (
397+
td.childNodes.length === 1 &&
398+
td.firstChild &&
399+
td.firstChild.nodeType === 1 &&
400+
td.firstChild.classList &&
401+
td.firstChild.classList.contains("addb-json-text") &&
402+
td.firstChild.textContent === jsonText
403+
) {
404+
return false;
405+
}
406+
407+
td.textContent = "";
408+
var wrapper = document.createElement("div");
409+
wrapper.className = "addb-json-text";
410+
wrapper.textContent = jsonText;
411+
td.appendChild(wrapper);
412+
return true;
413+
}
414+
375415
function applyJsonFormattingToCurrentPage(dataTableApi, settings) {
376416
if (!dataTableApi) return;
377417

@@ -404,10 +444,7 @@
404444

405445
if (mode === "wrapped") {
406446
// Keep raw JSON text, but apply JSON cell styling.
407-
if (td.textContent !== cellData || td.childNodes.length !== 1 || td.firstChild.nodeType !== 3) {
408-
td.textContent = cellData;
409-
didMutateDom = true;
410-
}
447+
if (renderWrappedJsonCell(td, cellData)) didMutateDom = true;
411448
continue;
412449
}
413450

@@ -460,6 +497,7 @@
460497
applySidebarWidth(currentSettings);
461498
applyBodyClasses(currentSettings);
462499
applyMaxColumnWidth(currentSettings);
500+
applyJsonMaxLines(currentSettings);
463501

464502
var dataTableReason = reason;
465503
if (previousSettings.jsonMode !== currentSettings.jsonMode) dataTableReason = "jsonMode";
@@ -583,13 +621,15 @@
583621

584622
function readDraftFromForm() {
585623
var maxWidthRaw = $("#addb-max-column-width").val();
624+
var jsonMaxLinesRaw = $("#addb-json-max-lines").val();
586625
var settings = {
587626
tableWidth: $("input[name='addb-table-width']:checked").val(),
588627
sidebarWidth: $("input[name='addb-sidebar-width']:checked").val(),
589628
rowDensity: $("input[name='addb-row-density']:checked").val(),
590629
wrapLongText: $("#addb-wrap-long-text").is(":checked"),
591630
maxColumnWidthPx: maxWidthRaw === "" ? null : maxWidthRaw,
592631
jsonMode: $("#addb-json-mode").val(),
632+
jsonMaxLines: jsonMaxLinesRaw,
593633
stickyHeader: $("#addb-sticky-header").is(":checked"),
594634
pageLength: $("#addb-page-length").val()
595635
};
@@ -603,6 +643,7 @@
603643
$("#addb-wrap-long-text").prop("checked", !!settings.wrapLongText);
604644
$("#addb-max-column-width").val(settings.maxColumnWidthPx === null ? "" : settings.maxColumnWidthPx);
605645
$("#addb-json-mode").val(settings.jsonMode);
646+
$("#addb-json-max-lines").val(String(settings.jsonMaxLines));
606647
$("#addb-sticky-header").prop("checked", !!settings.stickyHeader);
607648
$("#addb-page-length").val(String(settings.pageLength));
608649
}

0 commit comments

Comments
 (0)