Repository navigation
refactor: share job creation defaults, payload conversion, and draft state #1268
Description
Result
Provide one frontend source of job creation defaults, validation, and payload conversion for the advanced editor and guided setup. Preserve the advanced editor's existing behavior before introducing the new route.
Parent: #1266. Independent of the backend preview implementation; agree on its typed payload contract.
Scope
- Extract narrowly scoped helpers such as
src/job-form.tsfrom src/pages/JobEditor.tsx: new-job timezone/defaults, TCP/UDP defaults, schema, duration editing, target handling, selected profile revision, and conversion toJobForm. - Introduce a page-scoped draft owner/context for creation only, shared across guided and advanced creation routes. A draft can carry all advanced job fields, not merely the wizard's visible subset. Do not change saved-job edit ownership, conflict handling, security-scope confirmation, or revision payloads.
- Preserve omitted notification routing versus explicit empty selection, unresolved built-in profile revision versus explicitly selected revision, protocol toggle restoration, and untouched values.
- Share the unsaved-change behavior needed for cross-mode navigation. Deliberate guided↔advanced transitions keep the draft; leaving the creation journey still asks to discard. Reload can discard an unsaved draft after the existing browser warning; do not introduce persistence for this scope.
- Account passwords and destination URLs/provider credentials remain outside this draft owner, router state, query keys, browser storage, and logs. Mode transfer must never serialize them.
- Preserve the current new-job defaults (two baseline samples, current confirmation threshold, full-range built-in TCP discovery, explicit high-cost opt-in, schedule/timezone behavior) and existing edit round trips.
Acceptance and regression evidence
-
JobEditoruses shared helpers and saves the same payloads for existing representative create/edit cases. - Guided→advanced→guided round-trip preserves targets, profiles, durations, DNS mode, protocols, routing, schedule, baseline controls, and advanced-only fields.
- Omitted routing differs from intentional
[]; omitted profile revision is not replaced with a hard-coded built-in revision. - Revision reload, stale edits, rebaseline confirmation, dirty-page navigation, browser Back, and protocol toggle preservation retain current behavior.
- New-job defaults remain immutable across two separate draft instances; canceled or successfully created drafts clear appropriately.
- No secret appears in transferred state or cache; no browser-storage persistence is introduced.
Likely files: new src/job-form.ts and a small creation-draft provider/hook, src/pages/JobEditor.tsx, src/main.tsx only as required to mount page-scoped state, src/target.ts reuse, and focused unit/round-trip/navigation tests. Avoid a broad form framework or unrelated editor rewrite.
Checks: npm run lint, npm run build, npm run test:coverage, targeted relevant browser cases, and normal frontend diff coverage. This extraction should preserve documented behavior; include any required maintainer documentation if a new shared ownership convention needs explanation. Estimated effort: 2–4 hours.
Activity