diff --git a/viewer/render_test.go b/viewer/render_test.go index dc89068..1871517 100644 --- a/viewer/render_test.go +++ b/viewer/render_test.go @@ -48,7 +48,7 @@ func TestRenderHTMLIncludesKnownSectionsAndFields(t *testing.T) { } } for _, needle := range []string{ - ``, + ``, ``, ``, } { @@ -278,7 +278,7 @@ func TestRenderHTMLGroupsPCIeDevicesByClass(t *testing.T) { if strings.Contains(text, "device_class") { t.Fatalf("expected device_class column to be hidden from PCIe tables") } - if !strings.Contains(text, ``) { + if !strings.Contains(text, ``) { t.Fatalf("expected grouped PCIe tables to render compact status header cells") } if !strings.Contains(text, ``) { @@ -320,15 +320,12 @@ func TestRenderHTMLAddsSeverityFilterForEventLogs(t *testing.T) { text := string(html) for _, needle := range []string{ "Event Logs", - "All severities", - ``, - ``, `data-severity="critical"`, `data-severity="info"`, - ``, + ``, ``, ``, - `severity`, + `severity`, "/static/view.js", } { if !strings.Contains(text, needle) { @@ -400,9 +397,9 @@ func TestRenderHTMLDisplaysHardwareContract210Fields(t *testing.T) { "Storage", "Event Logs", "Platform Config", - "logical_block_size_bytes", - "physical_block_size_bytes", - "metadata_bytes_per_block", + `logical_block_size_bytes`, + `physical_block_size_bytes`, + `metadata_bytes_per_block`, "512", "4096", "8", diff --git a/web/static/view.css b/web/static/view.css index 72cf0e6..5af724d 100644 --- a/web/static/view.css +++ b/web/static/view.css @@ -330,41 +330,46 @@ body { display: block; } -.table-toolbar { - display: flex; - align-items: center; - gap: 10px; - margin: 0 0 10px; -} - -.table-toolbar-label { - color: var(--muted); - font-size: 12px; - font-weight: 700; - letter-spacing: 0.04em; - text-transform: uppercase; -} - -.table-severity-filter { - min-width: 180px; - border: 1px solid var(--border); - border-radius: 4px; - padding: 7px 10px; - background: var(--surface); - color: var(--ink); - font: inherit; -} - -.table-severity-filter:focus-visible { - outline: 2px solid var(--accent); - outline-offset: 2px; -} - .table-filter-empty { margin: 10px 0 0; color: var(--muted); } +.filter-row th { + background: var(--surface-2); + padding: 5px 8px; + border-top: 1px solid var(--border-lite); +} + +.col-filter-text { + width: 100%; + min-width: 40px; + border: 1px solid var(--border); + border-radius: 3px; + padding: 4px 6px; + font: inherit; + font-size: 12px; + background: var(--surface); + color: var(--ink); +} + +.col-filter-text:focus-visible { + outline: 2px solid var(--accent); + outline-offset: 1px; +} + +.col-filter-select { + width: 100%; + min-width: 40px; + border: 1px solid var(--border); + border-radius: 3px; + padding: 3px 4px; + font: inherit; + font-size: 12px; + background: var(--surface); + color: var(--ink); +} + .data-table .status-column { width: 1%; white-space: nowrap; @@ -425,13 +430,5 @@ body { grid-column: auto; } - .table-toolbar { - align-items: stretch; - flex-direction: column; - } - .table-severity-filter { - min-width: 0; - width: 100%; - } } diff --git a/web/static/view.js b/web/static/view.js index e6257c2..588c8cc 100644 --- a/web/static/view.js +++ b/web/static/view.js @@ -1,31 +1,100 @@ document.addEventListener("DOMContentLoaded", () => { document.querySelectorAll(".table-filterable").forEach((container) => { - const select = container.querySelector(".table-severity-filter"); - if (!select) { - return; + const table = container.querySelector(".data-table"); + if (!table) return; + + const thead = table.querySelector("thead"); + const headerRow = thead.querySelector("tr"); + const headerCells = Array.from(headerRow.querySelectorAll("th")); + const emptyNotice = container.querySelector(".table-filter-empty"); + const rows = Array.from(table.querySelectorAll("tbody tr")); + + const activeFilters = new Map(); + + function getCellValue(cell, colName) { + if (colName === "severity_icon" || colName === "status") { + return (cell.querySelector(".status-badge")?.title || "").toLowerCase(); + } + return cell.textContent.trim().toLowerCase(); } - const rows = Array.from(container.querySelectorAll("tbody tr[data-severity-row='true']")); - const emptyNotice = container.querySelector(".table-filter-empty"); - - const applyFilter = () => { - const selected = select.value; + function applyFilters() { let visibleCount = 0; - rows.forEach((row) => { - const matches = selected === "" || row.dataset.severity === selected; - row.hidden = !matches; - if (matches) { - visibleCount += 1; - } + const cells = row.querySelectorAll("td"); + let visible = true; + activeFilters.forEach((filterValue, colIndex) => { + if (!filterValue) return; + const cell = cells[colIndex]; + if (!cell) { visible = false; return; } + const colName = headerCells[colIndex]?.dataset.col || ""; + if (!getCellValue(cell, colName).includes(filterValue)) visible = false; + }); + row.hidden = !visible; + if (visible) visibleCount++; }); + if (emptyNotice) emptyNotice.hidden = visibleCount > 0; + } - if (emptyNotice) { - emptyNotice.hidden = visibleCount !== 0; + const filterRow = document.createElement("tr"); + filterRow.className = "filter-row"; + + headerCells.forEach((th, colIndex) => { + const colName = th.dataset.col || ""; + const filterTh = document.createElement("th"); + if (th.className) filterTh.className = th.className; + + const isIconCol = colName === "severity_icon" || colName === "status"; + + if (isIconCol) { + const select = document.createElement("select"); + select.className = "col-filter col-filter-select"; + select.setAttribute("aria-label", "filter " + (th.getAttribute("aria-label") || colName)); + const allOpt = document.createElement("option"); + allOpt.value = ""; + allOpt.textContent = "All"; + select.appendChild(allOpt); + + const seen = new Set(); + rows.forEach((row) => { + const cell = row.querySelectorAll("td")[colIndex]; + if (!cell) return; + const val = cell.querySelector(".status-badge")?.title || ""; + if (val && !seen.has(val)) { + seen.add(val); + const opt = document.createElement("option"); + opt.value = val.toLowerCase(); + opt.textContent = val; + select.appendChild(opt); + } + }); + + if (select.options.length > 1) { + select.addEventListener("change", () => { + activeFilters.set(colIndex, select.value); + applyFilters(); + }); + filterTh.appendChild(select); + } + } else if (colName) { + const input = document.createElement("input"); + input.type = "text"; + input.className = "col-filter col-filter-text"; + input.setAttribute("aria-label", "filter " + colName); + let debounceTimer; + input.addEventListener("input", () => { + clearTimeout(debounceTimer); + debounceTimer = setTimeout(() => { + activeFilters.set(colIndex, input.value.trim().toLowerCase()); + applyFilters(); + }, 300); + }); + filterTh.appendChild(input); } - }; - select.addEventListener("change", applyFilter); - applyFilter(); + filterRow.appendChild(filterTh); + }); + + thead.appendChild(filterRow); }); }); diff --git a/web/templates/view.html b/web/templates/view.html index cd8814a..6521a55 100644 --- a/web/templates/view.html +++ b/web/templates/view.html @@ -64,24 +64,13 @@ {{ if eq .Kind "table" }} {{ $section := . }} -
- {{ if .SeverityOptions }} -
- - -
- {{ end }} +
{{ range .Columns }} - {{ if and (ne . "status") (ne . "severity_icon") }}{{ . }}{{ end }} + {{ end }} @@ -108,9 +97,7 @@
{{ if and (ne . "status") (ne . "severity_icon") }}{{ . }}{{ end }}
- {{ if .SeverityOptions }} - - {{ end }} +
{{ end }} @@ -119,24 +106,13 @@

{{ .Title }}

{{ $group := . }} -
- {{ if .SeverityOptions }} -
- - -
- {{ end }} +
{{ range .Columns }} - {{ if and (ne . "status") (ne . "severity_icon") }}{{ . }}{{ end }} + {{ end }} @@ -163,9 +139,7 @@
{{ if and (ne . "status") (ne . "severity_icon") }}{{ . }}{{ end }}
- {{ if .SeverityOptions }} - - {{ end }} +
{{ end }}