Skip to content

Automatic Environment Backups: config-screen wizard redesign (v0.7.0)#149

Open
roger-datocms wants to merge 5 commits into
masterfrom
feature/ui-improvements
Open

Automatic Environment Backups: config-screen wizard redesign (v0.7.0)#149
roger-datocms wants to merge 5 commits into
masterfrom
feature/ui-improvements

Conversation

@roger-datocms

Copy link
Copy Markdown
Member

Summary

Redesigns the Automatic Environment Backups configuration screen from a flat three-card layout into a guided four-step wizard, and fixes the bugs behind a support ticket (a fresh install failing with HTTP 401: UNAUTHORIZED - Missing or invalid X-Datocms-Backups-Auth header, plus an infinite request loop on the config screen).

Bumps the plugin to v0.7.0. The persisted-parameter schema is unchanged, so existing installs keep working with no migration.

Why

A fresh install was sending the wrong/default auth token. Two root causes:

  • Auth-secret desync. The secret had three out-of-sync representations — the input field, an in-memory savedFormValues snapshot, and the persisted parameter. "Connect" read one while the overview and "Backup now" read another, so the plugin could send a stale/default token → 401.
  • Infinite render/request loop. A mount effect that persisted parameters also depended on ctx-derived callbacks, and ctx changes identity on every updatePluginParameters, so the effect re-fired forever. The screen never settled and the real error was buried several sections down.

What changed

Bug fixes

  • Infinite loop: the mount health ping now runs exactly once via a StrictMode-safe ref guard (hasRunMountCheckRef/isMountCheckUnmountedRef) with an empty-deps effect.
  • Desync: the saved plugin parameters are now the single source of truth (removed the savedFormValues React snapshot); every read comes from ctx.plugin.attributes.parameters via typed getters.

Redesign — guided four-step wizard

  • Step 1 — Auth secret & deploy: auto-generates a 128-bit hex secret on fresh installs; regenerate icon; a single "Save and copy" action; a "Revert to saved?" undo when editing; provider deploy menu; the secret is no longer printed twice.
  • Step 2 — Connect & test: "Save & test connection" surfaces the exact pass/fail reason inline (fixes the buried-error problem).
  • Step 3 — Backup cadence: "Save & continue" creates any missing backup environments.
  • Status overview: a live checklist + per-cadence rows + Backup now, with an "All ok!" state.
  • A top progress timeline, a multi-open accordion (fixes an Edit-button scroll-jump / CLS), and SDK Spinners with explicit "what we're waiting for" text.
  • Explicit per-step saves (no global Save button); each save updates every representation of a value together.
  • Clarified the Advanced-settings note (replaced the opaque "runs in Lambda cron mode only" with a plain-language explanation of the scheduled-function flow).

Architecture

  • Split the ~1,860-line ConfigScreen.tsx into small, single-purpose units under src/config/: pure, unit-tested modules (generateAuthSecret, pluginParams, deriveStepStatuses), the useBackupsConfig orchestration hook, and per-step components. 60 unit tests (25 new), no new test deps.

Docs

  • Rewrote the README setup for the wizard and embedded a screenshot; added a plugin-local AGENTS.md; committed the design spec under docs/superpowers/specs/; added a CHANGELOG 0.7.0 entry.

Screenshot

The Automatic Environment Backups configuration wizard

Testing

  • tsc --noEmit, vitest run (60 passing), and vite build — all green.
  • Reviewed by an xhigh multi-agent code review; all confirmed findings (data-integrity clobbers, a dropped on-connect backup creation, silent failures, a dead condition) were fixed in a follow-up commit.

Commits

  1. Design spec
  2. Config-screen wizard redesign (monolith → gated accordion, single source of truth)
  3. Code-review fixes
  4. UI pass (Step 1 controls, CLS fix, Spinners, progress timeline)
  5. Docs + version bump to 0.7.0

🤖 Generated with Claude Code

roger-datocms and others added 5 commits June 30, 2026 19:23
Design spec for reworking the Automatic Environment Backups config screen into a gated, per-step wizard with a single source of truth (saved plugin parameters).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Split the ~1.8k-line ConfigScreen monolith into a thin orchestrator plus
focused single-purpose units under src/config/:

- Pure, unit-tested modules: generateAuthSecret, pluginParams (typed
  source-of-truth readers), deriveStepStatuses + buildStatusChecklist.
- useBackupsConfig hook holding all edit-state, the queued authoritative
  persister, per-step save+act handlers, and the run-once mount ping.
- Accordion chrome (StepSection, StatusBox) and per-step components
  (StepSecret, StepConnect, StepSchedule, StatusOverview, AdvancedSettings).

Behavior changes:
- Saved plugin parameters are the single source of truth; the savedFormValues
  React snapshot is removed. This eliminates the auth-secret desync that made
  the plugin send the wrong/default token (HTTP 401).
- Explicit per-step saves; no global Save button.
- Fresh installs auto-generate a 128-bit hex secret; existing secrets are kept.
- Preserves the run-once, StrictMode-safe mount health ping, fixing the
  config-screen infinite request loop.
- Persisted-parameter schema is unchanged, so existing installs keep working.

Adds 25 unit tests for the pure modules (60 total, all green). tsc + vitest +
vite build all pass.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Fixes from the xhigh review of the wizard rewrite:

- persistPluginParameters now merges against a running accumulator ref, so
  sequential mount-flow persists compose even without a CMA token (was
  clobbering the schedule migration on token-less roles).
- Mount health-check success persists only the connection result, not the
  stale first-render secret/URL snapshot (was reverting a secret saved during
  the in-flight check).
- Mount schedule migration only runs for an actually-stored legacy schedule, so
  a fresh install no longer auto-completes step 3 with unchosen cadences.
- saveAndTestConnection re-creates missing backup environments on connect when a
  schedule is already saved (restores the old connect behavior for reconnects),
  surfaces failures via a transient error box independent of persistence, and no
  longer overwrites a previously-healthy deployment URL on a failed test.
- saveSecret clears any recorded connection state on a secret change (not only a
  healthy one), so re-saving after a 401 doesn't show a stale error.
- saveDebug reverts the optimistic toggle and alerts on persist failure.
- deriveStepStatuses/buildStatusChecklist drop a dead always-true sub-condition.
- StepSection gives a collapsed current/error step an explicit open affordance.
- TSDoc added to the remaining internal helpers.

tsc + vitest (60) + vite build all green.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Step 1 (auth secret):
- Regenerate is now an icon button beside the field (tooltip via native title
  + aria-label); Save and Copy are merged into one "Save and copy" primary
  button with an inline Spinner while saving.
- The edit warning always offers a "Revert to saved?" link (new revertSecret),
  with the redeploy note shown when a healthy connection exists.
- The deploy box no longer repeats the secret value and now reads: set
  DATOCMS_BACKUPS_SHARED_SECRET to the secret above, then continue with the
  deployed URL.
- New hook handlers: saveAndCopySecret, revertSecret.

Accordion / feedback:
- Replaced the single expandedStep with a multi-open Set so [Edit] is additive
  and never collapses a step above the clicked one — fixes the scroll-jump CLS.
  Kept the custom StepSection (numbered card) over the SDK collapsible Section.
- Added SDK Spinners with explicit "what we're waiting for" text to the Connect,
  Schedule, and Status-overview inline boxes (and per-cadence backup-now rows).

New StepTimeline: horizontal progress stepper at the top with done/current/error
/upcoming nodes, connectors, and an "All ok!" terminal state.

Advanced settings: replaced the opaque "runs in Lambda cron mode only" note with
a plain-language explanation of the scheduled-function backup flow (daily 02:05
UTC, clones the primary environment into sandbox backups).

tsc + vitest (60) + vite build all green.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
- README: rewrite Setup for the four-step wizard, refresh "How it works" and
  "Managing the connection", embed the new config-screen screenshot.
- Add a plugin-local AGENTS.md documenting the src/config architecture (params
  as single source of truth, per-step saves, pure tested modules, the mount
  run-once/StrictMode and multi-open-accordion gotchas).
- CHANGELOG: 0.7.0 entry.
- Bump version 0.6.13 → 0.7.0 (minor).

Co-Authored-By: Claude Opus 4.8 (1M context) <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.

1 participant