feat(apps): stepped creation wizard, branch previews, and app-creation fixes

This session (frontend focus):
- Rebuild /apps/new as a 4-step wizard (Basics → Configure → Trigger → Review):
  WizardRail, SourceKindPicker card grid, AppManifest review, per-step validation,
  ConfirmDialog-based unsaved-changes guard.
- Extract lib/workload/sourceForms.ts (single source of truth for source_config)
  + {Image,Compose,Static,Dockerfile}SourceForm + StaticDiscoveryWizard; fold the
  /apps/[id] edit form onto the same components (removes the duplication). Add
  vitest + sourceForms unit tests.
- Branch preview environments UI: /chain is_preview/preview_branch + a Preview
  environments panel on /apps/[id] (per-branch URLs, ConfirmDialog teardown, armed
  state); RegistryImagePicker on the registry trigger and the image source.
- Fixes: image-inspect 404 -> admin-gated POST /api/discovery/image/inspect;
  conflict-panel blur flicker; friendly localized discovery errors; CPU/Memory
  label hints; dashboard + /apps "Total workloads" count only source_kind workloads
  (drop stale trigger_kind gate); NPM cert/access-list name cache; EntityPicker
  empty-list guard.
- Update CLAUDE.md frontend conventions + add a Build & Test section.

Also captures pre-existing in-progress platform work (not from this session):
workload notifications, Prometheus metrics export, store lockfile, health probes,
backup hardening, and related store/webhook/scheduler changes.
This commit is contained in:
2026-05-29 02:09:54 +03:00
parent 956943edbb
commit 410a131cec
112 changed files with 13285 additions and 2765 deletions
@@ -0,0 +1,286 @@
<!--
Dockerfile source form. Shares the provider + repo + branch + token
git-discovery wiring with the static source (StaticDiscoveryWizard in its
compact `dockerfile` variant — same handlers, no folder tree). The
build-step controls (context path, dockerfile path, port) are the only
dockerfile-specific UI.
The parent owns the `DockerfileFormState` (from `$lib/workload/sourceForms`)
and binds it here; serialization to `source_config` is done by the parent
via `dockerfileToConfig` so the shape (incl. preserved unknown keys + the
scrubbed static-only keys) stays byte-identical. `DockerfileFormState
extends GitSourceState`, so the same object is bound into the wizard.
-->
<script lang="ts">
import type { DockerfileFormState } from '$lib/workload/sourceForms';
import StaticDiscoveryWizard from '$lib/components/workload/StaticDiscoveryWizard.svelte';
import { IconX } from '$lib/components/icons';
import { t } from '$lib/i18n';
interface Props {
form: DockerfileFormState;
/** Flip to the raw-JSON editor (owned by the parent). */
onAdvanced: () => void;
/**
* Transient discovery status — OPTIONAL pass-through to
* StaticDiscoveryWizard (dockerfile variant: detect + test only, no
* folder tree / mode). Each defaults to this component's own internal
* `$state`, so a parent that doesn't bind them keeps the original
* "resets on remount" behaviour (the detail/edit page `apps/[id]`
* binds none of these). The create wizard `apps/new` binds them up to
* the PAGE so the detect/test pills survive the form unmounting under
* the Advanced-JSON / source-kind toggles.
*/
detectStatus?: 'idle' | 'pending' | 'ok' | 'error';
detectError?: string;
testStatus?: 'idle' | 'pending' | 'ok' | 'error';
testError?: string;
}
let {
form = $bindable(),
onAdvanced,
detectStatus = $bindable('idle'),
detectError = $bindable(''),
testStatus = $bindable('idle'),
testError = $bindable('')
}: Props = $props();
// `touched` flips true on first blur — used by the pill to avoid shouting
// "required" the instant the user lands on the form.
let portTouched = $state(false);
// A cleared <input type="number"> binds to null (not 0) in Svelte 5, and
// `null <= 0` is false — so a bare `port <= 0` check would pass validation
// on an empty field. Guard against null/NaN/non-positive here.
const portValid = $derived(
typeof form.port === 'number' && Number.isFinite(form.port) && form.port > 0
);
</script>
<div class="image-form">
<div class="image-form-head">
<span class="editor-title">{$t('apps.new.dockerfileHeader')}</span>
<button type="button" class="json-escape" onclick={onAdvanced} title={$t('apps.new.switchToJsonTitle')}>
{$t('apps.new.advancedJson')}
</button>
</div>
<StaticDiscoveryWizard
bind:git={form}
variant="dockerfile"
bind:detectStatus
bind:detectError
bind:testStatus
bind:testError
idPrefix="app-df"
/>
<!-- Build-step controls — the only dockerfile-only UI. The form is a
two-phase form (locate the code, describe how to build it). A
forge-eyebrow divider phrases the conceptual break. -->
<div class="df-section-break" aria-hidden="false">
<span class="forge-eyebrow">
<span class="forge-ember"></span>
<span class="eb-word">{$t('apps.new.dockerfileBuildEyebrow')}</span>
</span>
</div>
<div class="row">
<label class="sub" for="app-df-context">
<span class="sub-label">{$t('apps.new.dockerfileContextPath')}</span>
<input
id="app-df-context"
type="text"
class="input mono"
bind:value={form.contextPath}
placeholder={$t('apps.new.dockerfileContextPathPlaceholder')}
autocomplete="off"
spellcheck="false"
/>
</label>
<label class="sub" for="app-df-dockerfile">
<span class="sub-label">{$t('apps.new.dockerfilePath')}</span>
<input
id="app-df-dockerfile"
type="text"
class="input mono"
bind:value={form.dockerfilePath}
placeholder="Dockerfile"
autocomplete="off"
spellcheck="false"
/>
</label>
</div>
<div class="row">
<label class="sub" for="app-df-port">
<span class="sub-label"
>{$t('apps.new.dockerfilePort')}<span class="req-star" aria-label={$t('apps.new.fieldRequired')}
>*</span
></span
>
<input
id="app-df-port"
type="number"
min="1"
max="65535"
class="input mono"
bind:value={form.port}
onblur={() => (portTouched = true)}
placeholder="8080"
required
/>
</label>
</div>
{#if portTouched && !portValid}
<div class="discover-pill discover-pill-bad">
<IconX size={12} />
<span>{$t('apps.new.dockerfilePortRequired')}</span>
</div>
{/if}
<p class="hint image-form-foot">{$t('apps.new.dockerfileFoot')}</p>
</div>
<style>
.input {
width: 100%;
background: var(--surface-input);
border: 1px solid var(--border-input);
border-radius: var(--radius-lg);
padding: 0.6rem 0.8rem;
font-size: 0.92rem;
color: var(--text-primary);
font-family: inherit;
outline: none;
transition: border-color 120ms ease, box-shadow 120ms ease;
}
.input:focus {
border-color: var(--border-focus);
box-shadow: 0 0 0 3px var(--accent-soft);
}
.input:focus-visible {
outline: none;
}
.hint {
font-size: 0.78rem;
color: var(--text-tertiary);
margin: 0;
line-height: 1.45;
}
.row {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 0.9rem;
}
@media (max-width: 600px) {
.row {
grid-template-columns: 1fr;
}
}
.sub {
display: flex;
flex-direction: column;
gap: 0.35rem;
}
.sub-label {
font-family: var(--forge-mono);
font-size: 0.62rem;
font-weight: 600;
letter-spacing: 0.14em;
text-transform: uppercase;
color: var(--text-secondary);
}
/* Required-field marker — same danger hue as the page-level `.req`
badge, rendered as a compact asterisk. */
.req-star {
margin-left: 0.2rem;
color: var(--color-danger);
font-weight: 700;
}
.editor-title {
margin-left: 0.4rem;
color: var(--text-secondary);
font-weight: 600;
letter-spacing: 0.02em;
}
/* ── "Edit as JSON" escape hatch ─────────────────────────
Quiet secondary text-link rather than a prominent chip, so it doesn't
compete with the form title. */
.json-escape {
background: none;
border: 0;
padding: 0;
font-family: var(--forge-mono);
font-size: 0.62rem;
font-weight: 600;
letter-spacing: 0.08em;
text-transform: uppercase;
color: var(--text-tertiary);
cursor: pointer;
text-decoration: none;
text-underline-offset: 3px;
transition: color 120ms ease;
}
.json-escape:hover {
color: var(--forge-accent);
text-decoration: underline;
}
.json-escape:focus-visible {
outline: 2px solid var(--border-focus);
outline-offset: 2px;
border-radius: var(--radius-sm);
}
/* ── Image source form shell (shared visual vocabulary) ── */
.image-form {
display: flex;
flex-direction: column;
gap: 0.9rem;
border: 1px solid var(--border-primary);
border-radius: var(--radius-lg);
background: var(--surface-input);
padding: 0.85rem 1rem;
}
.image-form-head {
display: flex;
align-items: center;
justify-content: space-between;
gap: 0.5rem;
padding-bottom: 0.55rem;
border-bottom: 1px solid var(--border-primary);
margin-bottom: 0.2rem;
}
.image-form-foot {
margin-top: 0.2rem;
padding-top: 0.55rem;
border-top: 1px dashed var(--border-primary);
}
/* Conceptual section divider — separates git-discovery from build-step.
Same dashed border vocabulary as image-form-foot so it reads as a
sibling of the foot hint, not a new pattern. */
.df-section-break {
margin-top: 0.45rem;
padding-top: 0.55rem;
border-top: 1px dashed var(--border-primary);
}
.discover-pill {
display: inline-flex;
align-items: center;
gap: 0.35rem;
padding: 0.28rem 0.55rem;
border-radius: var(--radius-md);
font-family: var(--forge-mono);
font-size: 0.62rem;
font-weight: 600;
letter-spacing: 0.06em;
line-height: 1;
align-self: flex-start;
}
.discover-pill-bad {
background: color-mix(in srgb, var(--color-danger) 14%, transparent);
color: var(--color-danger-dark);
border: 1px solid color-mix(in srgb, var(--color-danger) 40%, transparent);
}
:global([data-theme='dark']) .discover-pill-bad {
color: #fca5a5;
}
</style>