Files
MujicaUI/devtools/service_status.go
T
ZacharyZhang-NYandClaude Opus 5.5 bcce34cda1 Upgrade MyGo to v0.5.5
MyGo v0.5.5 returns ui.Element as a checked value handle instead of a
pointer. Migrated with `mygo migrate-ui`, then fixed what the codemod
leaves to review:

- Element nil checks become .Valid(); absent elements are ui.Element{}.
- Input handlers and paint callbacks run outside the build pass, where
  elements expire and Context methods are inert: read IsDisabled into a
  local during the build, keep a ui.Handle for Focus, use c.Services()
  for clipboard access, create ui.Local state during the build.
- Add core.AutoFocus: v0.5.5 records an overlay's opener after its
  content builds, so same-frame autofocus lost focus restore on close.
  It focuses one frame later; cascader rows defer their focus likewise.
- core.OverlayLayer identifies build passes by the root element, not
  c.Now(), which repeats across passes and under the Tester clock.
- Context menus survive the opening press counted as PressedOutside;
  split button tooltip no longer reorders its open menu; disabled
  menubar rows pass presses to the panel; Form defers blur-started
  async checks so the growing message no longer moves Submit away
  from the release; Combobox drops its disabled copy now that MyGo
  blocks typing under a disabled wrapper (canary flipped to a guard).
- The Tester clock is virtual: tests use Advance/Now instead of
  time.Sleep/time.Now and read element state inside the view. The web
  mirror advances the clock to wall time before each frame and input.
- AGENTS.md and docs describe the value Element API and the new pin.

Snapshot goldens are darwin-only and were not re-verified here.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-17 01:37:54 -04:00

107 lines
3.5 KiB
Go

package devtools
import (
"fmt"
"github.com/egoist/mygo/ui"
"git.zacharyzhang.com/ZacharyZhang-NY/MujicaUI/agent"
"git.zacharyzhang.com/ZacharyZhang-NY/MujicaUI/chart"
"git.zacharyzhang.com/ZacharyZhang-NY/MujicaUI/core"
"git.zacharyzhang.com/ZacharyZhang-NY/MujicaUI/theme"
)
// ServiceHealth is a service's state. The zero value is ServiceOperational.
type ServiceHealth int
const (
ServiceOperational ServiceHealth = iota
ServiceDegraded
ServiceOutage
)
// ServiceItem is one service the caller reports.
type ServiceItem struct {
Name string
Health ServiceHealth
// Note explains a degraded or down service.
Note string
}
// ServiceStatusOptions configure a ServiceStatus.
type ServiceStatusOptions struct {
// MaxHeight caps the scrolling list; zero means 360.
MaxHeight float32
}
// ServiceStatus lists service health and an overall summary.
func ServiceStatus(c *ui.Context, services []ServiceItem, opts ServiceStatusOptions) ui.Element {
if opts.MaxHeight < 0 {
panic("mujica: ServiceStatus MaxHeight is negative")
}
col := ui.Column(c).Shrink(0).Gap(core.Density(c).Unit() * 2)
summaryState := ui.Local(col, "mujica.services.summary", func() serviceSummary { return serviceSummary{key: "unset"} })
if key := chart.ChartID(services); key != summaryState.key {
worst, counts := ServiceOperational, [3]int{}
for i, s := range services {
if s.Name == "" || s.Health < ServiceOperational || s.Health > ServiceOutage {
panic(fmt.Sprintf("mujica: ServiceStatus service %d needs a Name and a known Health", i))
}
worst = max(worst, s.Health)
counts[s.Health]++
}
summaryState.key, summaryState.worst, summaryState.counts = key, worst, counts
}
worst, counts := summaryState.worst, summaryState.counts
maxH := opts.MaxHeight
if maxH == 0 {
maxH = 360
}
k := core.Tokens(c)
u := core.Density(c).Unit()
summary := core.Msg(c, [...]string{"service_status.all_ok", "service_status.some_degraded", "service_status.some_down"}[worst])
col.Label(summary)
col.Children(func() {
ui.Row(c).Gap(u*3).AlignItems(ui.Center).Padding(u*3).Radius(theme.CardRadius).Border(theme.BorderWidth, k.Border).
Background(k.Surface).Role(ui.RoleStatus).Label(summary).Children(func() {
devtoolsSeverity(c, serviceSeverity(worst), summary)
ui.Box(c).Grow(1)
agent.AgentCaption(c, fmt.Sprintf(core.Msg(c, "service_status.counts"), counts[0], counts[1], counts[2]))
})
if len(services) == 0 {
agent.AgentCaption(c, core.Msg(c, "service_status.empty"))
return
}
agent.AgentRows(c, len(services), func(i int) {
s := services[i]
word := serviceWord(c, s.Health)
ui.Row(c.Key(i)).Gap(u*3).AlignItems(ui.Center).MinHeight(core.Density(c).ControlHeight()).Padding(u, u*3).
Label(s.Name + ", " + word).Children(func() {
ui.Column(c).Grow(1).Shrink(1).Children(func() {
ui.Text(c, s.Name).SingleLine()
if s.Note != "" {
agent.AgentCaption(c, s.Note)
}
})
devtoolsSeverity(c, serviceSeverity(s.Health), word)
})
}).Shrink(1).MaxHeight(maxH).Background(k.Surface).Border(theme.BorderWidth, k.Border).
Radius(theme.CardRadius).Dividers(theme.BorderWidth, k.Border)
})
return col
}
func serviceSeverity(h ServiceHealth) core.Severity {
return [...]core.Severity{core.SeveritySuccess, core.SeverityWarning, core.SeverityError}[h]
}
func serviceWord(c *ui.Context, h ServiceHealth) string {
return core.Msg(c, [...]string{"service_status.operational", "service_status.degraded", "service_status.outage"}[h])
}
type serviceSummary struct {
key string
worst ServiceHealth
counts [3]int
}