Skip to content

refactor(ui): centralize lifecycle action gating and labels - #6

Open
thetimblank wants to merge 1 commit into
mainfrom
fix/centralize-lifecycle-action-gating
Open

refactor(ui): centralize lifecycle action gating and labels#6
thetimblank wants to merge 1 commit into
mainfrom
fix/centralize-lifecycle-action-gating

Conversation

@thetimblank

Copy link
Copy Markdown
Owner

Closes #4.

Problem

The sleep gate (status === 'online' && !isProxyProvider(...)) and the sleeping-state labels (Shutdown/Force Kill, Awake, Stop sleeping) were copy-pasted across server-card.tsx, ServerNodeMenu.tsx and server-overview-panel.tsx (and the dashboard tile repeated the start/stop gates too). That duplication had already let the overview panel drift.

Change

Added lifecycle helpers next to isStoppedStatus/isRunningStatus in src/data/servers.tsx:

  • canStartStatus, canStopStatus, canRestartStatus, canForceKillStatus, canSleepServer(server)
  • startActionLabel, stopActionLabel, forceKillActionLabel

All four lifecycle surfaces now render from these — server card, dashboard tile, network node menu, server overview panel.

Behavior differences this collapses (all in the overview panel, which was the outlier)

  • Force Kill no longer shows for a crashed server (it was gated on !isOffline); matches the card and node menu.
  • crashed now offers Serve (previously only offline did).
  • A sleeping server now gets a "Stop sleeping" button there, like everywhere else.

Also unified the node menu's wording with the rest of the app: StartServe, Force killForce Kill.

Testing

  • New src/data/server-lifecycle-actions.test.ts covers every gate across all six statuses plus the proxy case and the labels.
  • npm run test:run — 148 tests pass; npm run build clean.

🤖 Generated with Claude Code

The sleep gate (online && !proxy) and the sleeping-state labels were
copy-pasted across the server card, network node menu and server overview
panel, which had already let the overview panel diverge (broader isRunning
gate for sleep, !isOffline for force-kill, no stop affordance while sleeping).

Add canStartStatus/canStopStatus/canRestartStatus/canForceKillStatus/
canSleepServer plus start/stop/forceKill label helpers next to
isStoppedStatus in data/servers.tsx, and route all four lifecycle surfaces
(including the dashboard tile) through them. Unit-tests the gates and labels.

Closes #4

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Centralize sleep/wake button gating and labels (duplicated across 3 files)

1 participant