diff --git a/changelog.d/added-16042-matrix-header-tab.md b/changelog.d/added-16042-matrix-header-tab.md new file mode 100644 index 0000000000..232fe22048 --- /dev/null +++ b/changelog.d/added-16042-matrix-header-tab.md @@ -0,0 +1 @@ +- Add a Matrix tab to the Activity Monitor header, shown only when `dashboard.matrix.enabled` is set; the status payload gains an additive `matrixEnabled` boolean (#16042, RFC #15862). diff --git a/src/docs/streaming-the-activity-monitor.md b/src/docs/streaming-the-activity-monitor.md index 32a4f02d12..a8bc468117 100644 --- a/src/docs/streaming-the-activity-monitor.md +++ b/src/docs/streaming-the-activity-monitor.md @@ -189,6 +189,8 @@ full-screen Activity Monitor. ## Matrix mode (separate channel) +When `dashboard.matrix.enabled` is set, the Activity Monitor header also shows a **Matrix** tab that opens `?kiosk=1&view=matrix` in the same window. + Matrix is an experimental, default-off code display for a separate channel, [`twitch.tv/hivecommonsmatrix`](https://www.twitch.tv/hivecommonsmatrix). It depends on the Matrix display renderer (`/?kiosk=1&view=matrix`, diff --git a/src/pkg/dashboard/matrix_header_tab_test.go b/src/pkg/dashboard/matrix_header_tab_test.go new file mode 100644 index 0000000000..84fe806882 --- /dev/null +++ b/src/pkg/dashboard/matrix_header_tab_test.go @@ -0,0 +1,52 @@ +package dashboard + +import ( + "encoding/json" + "net/http" + "net/http/httptest" + "strings" + "testing" + + "github.com/hivecommons/hive/pkg/config" +) + +func TestDashboardMatrixHeaderTabHiddenByDefault(t *testing.T) { + raw, err := staticFS.ReadFile("static/index.html") + if err != nil { + t.Fatalf("reading embedded static/index.html: %v", err) + } + html := string(raw) + start := strings.Index(html, `id="oc-matrix-tab"`) + if start < 0 { + t.Fatal("static/index.html missing the Matrix header tab") + } + open := html[strings.LastIndex(html[:start], "")] + for _, want := range []string{`href="?kiosk=1&view=matrix"`, ` hidden`, `nav-chip`} { + if !strings.Contains(open, want) { + t.Fatalf("Matrix header tab %q missing %q", open, want) + } + } + if !strings.Contains(html, "data.matrixEnabled") { + t.Fatal("static/index.html never toggles the Matrix tab from the status payload") + } +} + +func TestHandleStatus_MatrixEnabledFlag(t *testing.T) { + for _, enabled := range []bool{false, true} { + s := newTestServer() + s.MatrixObserver(config.MatrixConfig{Enabled: enabled, Repos: []string{"org/repo"}}) + s.UpdateStatus(minimalPayload()) + + rec := httptest.NewRecorder() + s.handleStatus(rec, httptest.NewRequest(http.MethodGet, "/api/status", nil)) + + var raw map[string]any + if err := json.NewDecoder(rec.Body).Decode(&raw); err != nil { + t.Fatalf("decode error: %v", err) + } + if got, ok := raw["matrixEnabled"].(bool); !ok || got != enabled { + t.Errorf("matrixEnabled = %v (present=%v), want %v", raw["matrixEnabled"], ok, enabled) + } + } +} diff --git a/src/pkg/dashboard/server.go b/src/pkg/dashboard/server.go index 632b27f46b..a97c03d51f 100644 --- a/src/pkg/dashboard/server.go +++ b/src/pkg/dashboard/server.go @@ -3719,7 +3719,7 @@ func (s *Server) handleStatus(w http.ResponseWriter, r *http.Request) { return } now := time.Now().UTC() - payload := statusWithWebhooks{StatusPayload: s.statusWithOverviewBands(status, now), Webhooks: github.WebhookHealthSnapshot(), CIFailureSignals: github.CIFailureSignals().Snapshot()} + payload := statusWithWebhooks{StatusPayload: s.statusWithOverviewBands(status, now), Webhooks: github.WebhookHealthSnapshot(), CIFailureSignals: github.CIFailureSignals().Snapshot(), MatrixEnabled: s.currentMatrixConfig().Active()} if s.deps != nil && s.deps.EvalLoop != nil { loop := s.deps.EvalLoop() payload.EvalLoopStatus = &loop @@ -3740,6 +3740,10 @@ type statusWithWebhooks struct { // signals, the last one, webhook-triggered kicks and unmatched heads. CIFailureSignals github.CIFailureSignalsStatus `json:"ci_failure_signals"` *EvalLoopStatus + // MatrixEnabled reports whether the Matrix block is active (enabled with + // at least one repo, see config.MatrixConfig.Active) so the header shows + // the Matrix tab only on hives whose /api/matrix/lines will serve it. + MatrixEnabled bool `json:"matrixEnabled"` // UpgradeProgress is the spoke's view of the scheduled-upgrade state // machine (scheduled / draining / pulling / … / missed) with the drain // countdown, derived at serve time (#14856). Absent on a hive the hub diff --git a/src/pkg/dashboard/settings_parity_allowlist.txt b/src/pkg/dashboard/settings_parity_allowlist.txt index ce7bf641d3..8ffbfd74fd 100644 --- a/src/pkg/dashboard/settings_parity_allowlist.txt +++ b/src/pkg/dashboard/settings_parity_allowlist.txt @@ -182,7 +182,7 @@ compliance.frameworks[] # TODO #11854 contribute.token_idle_max # TODO #11854 contribute.token_max_age # TODO #11854 convergence.mutation.max_writers_per_target # boundary capacity tuning; yaml-only (#14645) -dashboard.matrix.enabled # experimental default-off Matrix block; nothing reads it yet (#15862) +dashboard.matrix.enabled # experimental default-off Matrix block; gates the header tab via /api/status, no Settings control (#15862, #16042) dashboard.matrix.exclude_paths[] # experimental default-off Matrix block; nothing reads it yet (#15862) dashboard.matrix.repos[] # experimental default-off Matrix block; nothing reads it yet (#15862) debug.pprof_addr # loopback-only pprof bind address, operator/debug knob, not a Settings control (#14681) diff --git a/src/pkg/dashboard/static-src/html/topbar.html b/src/pkg/dashboard/static-src/html/topbar.html index d6696d7d0f..2b07aaeb9d 100644 --- a/src/pkg/dashboard/static-src/html/topbar.html +++ b/src/pkg/dashboard/static-src/html/topbar.html @@ -25,6 +25,7 @@
+ diff --git a/src/pkg/dashboard/static-src/js/refresh.js b/src/pkg/dashboard/static-src/js/refresh.js index 22116f0c01..beda121ede 100644 --- a/src/pkg/dashboard/static-src/js/refresh.js +++ b/src/pkg/dashboard/static-src/js/refresh.js @@ -484,6 +484,10 @@ if (data.statusSeq < _statusSeqFloor || data.statusSeq < _lastStatusSeq) return; _lastStatusSeq = data.statusSeq; } + if (typeof data.matrixEnabled === 'boolean') { + const matrixTab = document.getElementById('oc-matrix-tab'); + if (matrixTab) matrixTab.hidden = !data.matrixEnabled; + } if (document.body.style.opacity === '0') document.body.style.opacity = '1'; const scrollAnchor = captureScrollAnchor(); updateNavbarClockTimeZone(data); diff --git a/src/pkg/dashboard/static/index.html b/src/pkg/dashboard/static/index.html index f86e9fe8dd..95e2787a95 100644 --- a/src/pkg/dashboard/static/index.html +++ b/src/pkg/dashboard/static/index.html @@ -7760,6 +7760,7 @@

🐝 Getting Started + @@ -43863,6 +43864,10 @@ if (data.statusSeq < _statusSeqFloor || data.statusSeq < _lastStatusSeq) return; _lastStatusSeq = data.statusSeq; } + if (typeof data.matrixEnabled === 'boolean') { + const matrixTab = document.getElementById('oc-matrix-tab'); + if (matrixTab) matrixTab.hidden = !data.matrixEnabled; + } if (document.body.style.opacity === '0') document.body.style.opacity = '1'; const scrollAnchor = captureScrollAnchor(); updateNavbarClockTimeZone(data);