Skip to content

Commit 4ccb9c9

Browse files
committed
Use a table instead of divs, and get styling correct.
1 parent 10aec6e commit 4ccb9c9

File tree

5 files changed

+90
-50
lines changed

5 files changed

+90
-50
lines changed

FrontEnd/scripts/debug_panel.js

Lines changed: 42 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,44 +19,73 @@ export class SPIDebugPanel extends HTMLElement {
1919
// into the browser console.
2020
if (localStorage.getItem('spiDebug') === 'true') {
2121
this.classList.remove('hidden')
22+
23+
this.reset()
24+
this.addButtons()
2225
this.addCanonicalUrls()
2326
}
27+
}
28+
29+
disconnectedCallback() {
30+
console.log('SPIDebugPanel disconnectedCallback')
31+
}
32+
33+
reset() {
34+
const buttonsContainer = this.querySelector('.buttons')
35+
if (buttonsContainer) buttonsContainer.remove()
2436

25-
this.querySelector('.buttons > .hide').addEventListener('click', () => {
37+
const dynamicRowElements = this.querySelectorAll('tr:not([server-side])')
38+
dynamicRowElements.forEach((row) => row.remove())
39+
}
40+
41+
addButtons() {
42+
const hideButton = document.createElement('button')
43+
hideButton.innerText = 'Hide'
44+
hideButton.title = 'Temporarily hide this panel'
45+
hideButton.addEventListener('click', () => {
2646
this.classList.add('hidden')
2747
})
2848

29-
this.querySelector('.buttons > .disable').addEventListener('click', () => {
30-
this.classList.add('hidden')
49+
const disableButton = document.createElement('button')
50+
disableButton.innerText = 'Disable'
51+
disableButton.title = 'Disable the debug panel'
52+
disableButton.addEventListener('click', () => {
3153
localStorage.setItem('spiDebug', 'false')
54+
this.classList.add('hidden')
3255
})
33-
}
3456

35-
disconnectedCallback() {
36-
console.log('SPIDebugPanel disconnectedCallback')
57+
const buttonsContainer = document.createElement('div')
58+
buttonsContainer.classList.add('buttons')
59+
buttonsContainer.appendChild(hideButton)
60+
buttonsContainer.appendChild(disableButton)
61+
this.prepend(buttonsContainer)
3762
}
3863

39-
newTableRow(title, value) {
64+
newTableRow(title, value, valueCssClass) {
65+
const tableElement = this.querySelector('table > tbody')
4066
const rowElement = document.createElement('tr')
4167

4268
const titleCellElement = document.createElement('td')
4369
titleCellElement.innerText = title
4470

71+
const valueSpanElement = document.createElement('span')
72+
valueSpanElement.innerText = value
4573
const valueCellElement = document.createElement('td')
46-
valueCellElement.innerText = value
74+
valueCellElement.appendChild(valueSpanElement)
75+
if (valueCssClass) valueCellElement.classList.add(valueCssClass)
4776

4877
rowElement.appendChild(titleCellElement)
4978
rowElement.appendChild(valueCellElement)
50-
return rowElement
79+
tableElement.appendChild(rowElement)
5180
}
5281

5382
addCanonicalUrls() {
54-
const tableElement = this.querySelector('table')
5583
const canonicalUrl = document.querySelector('link[rel="canonical"]').href
5684
const windowUrl = window.location.href
85+
const matchingCanonicalUrl = canonicalUrl === windowUrl
5786

58-
tableElement.appendChild(this.newTableRow('Canonical URL', canonicalUrl))
59-
tableElement.appendChild(this.newTableRow('Window URL', windowUrl))
60-
tableElement.appendChild(this.newTableRow('URLs Match', canonicalUrl === windowUrl))
87+
this.newTableRow('Canonical URL', canonicalUrl)
88+
this.newTableRow('Window URL', windowUrl)
89+
this.newTableRow('Canonical Match', matchingCanonicalUrl, matchingCanonicalUrl ? 'green' : 'red')
6190
}
6291
}

FrontEnd/styles/debug_panel.scss

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ spi-debug-panel {
2525
overflow-y: auto;
2626
max-height: 500px;
2727
min-height: 100px;
28+
padding: 18px;
2829
background-color: var(--debug-console-background);
2930
border-top: 1px solid var(--debug-console-border);
3031

@@ -38,7 +39,7 @@ spi-debug-panel {
3839

3940
button {
4041
cursor: pointer;
41-
padding: 2px 6px;
42+
padding: 0 6px;
4243
font-size: 10px;
4344
color: var(--page-text);
4445
background: none;
@@ -52,15 +53,37 @@ spi-debug-panel {
5253
}
5354
}
5455

55-
[data-debug-console-target='grid'] {
56-
display: grid;
57-
grid-template-columns: min-content 1fr;
58-
gap: 3px 20px;
59-
padding: 5px;
56+
table {
57+
width: 100%;
58+
border-collapse: collapse;
59+
60+
tr {
61+
> td:first-child {
62+
width: 20%;
63+
font-size: 14px;
64+
font-weight: 600;
65+
white-space: nowrap;
66+
}
67+
68+
> td:last-child {
69+
width: 80%;
70+
font-family: monospace;
71+
font-size: 12px;
72+
}
73+
}
74+
75+
td > span {
76+
padding: 3px;
77+
}
78+
79+
td.green > span {
80+
color: var(--very-light-grey);
81+
background-color: var(--mid-green);
82+
}
6083

61-
tr > td:first-child {
62-
font-weight: 600;
63-
white-space: nowrap;
84+
td.red > span {
85+
color: var(--very-light-grey);
86+
background-color: var(--mid-red);
6487
}
6588
}
6689
}

Sources/App/Views/DocumentationPageProcessor.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ struct DocumentationPageProcessor {
293293
}
294294

295295
var frontEndDebugPanel: String {
296-
Plot.Node<HTML.BodyContext>.spiFrontEndDebugConsole(dataItems: []).render()
296+
Plot.Node<HTML.BodyContext>.spiFrontEndDebugPanel(dataItems: []).render()
297297
}
298298

299299
var processedPage: String {

Sources/App/Views/Plot+Extensions.swift

Lines changed: 14 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -207,36 +207,24 @@ extension Node where Context: HTML.BodyContext {
207207
)
208208
}
209209

210-
static func spiFrontEndDebugConsole(dataItems: [PublicPage.DebugConsoleDataItem]) -> Node<HTML.BodyContext> {
210+
static func spiFrontEndDebugPanel(dataItems: [PublicPage.DebugConsoleDataItem]) -> Node<HTML.BodyContext> {
211211
.element(named: "spi-debug-panel", nodes: [
212212
.class("hidden"),
213-
.div(
214-
.class("buttons"),
215-
.button(
216-
.class("hide"),
217-
.text("Hide"),
218-
.title("Temporarily hide this panel")
219-
),
220-
.button(
221-
.class("disable"),
222-
.text("Disable"),
223-
.title("Disable the debug console")
224-
)
225-
),
226213
.table(
227-
.class("grid"),
228-
.group(
229-
dataItems.map({ dataItem -> Node<HTML.TableContext> in
230-
.tr(
231-
.class("server-side"),
232-
.td(
233-
.text(dataItem.title)
234-
),
235-
.td(
236-
.text(dataItem.value)
214+
.tbody(
215+
.group(
216+
dataItems.map({ dataItem -> Node<HTML.TableContext> in
217+
.tr(
218+
.attribute(named: "server-side"),
219+
.td(
220+
.text(dataItem.title)
221+
),
222+
.td(
223+
.text(dataItem.value)
224+
)
237225
)
238-
)
239-
})
226+
})
227+
)
240228
)
241229
)
242230
])

Sources/App/Views/PublicPage.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,7 @@ class PublicPage {
465465
/// Output a hidden-by-default panel on the page showing useful debug information
466466
/// - Returns: The HTML for the debug console element.
467467
final func frontEndDebugConsole() -> Node<HTML.BodyContext> {
468-
.spiFrontEndDebugConsole(dataItems: frontEndDebugConsoleData())
468+
.spiFrontEndDebugPanel(dataItems: frontEndDebugConsoleData())
469469
}
470470

471471
/// Returns the debug information that a page would like to show in the front-end debug console.

0 commit comments

Comments
 (0)