refactor(tui): move maintenance from sidebar to bottom strip

Replace the cramped 22-char maint sidebar with a full-width bottom
strip in the same position as logs. Bottom panel is modal: l for logs,
m for maint, same key again to close. Maint strip shows one row per
window with icon, title, affected monitors, and status/time remaining.

Removes maintSidebarW constant and maintOffset field. Introduces
bottomPanel enum (bottomNone/bottomLogs/bottomMaint) replacing
logsOpen and maintOpen booleans. m key no longer gated behind
wideBreakpoint.
This commit is contained in:
2026-06-30 22:47:50 -04:00
parent f7303c946c
commit e3d681311f
4 changed files with 82 additions and 89 deletions
+10 -4
View File
@@ -95,6 +95,14 @@ const (
panelMaint = 3
)
type bottomPanel int
const (
bottomNone bottomPanel = iota
bottomLogs
bottomMaint
)
const (
detailDefault = 0
detailSLA = 1
@@ -198,11 +206,9 @@ type Model struct {
lastTabLoad time.Time // last dispatch of loadTabDataCmd (throttle)
tabSeq int // seq of the newest issued tab-data load
logsOpen bool
bottomPanel bottomPanel
detailOpen bool
maintOpen bool
maintCursor int
maintOffset int
detailChanges []models.StateChange
detailChangesSiteID int
detailDailyDays []monitor.DayReport
@@ -249,7 +255,7 @@ func InitialModel(ctx context.Context, isAdmin bool, s store.Store, eng *monitor
theme: theme,
themeIndex: themeIdx,
st: newStyles(theme),
logsOpen: true,
bottomPanel: bottomLogs,
detailOpen: detailPref == "true",
demoMode: os.Getenv("UPTOP_DEMO") == "1",
version: version,
+14 -16
View File
@@ -157,7 +157,7 @@ func (m *Model) recalcLayout() {
if m.filterMode || m.filterText != "" {
chrome++
}
if m.logsOpen {
if m.bottomPanel != bottomNone {
chrome += logsStripHeight
}
m.maxTableRows = m.termHeight - chrome
@@ -580,22 +580,20 @@ func (m *Model) handleDashboardKey(msg tea.KeyMsg) (tea.Model, tea.Cmd) {
m.sortAsc = !m.sortAsc
m.refreshLive()
case "m":
if m.termWidth >= wideBreakpoint {
if m.focusedPanel == panelMaint {
m.maintOpen = false
m.focusedPanel = panelMonitors
} else {
m.maintOpen = true
m.focusedPanel = panelMaint
}
m.recalcLayout()
}
case "l":
if m.logsOpen {
m.logsOpen = false
if m.bottomPanel == bottomMaint {
m.bottomPanel = bottomNone
m.focusedPanel = panelMonitors
} else {
m.logsOpen = true
m.bottomPanel = bottomMaint
m.focusedPanel = panelMaint
}
m.recalcLayout()
case "l":
if m.bottomPanel == bottomLogs {
m.bottomPanel = bottomNone
m.focusedPanel = panelMonitors
} else {
m.bottomPanel = bottomLogs
m.focusedPanel = panelLogs
}
m.recalcLayout()
@@ -868,7 +866,7 @@ func (m *Model) handleClick(msg tea.MouseMsg) (tea.Model, tea.Cmd) {
}
}
if m.maintOpen && m.zones.Get("panel-maint").InBounds(msg) {
if m.bottomPanel == bottomMaint && m.zones.Get("panel-maint").InBounds(msg) {
m.focusedPanel = panelMaint
return m, nil
} else if m.zones.Get("panel-monitors").InBounds(msg) {
+14 -24
View File
@@ -143,28 +143,18 @@ func (m Model) computeStats() dashboardStats {
return s
}
const maintSidebarW = 22
func (m Model) viewMonitorsLayout() string {
availW := m.termWidth - chromePadH
wide := m.termWidth >= wideBreakpoint
showMaint := m.maintOpen && wide
showDetail := m.detailOpen && wide
var maintW, detailW, monW int
if showMaint {
maintW = maintSidebarW
if maintW > availW/4 {
maintW = availW / 4
}
}
remaining := availW - maintW
var detailW, monW int
if showDetail {
monW = remaining * 60 / 100
detailW = remaining - monW
monW = availW * 60 / 100
detailW = availW - monW
} else {
monW = remaining
monW = availW
}
m.contentWidth = monW - 2
@@ -173,11 +163,6 @@ func (m Model) viewMonitorsLayout() string {
monPanel := m.zones.Mark("panel-monitors", m.titledPanel("Monitors", monitors, monW, m.focusedPanel == panelMonitors))
var topParts []string
if showMaint {
sidebar := m.viewMaintSidebar(maintW-2, m.maxTableRows)
maintPanel := m.zones.Mark("panel-maint", m.titledPanel("Maint", sidebar, maintW, m.focusedPanel == panelMaint))
topParts = append(topParts, maintPanel)
}
topParts = append(topParts, monPanel)
if showDetail {
title := ""
@@ -199,10 +184,15 @@ func (m Model) viewMonitorsLayout() string {
top := lipgloss.JoinHorizontal(lipgloss.Top, topParts...)
if m.logsOpen {
switch m.bottomPanel {
case bottomLogs:
logContent := m.viewLogsStrip(availW-2, logsStripHeight-2)
logPanel := m.zones.Mark("panel-logs", m.titledPanel("Logs", logContent, availW, m.focusedPanel == panelLogs))
return top + "\n" + logPanel
case bottomMaint:
maintContent := m.viewMaintStrip(availW-2, logsStripHeight-2)
maintPanel := m.zones.Mark("panel-maint", m.titledPanel("Maint", maintContent, availW, m.focusedPanel == panelMaint))
return top + "\n" + maintPanel
}
return top
}
@@ -296,7 +286,7 @@ func (m Model) renderFooter(_ dashboardStats) string {
var parts []string
if m.focusedPanel == panelMaint {
parts = []string{m.hotkey("n", "New"), m.hotkey("x", "End"), m.hotkey("d", "Del"), m.hotkey("Esc", "Back")}
parts = []string{m.hotkey("n", "New"), m.hotkey("Enter", "Detail"), m.hotkey("x", "End"), m.hotkey("d", "Del"), m.hotkey("m/Esc", "Back")}
} else if m.focusedPanel == panelLogs {
parts = []string{m.hotkey("↑/↓", "Scroll"), m.hotkey("Enter", "Expand"), m.hotkey("l/Esc", "Back")}
} else if m.detailOpen && m.detailMode == detailSLA {
@@ -304,7 +294,7 @@ func (m Model) renderFooter(_ dashboardStats) string {
} else if m.detailOpen && m.detailMode == detailHistory {
parts = []string{m.hotkey("Esc", "Back")}
} else if m.detailOpen {
parts = []string{m.hotkey("Enter", "Close"), m.hotkey("h", "History"), m.hotkey("s", "SLA"), m.hotkey("e", "Edit"), m.hotkey("m", "Maint")}
parts = []string{m.hotkey("Enter", "Close"), m.hotkey("h", "History"), m.hotkey("s", "SLA"), m.hotkey("e", "Edit")}
} else {
parts = []string{m.hotkey("/", "Filter"), m.hotkey("Enter", "Detail")}
if m.cursor < len(m.sites) && m.sites[m.cursor].Type == "group" {
@@ -314,9 +304,9 @@ func (m Model) renderFooter(_ dashboardStats) string {
parts = append(parts, m.hotkey("Space", "Collapse"))
}
}
parts = append(parts, m.hotkey("n", "New"), m.hotkey("e", "Edit"), m.hotkey("d", "Del"), m.hotkey("m", "Maint"))
parts = append(parts, m.hotkey("n", "New"), m.hotkey("e", "Edit"), m.hotkey("d", "Del"))
}
parts = append(parts, m.hotkey("l", "Logs"), m.hotkey("S", "Settings"), m.hotkey("T", "Theme"), m.hotkey("q", "Quit"))
parts = append(parts, m.hotkey("m", "Maint"), m.hotkey("l", "Logs"), m.hotkey("S", "Settings"), m.hotkey("T", "Theme"), m.hotkey("q", "Quit"))
line := strings.Join(parts, dot)
if m.filterText != "" {
+44 -45
View File
@@ -85,6 +85,15 @@ func (m Model) viewMaintDetailPanel() string {
return lipgloss.NewStyle().Padding(1, 2).Render(b.String())
}
func (m Model) monitorNameByID(id int) string {
for _, s := range m.engine.GetAllSites() {
if s.ID == id {
return s.Name
}
}
return fmt.Sprintf("#%d", id)
}
func (m Model) activeMaintWindows() []models.MaintenanceWindow {
now := time.Now()
var out []models.MaintenanceWindow
@@ -97,31 +106,28 @@ func (m Model) activeMaintWindows() []models.MaintenanceWindow {
return out
}
func (m Model) viewMaintSidebar(width, maxLines int) string {
func (m Model) viewMaintStrip(width, maxLines int) string {
windows := m.activeMaintWindows()
if len(windows) == 0 {
return m.st.subtleStyle.Render(" No active maintenance")
return m.st.subtleStyle.Render(" No active maintenance")
}
contentW := width - 2
if contentW < 10 {
contentW = 10
}
start := m.maintOffset
if start > len(windows) {
start = len(windows)
}
linesUsed := 0
end := start
for end < len(windows) && linesUsed+2 <= maxLines {
linesUsed += 2
end++
}
var lines []string
now := time.Now()
for i := start; i < end; i++ {
titleW := 30
monW := 20
if width < 80 {
titleW = width / 3
monW = width / 5
}
end := maxLines
if end > len(windows) {
end = len(windows)
}
style := lipgloss.NewStyle().Width(width).MaxWidth(width)
var lines []string
for i := 0; i < end; i++ {
mw := windows[i]
selected := m.focusedPanel == panelMaint && i == m.maintCursor
@@ -134,37 +140,40 @@ func (m Model) viewMaintSidebar(width, maxLines int) string {
icon = m.st.warnStyle.Render("○")
}
title := limitStr(mw.Title, contentW-3)
titleLine := " " + icon + " " + title
title := limitStr(mw.Title, titleW)
var detail string
monName := "All Monitors"
if mw.MonitorID > 0 {
monName = m.monitorNameByID(mw.MonitorID)
}
monName = limitStr(monName, monW)
var status string
if isActive {
if mw.EndTime.IsZero() {
detail = m.st.subtleStyle.Render("active · indefinite")
status = m.st.subtleStyle.Render("active · indefinite")
} else {
remaining := time.Until(mw.EndTime)
detail = m.st.subtleStyle.Render("active · " + fmtDuration(remaining))
status = m.st.subtleStyle.Render("active · " + fmtDuration(time.Until(mw.EndTime)) + " left")
}
} else {
detail = m.st.subtleStyle.Render(mw.StartTime.Format("Jan 02") + " · " + fmtDuration(mw.EndTime.Sub(mw.StartTime)))
status = m.st.subtleStyle.Render("scheduled · " + mw.StartTime.Format("Jan 02 15:04"))
}
detailLine := " " + limitStr(detail, contentW-3)
line := fmt.Sprintf(" %s %-*s %-*s %s", icon, titleW, title, monW, m.st.subtleStyle.Render(monName), status)
if selected {
sel := m.st.tableSelectedStyle
titleLine = sel.Render(lipgloss.NewStyle().Width(contentW).Render(titleLine))
detailLine = sel.Render(lipgloss.NewStyle().Width(contentW).Render(detailLine))
line = m.st.tableSelectedStyle.Render(lipgloss.NewStyle().Width(width).Render(line))
}
lines = append(lines, titleLine, detailLine)
lines = append(lines, line)
}
if len(windows) > end-start {
more := fmt.Sprintf(" %d more", len(windows)-(end-start))
if len(windows) > end {
more := fmt.Sprintf(" %d more", len(windows)-end)
lines = append(lines, m.st.subtleStyle.Render(more))
}
return strings.Join(lines, "\n")
return style.Render(strings.Join(lines, "\n"))
}
func (m *Model) scrollMaintCursor(delta int) {
@@ -180,14 +189,4 @@ func (m *Model) scrollMaintCursor(delta int) {
if m.maintCursor >= total {
m.maintCursor = total - 1
}
if m.maintCursor < m.maintOffset {
m.maintOffset = m.maintCursor
}
visible := m.maxTableRows / 2
if visible < 1 {
visible = 1
}
if m.maintCursor >= m.maintOffset+visible {
m.maintOffset = m.maintCursor - visible + 1
}
}