Skip to content

Commit 506513e

Browse files
authored
Delay errors, with collapsed output (#272)
1 parent 9abdd9c commit 506513e

2 files changed

Lines changed: 71 additions & 8 deletions

File tree

ggsql-wasm/demo/src/quarto/main.ts

Lines changed: 42 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ interface CellInfo {
1919
error: string | null;
2020
editor: EditorInstance | null;
2121
errorDisplay: HTMLElement | null;
22+
errorTimerId: number | null;
2223
}
2324

2425
// ---------------------------------------------------------------------------
@@ -117,6 +118,7 @@ function gatherCells(): CellInfo[] {
117118
error: null,
118119
editor: null,
119120
errorDisplay: null,
121+
errorTimerId: null,
120122
});
121123
}
122124

@@ -246,14 +248,50 @@ async function applyEditors(
246248
}
247249
}
248250

251+
const ERROR_DELAY_MS = 1000;
252+
253+
function clearError(cell: CellInfo): void {
254+
if (cell.errorTimerId !== null) {
255+
clearTimeout(cell.errorTimerId);
256+
cell.errorTimerId = null;
257+
}
258+
const el = cell.errorDisplay!;
259+
el.innerHTML = "";
260+
el.classList.remove("visible", "collapsed");
261+
}
262+
263+
function showError(cell: CellInfo, message: string): void {
264+
clearError(cell);
265+
cell.errorTimerId = window.setTimeout(() => {
266+
cell.errorTimerId = null;
267+
const el = cell.errorDisplay!;
268+
el.innerHTML = "";
269+
270+
const toggle = document.createElement("span");
271+
toggle.className = "ggsql-error-toggle";
272+
toggle.textContent = "\u25B6";
273+
274+
const text = document.createElement("span");
275+
text.className = "ggsql-error-text";
276+
text.textContent = message;
277+
278+
el.appendChild(toggle);
279+
el.appendChild(text);
280+
el.classList.add("visible", "collapsed");
281+
282+
el.onclick = () => {
283+
const isCollapsed = el.classList.toggle("collapsed");
284+
toggle.textContent = isCollapsed ? "\u25B6" : "\u25BC";
285+
};
286+
}, ERROR_DELAY_MS);
287+
}
288+
249289
async function executeCell(
250290
cell: CellInfo,
251291
editorInst: EditorInstance,
252292
ctx: WasmContextManager
253293
): Promise<void> {
254-
const errorDisplay = cell.errorDisplay!;
255-
errorDisplay.textContent = "";
256-
errorDisplay.classList.remove("visible");
294+
clearError(cell);
257295

258296
const currentQuery = rewriteCsvRefs(editorInst.getValue());
259297

@@ -270,8 +308,7 @@ async function executeCell(
270308
ctx.executeSql(currentQuery);
271309
}
272310
} catch (e: any) {
273-
errorDisplay.textContent = String(e);
274-
errorDisplay.classList.add("visible");
311+
showError(cell, String(e));
275312
}
276313
}
277314

ggsql-wasm/demo/src/quarto/styles.css

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,41 @@
2424
color: #AE2012;
2525
background: #FFF0ED;
2626
border-top: 1px solid #E5A4A0;
27-
white-space: pre-wrap;
28-
word-break: break-word;
2927
display: none;
28+
cursor: pointer;
29+
gap: 6px;
30+
align-items: flex-start;
3031
}
3132

3233
.ggsql-editor-wrapper .monaco-editor .overflow-guard {
3334
touch-action: pan-y !important;
3435
}
3536

3637
.ggsql-error-display.visible {
37-
display: block;
38+
display: flex;
39+
}
40+
41+
.ggsql-error-toggle {
42+
flex-shrink: 0;
43+
font-size: 10px;
44+
line-height: 1.6;
45+
user-select: none;
46+
width: 1em;
47+
text-align: center;
48+
}
49+
50+
.ggsql-error-text {
51+
flex: 1;
52+
min-width: 0;
53+
}
54+
55+
.ggsql-error-display.collapsed .ggsql-error-text {
56+
white-space: nowrap;
57+
overflow: hidden;
58+
text-overflow: ellipsis;
59+
}
60+
61+
.ggsql-error-display:not(.collapsed) .ggsql-error-text {
62+
white-space: pre-wrap;
63+
word-break: break-word;
3864
}

0 commit comments

Comments
 (0)