@spunto/design-system 0.51.0 → 0.53.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +9 -0
- package/package.json +1 -1
- package/src/brand/logo.test.tsx +7 -1
- package/src/brand/logo.ts +15 -12
- package/src/brand/spunto-logo.tsx +7 -3
- package/src/colors.ts +11 -10
- package/src/components/devcontainer/stack-mark-paths.ts +3 -0
- package/src/components/devcontainer/stack-mark.test.ts +16 -0
- package/src/components/devcontainer/stack-mark.tsx +1 -0
- package/src/components/projects/advanced-sections.tsx +9 -41
- package/src/components/projects/form-nav.tsx +225 -0
- package/src/components/projects/form-section.tsx +5 -2
- package/src/components/projects/index.ts +8 -1
- package/src/components/projects/project-form-sidebar.test.tsx +47 -0
- package/src/components/projects/project-form.tsx +277 -14
- package/src/components/projects/section-status.ts +67 -0
- package/src/components/projects/types.ts +26 -0
- package/src/components/tasks/new-task-composer.tsx +27 -4
- package/src/components/tasks/new-task-dialog.tsx +6 -0
- package/src/components/tasks/tasks.test.tsx +14 -0
- package/styles.css +120 -52
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
"use client"
|
|
2
2
|
|
|
3
|
-
import { useState, type ComponentType, type ReactNode } from "react"
|
|
3
|
+
import { useRef, useState, type ComponentType, type ReactNode } from "react"
|
|
4
4
|
import {
|
|
5
|
+
ArrowLeftIcon,
|
|
6
|
+
ArrowRightIcon,
|
|
5
7
|
BlocksIcon,
|
|
6
8
|
BoxIcon,
|
|
7
9
|
GitBranchIcon,
|
|
@@ -14,6 +16,7 @@ import {
|
|
|
14
16
|
} from "lucide-react"
|
|
15
17
|
|
|
16
18
|
import { cn } from "../../utils"
|
|
19
|
+
import { Button } from "../button"
|
|
17
20
|
import { Input } from "../input"
|
|
18
21
|
import { Switch } from "../switch"
|
|
19
22
|
import { Textarea } from "../textarea"
|
|
@@ -23,6 +26,8 @@ import { ImagePicker, type ImagePickerProps } from "./image-picker"
|
|
|
23
26
|
import { AdvancedDisclosure, advancedSummary } from "./advanced-sections"
|
|
24
27
|
import { BuildManifest, type ManifestRow } from "./build-manifest"
|
|
25
28
|
import { Field, FormSection, type SectionAccent } from "./form-section"
|
|
29
|
+
import { FormNav, SectionStatusBadge, type FormNavItem } from "./form-nav"
|
|
30
|
+
import { isSectionRequired, sectionSummary } from "./section-status"
|
|
26
31
|
import { RepoList, type GitProvider, type GitRepoOption, type RepoFieldRender } from "./repo-list"
|
|
27
32
|
import { SecretList } from "./secret-list"
|
|
28
33
|
import {
|
|
@@ -30,6 +35,7 @@ import {
|
|
|
30
35
|
isInternalSectionId,
|
|
31
36
|
type InternalSectionId,
|
|
32
37
|
type ProjectFormCustomSection,
|
|
38
|
+
type ProjectFormGroup,
|
|
33
39
|
type ProjectFormSectionId,
|
|
34
40
|
type ProjectFormValue,
|
|
35
41
|
type ProjectSecretRef,
|
|
@@ -69,6 +75,53 @@ const DEFAULT_ADVANCED: InternalSectionId[] = [
|
|
|
69
75
|
"secrets",
|
|
70
76
|
]
|
|
71
77
|
|
|
78
|
+
/** What a missing required section is called in the nav — the field, not the card. */
|
|
79
|
+
const REQUIRED_LABEL: Partial<Record<ProjectFormSectionId, string>> = { identity: "Name", image: "Base image" }
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* The `sidebar` layout's pages. "General" is the three sections that decide what
|
|
83
|
+
* a worker *is* — the ones the stacked layout keeps out of its fold — and the
|
|
84
|
+
* rest is sorted by what it tunes. A group none of whose sections is shown is
|
|
85
|
+
* dropped, so the same list serves creation and editing.
|
|
86
|
+
*/
|
|
87
|
+
export const DEFAULT_GROUPS: ProjectFormGroup[] = [
|
|
88
|
+
{
|
|
89
|
+
id: "general",
|
|
90
|
+
title: "General",
|
|
91
|
+
hint: "What the project is: its name, the image its workers boot, and the code they clone.",
|
|
92
|
+
icon: SquarePenIcon,
|
|
93
|
+
sections: ["identity", "image", "repositories"],
|
|
94
|
+
},
|
|
95
|
+
{
|
|
96
|
+
id: "tooling",
|
|
97
|
+
title: "Tooling",
|
|
98
|
+
hint: "What gets installed on top of the base image — devcontainer features and IDE extensions.",
|
|
99
|
+
icon: PuzzleIcon,
|
|
100
|
+
sections: ["features", "extensions"],
|
|
101
|
+
},
|
|
102
|
+
{
|
|
103
|
+
id: "lifecycle",
|
|
104
|
+
title: "Lifecycle",
|
|
105
|
+
hint: "Commands run when a worker is created, and every time it starts.",
|
|
106
|
+
icon: TerminalIcon,
|
|
107
|
+
sections: ["lifecycle"],
|
|
108
|
+
},
|
|
109
|
+
{
|
|
110
|
+
id: "runtime",
|
|
111
|
+
title: "Runtime",
|
|
112
|
+
hint: "How a running worker behaves: forwarded ports, preloaded images, Docker inside.",
|
|
113
|
+
icon: NetworkIcon,
|
|
114
|
+
sections: ["ports", "prewarm", "docker"],
|
|
115
|
+
},
|
|
116
|
+
{
|
|
117
|
+
id: "secrets",
|
|
118
|
+
title: "Secrets",
|
|
119
|
+
hint: "Environment variables injected into every workspace of the project.",
|
|
120
|
+
icon: KeyRoundIcon,
|
|
121
|
+
sections: ["secrets"],
|
|
122
|
+
},
|
|
123
|
+
]
|
|
124
|
+
|
|
72
125
|
export interface ProjectFormProps<TValue extends ProjectFormValue = ProjectFormValue> {
|
|
73
126
|
/**
|
|
74
127
|
* The complete value. Generic: an app whose project has a field the package
|
|
@@ -101,6 +154,22 @@ export interface ProjectFormProps<TValue extends ProjectFormValue = ProjectFormV
|
|
|
101
154
|
/** Forces the initial state. Omitted → open iff an advanced section has a value. */
|
|
102
155
|
defaultAdvancedOpen?: boolean
|
|
103
156
|
|
|
157
|
+
/**
|
|
158
|
+
* `stack` (default) — every section in one column, the tuning ones folded
|
|
159
|
+
* behind "Advanced options", the build manifest on the right.
|
|
160
|
+
*
|
|
161
|
+
* `sidebar` — a left rail of pages (`groups`), one page shown at a time, each
|
|
162
|
+
* entry marked required / filled / optional; the submit sits under the rail.
|
|
163
|
+
* The rail *is* the recap there, so `manifest` and `advancedSections` don't
|
|
164
|
+
* apply. Nothing is folded: a page you haven't opened still says what it holds.
|
|
165
|
+
*/
|
|
166
|
+
layout?: "stack" | "sidebar"
|
|
167
|
+
/**
|
|
168
|
+
* Pages of the `sidebar` layout. Defaults to `DEFAULT_GROUPS`. A shown section
|
|
169
|
+
* that no group lists — a custom one, typically — gets a page of its own, after.
|
|
170
|
+
*/
|
|
171
|
+
groups?: ProjectFormGroup[]
|
|
172
|
+
|
|
104
173
|
/** Catalogs, already fetched by the app — the form never calls an API. */
|
|
105
174
|
images?: DevcontainerImageEntry[]
|
|
106
175
|
features?: DevcontainerFeatureEntry[]
|
|
@@ -190,6 +259,8 @@ export function ProjectForm<TValue extends ProjectFormValue = ProjectFormValue>(
|
|
|
190
259
|
advancedLabel,
|
|
191
260
|
advancedHint,
|
|
192
261
|
defaultAdvancedOpen,
|
|
262
|
+
layout = "stack",
|
|
263
|
+
groups = DEFAULT_GROUPS,
|
|
193
264
|
images = [],
|
|
194
265
|
features = [],
|
|
195
266
|
imagePicker,
|
|
@@ -240,6 +311,144 @@ export function ProjectForm<TValue extends ProjectFormValue = ProjectFormValue>(
|
|
|
240
311
|
// user's cursor.
|
|
241
312
|
const [advancedOpen, setAdvancedOpen] = useState(() => defaultAdvancedOpen ?? summary.length > 0)
|
|
242
313
|
|
|
314
|
+
// ── Sidebar layout state. Declared unconditionally (hooks), unused in `stack`.
|
|
315
|
+
const pages = sidebarPages(shown, groups, custom)
|
|
316
|
+
const [activePage, setActivePage] = useState(() => pages[0]?.id ?? "")
|
|
317
|
+
// Flips once a submit was refused, and stays: from then on an empty required
|
|
318
|
+
// field is an error, not a reminder.
|
|
319
|
+
const [showErrors, setShowErrors] = useState(false)
|
|
320
|
+
const contentRef = useRef<HTMLDivElement>(null)
|
|
321
|
+
|
|
322
|
+
if (layout === "sidebar") {
|
|
323
|
+
const customList = customSections ?? []
|
|
324
|
+
const filledOf = (id: ProjectFormSectionId) => sectionSummary(value, id, savedSecrets, customList)
|
|
325
|
+
const navItems: FormNavItem[] = pages.map((page) => {
|
|
326
|
+
const required = page.sections.filter((id) => isSectionRequired(id, customList))
|
|
327
|
+
return {
|
|
328
|
+
id: page.id,
|
|
329
|
+
title: page.title,
|
|
330
|
+
icon: page.icon,
|
|
331
|
+
required: required.length,
|
|
332
|
+
missing: required.filter((id) => !filledOf(id)).map((id) => REQUIRED_LABEL[id] ?? metaOf(id).title),
|
|
333
|
+
summary: page.sections.map(filledOf).filter((x): x is string => !!x),
|
|
334
|
+
}
|
|
335
|
+
})
|
|
336
|
+
const firstMissing = navItems.find((item) => item.missing.length)
|
|
337
|
+
const index = Math.max(0, pages.findIndex((p) => p.id === activePage))
|
|
338
|
+
const page = pages[index]
|
|
339
|
+
const prev = pages[index - 1]
|
|
340
|
+
const next = pages[index + 1]
|
|
341
|
+
|
|
342
|
+
const go = (id: string) => {
|
|
343
|
+
setActivePage(id)
|
|
344
|
+
// Only scroll when the page's top went out of view: switching from the
|
|
345
|
+
// rail mustn't jolt a form you're already looking at the top of.
|
|
346
|
+
const el = contentRef.current
|
|
347
|
+
if (el && el.getBoundingClientRect().top < 0) el.scrollIntoView({ behavior: "smooth", block: "start" })
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
const submitBlock = (
|
|
351
|
+
<div className="space-y-3 border-t pt-4">
|
|
352
|
+
{firstMissing && showErrors && (
|
|
353
|
+
<p className="text-xs text-destructive">
|
|
354
|
+
Fill in the required fields first — {navItems.flatMap((i) => i.missing).join(", ").toLowerCase()}.
|
|
355
|
+
</p>
|
|
356
|
+
)}
|
|
357
|
+
{error && (
|
|
358
|
+
<p className="rounded-md border border-destructive/30 bg-destructive/10 px-3 py-2 text-sm text-destructive">
|
|
359
|
+
{error}
|
|
360
|
+
</p>
|
|
361
|
+
)}
|
|
362
|
+
<Button type="submit" size="lg" disabled={submitting} className="group w-full">
|
|
363
|
+
{submitting ? (
|
|
364
|
+
<span className="flex items-center gap-2">
|
|
365
|
+
<span className="h-4 w-4 animate-spin rounded-full border-2 border-background/40 border-t-background" />
|
|
366
|
+
{submittingLabel}
|
|
367
|
+
</span>
|
|
368
|
+
) : (
|
|
369
|
+
submitLabel
|
|
370
|
+
)}
|
|
371
|
+
</Button>
|
|
372
|
+
{manifestCaption && <p className="text-center text-[11px] text-muted-foreground">{manifestCaption}</p>}
|
|
373
|
+
{manifestFooter}
|
|
374
|
+
</div>
|
|
375
|
+
)
|
|
376
|
+
|
|
377
|
+
return (
|
|
378
|
+
<div className={cn("@container/form", className)}>
|
|
379
|
+
<form
|
|
380
|
+
data-slot="project-form"
|
|
381
|
+
data-layout="sidebar"
|
|
382
|
+
// Validation is ours: the browser's would stop at a required input on
|
|
383
|
+
// a page that isn't shown, and point at nothing.
|
|
384
|
+
noValidate
|
|
385
|
+
onSubmit={(e) => {
|
|
386
|
+
e.preventDefault()
|
|
387
|
+
if (firstMissing) {
|
|
388
|
+
setShowErrors(true)
|
|
389
|
+
go(firstMissing.id)
|
|
390
|
+
return
|
|
391
|
+
}
|
|
392
|
+
onSubmit?.(value)
|
|
393
|
+
}}
|
|
394
|
+
className="grid grid-cols-[minmax(0,1fr)] gap-6 @min-[48rem]/form:grid-cols-[15rem_minmax(0,1fr)] @min-[48rem]/form:items-start"
|
|
395
|
+
>
|
|
396
|
+
<aside className="min-w-0 @min-[48rem]/form:sticky @min-[48rem]/form:top-6">
|
|
397
|
+
<FormNav
|
|
398
|
+
items={navItems}
|
|
399
|
+
active={page?.id ?? ""}
|
|
400
|
+
onSelect={go}
|
|
401
|
+
showErrors={showErrors}
|
|
402
|
+
footer={<div className="hidden @min-[48rem]/form:block">{submitBlock}</div>}
|
|
403
|
+
/>
|
|
404
|
+
</aside>
|
|
405
|
+
|
|
406
|
+
<div ref={contentRef} className="min-w-0 scroll-mt-6 space-y-4">
|
|
407
|
+
{pages.map((p) => (
|
|
408
|
+
// Every page stays mounted, the others `hidden`: pickers keep their
|
|
409
|
+
// own UI state (a search, a "custom image" toggle) across pages,
|
|
410
|
+
// and `display:none` takes their inputs out of the tab order.
|
|
411
|
+
<div key={p.id} hidden={p.id !== page?.id} className="space-y-4">
|
|
412
|
+
<header className="space-y-1">
|
|
413
|
+
<p className="font-mono text-[11px] tracking-wide text-muted-foreground uppercase">
|
|
414
|
+
Step {pages.indexOf(p) + 1} of {pages.length}
|
|
415
|
+
</p>
|
|
416
|
+
<h2 className="font-display text-2xl font-bold tracking-tight">{p.title}</h2>
|
|
417
|
+
{p.hint && <p className="text-sm text-muted-foreground">{p.hint}</p>}
|
|
418
|
+
</header>
|
|
419
|
+
{p.sections.map((id) => {
|
|
420
|
+
const required = isSectionRequired(id, customList)
|
|
421
|
+
return section(id, undefined, (
|
|
422
|
+
<SectionStatusBadge required={required} filled={!!filledOf(id)} error={showErrors} />
|
|
423
|
+
))
|
|
424
|
+
})}
|
|
425
|
+
</div>
|
|
426
|
+
))}
|
|
427
|
+
|
|
428
|
+
<div className="flex items-center justify-between gap-3 pt-2">
|
|
429
|
+
{prev ? (
|
|
430
|
+
<Button type="button" variant="ghost" onClick={() => go(prev.id)} className="gap-1.5">
|
|
431
|
+
<ArrowLeftIcon className="h-4 w-4" />
|
|
432
|
+
{prev.title}
|
|
433
|
+
</Button>
|
|
434
|
+
) : (
|
|
435
|
+
<span />
|
|
436
|
+
)}
|
|
437
|
+
{next && (
|
|
438
|
+
<Button type="button" variant="outline" onClick={() => go(next.id)} className="gap-1.5">
|
|
439
|
+
Next: {next.title}
|
|
440
|
+
<ArrowRightIcon className="h-4 w-4" />
|
|
441
|
+
</Button>
|
|
442
|
+
)}
|
|
443
|
+
</div>
|
|
444
|
+
|
|
445
|
+
<div className="@min-[48rem]/form:hidden">{submitBlock}</div>
|
|
446
|
+
</div>
|
|
447
|
+
</form>
|
|
448
|
+
</div>
|
|
449
|
+
)
|
|
450
|
+
}
|
|
451
|
+
|
|
243
452
|
return (
|
|
244
453
|
// The container is this wrapper, not the form: a container query styles a
|
|
245
454
|
// container's DESCENDANTS, never the element that declares it — put both on
|
|
@@ -297,18 +506,29 @@ export function ProjectForm<TValue extends ProjectFormValue = ProjectFormValue>(
|
|
|
297
506
|
</div>
|
|
298
507
|
)
|
|
299
508
|
|
|
300
|
-
/**
|
|
301
|
-
function
|
|
509
|
+
/** Chrome of a section, built-in or the app's own. */
|
|
510
|
+
function metaOf(id: ProjectFormSectionId) {
|
|
302
511
|
const own = custom.get(id)
|
|
303
512
|
// A custom card is chrome-identical to a built-in one: same `FormSection`,
|
|
304
513
|
// same badge, same accent — only its body comes from the app.
|
|
305
|
-
|
|
514
|
+
return own
|
|
306
515
|
? { icon: own.icon, accent: own.accent, title: own.title, hint: own.hint }
|
|
307
516
|
: SECTION_META[id as InternalSectionId]
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
/**
|
|
520
|
+
* One section, numbered by its position in the whole form (folded or not) —
|
|
521
|
+
* or unnumbered in the sidebar layout, where the page is the step and the
|
|
522
|
+
* badge says required / optional instead.
|
|
523
|
+
*/
|
|
524
|
+
function section(id: ProjectFormSectionId, index: number | undefined, status?: ReactNode) {
|
|
525
|
+
const own = custom.get(id)
|
|
526
|
+
const meta = metaOf(id)
|
|
308
527
|
return (
|
|
309
528
|
<FormSection
|
|
310
529
|
key={id}
|
|
311
|
-
n={index + 1}
|
|
530
|
+
n={index == null ? undefined : index + 1}
|
|
531
|
+
status={status}
|
|
312
532
|
icon={meta.icon}
|
|
313
533
|
accent={meta.accent}
|
|
314
534
|
title={meta.title}
|
|
@@ -316,7 +536,7 @@ export function ProjectForm<TValue extends ProjectFormValue = ProjectFormValue>(
|
|
|
316
536
|
// The stagger is an inline delay rather than ten Tailwind variants;
|
|
317
537
|
// capped, or a long form's last section would arrive noticeably after
|
|
318
538
|
// you've already scrolled to it.
|
|
319
|
-
style={{ animationDelay: `${Math.min(index, 8) * 40}ms` }}
|
|
539
|
+
style={{ animationDelay: `${Math.min(index ?? 0, 8) * 40}ms` }}
|
|
320
540
|
>
|
|
321
541
|
{own ? own.render(value, patchCustom) : renderSection(id as InternalSectionId)}
|
|
322
542
|
{extras?.[id]}
|
|
@@ -329,12 +549,24 @@ export function ProjectForm<TValue extends ProjectFormValue = ProjectFormValue>(
|
|
|
329
549
|
case "identity":
|
|
330
550
|
return (
|
|
331
551
|
<div className="space-y-4">
|
|
332
|
-
<Field
|
|
552
|
+
<Field
|
|
553
|
+
label={
|
|
554
|
+
<>
|
|
555
|
+
Name
|
|
556
|
+
<span aria-hidden className="text-destructive">
|
|
557
|
+
*
|
|
558
|
+
</span>
|
|
559
|
+
</>
|
|
560
|
+
}
|
|
561
|
+
htmlFor="project-name"
|
|
562
|
+
error={showErrors && !value.name.trim() ? "Give the project a name." : undefined}
|
|
563
|
+
>
|
|
333
564
|
<Input
|
|
334
565
|
id="project-name"
|
|
335
566
|
name="name"
|
|
336
567
|
placeholder="my-project"
|
|
337
568
|
required
|
|
569
|
+
aria-invalid={showErrors && !value.name.trim() ? true : undefined}
|
|
338
570
|
value={value.name}
|
|
339
571
|
onChange={(e) => patch({ name: e.target.value })}
|
|
340
572
|
/>
|
|
@@ -354,13 +586,18 @@ export function ProjectForm<TValue extends ProjectFormValue = ProjectFormValue>(
|
|
|
354
586
|
|
|
355
587
|
case "image":
|
|
356
588
|
return (
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
589
|
+
<>
|
|
590
|
+
<ImagePicker
|
|
591
|
+
images={images}
|
|
592
|
+
value={value.image}
|
|
593
|
+
onChange={(image) => patch({ image })}
|
|
594
|
+
layout={imagePicker?.layout}
|
|
595
|
+
detail={imagePicker?.detail}
|
|
596
|
+
/>
|
|
597
|
+
{showErrors && !value.image && (
|
|
598
|
+
<p className="mt-3 text-xs text-destructive">Pick a base image, or type the reference of your own.</p>
|
|
599
|
+
)}
|
|
600
|
+
</>
|
|
364
601
|
)
|
|
365
602
|
|
|
366
603
|
case "repositories":
|
|
@@ -488,6 +725,32 @@ export function ProjectForm<TValue extends ProjectFormValue = ProjectFormValue>(
|
|
|
488
725
|
}
|
|
489
726
|
}
|
|
490
727
|
|
|
728
|
+
/**
|
|
729
|
+
* The sidebar's pages: the declared groups, narrowed to the sections actually
|
|
730
|
+
* shown (an empty group is dropped), then one page per shown section no group
|
|
731
|
+
* listed — so a custom section can't silently vanish for want of a group.
|
|
732
|
+
*/
|
|
733
|
+
function sidebarPages<TValue extends ProjectFormValue>(
|
|
734
|
+
shown: ProjectFormSectionId[],
|
|
735
|
+
groups: ProjectFormGroup[],
|
|
736
|
+
custom: Map<string, ProjectFormCustomSection<TValue>>
|
|
737
|
+
): ProjectFormGroup[] {
|
|
738
|
+
const placed = new Set<ProjectFormSectionId>()
|
|
739
|
+
const pages: ProjectFormGroup[] = []
|
|
740
|
+
for (const group of groups) {
|
|
741
|
+
const sections = group.sections.filter((id) => shown.includes(id) && !placed.has(id))
|
|
742
|
+
sections.forEach((id) => placed.add(id))
|
|
743
|
+
if (sections.length) pages.push({ ...group, sections })
|
|
744
|
+
}
|
|
745
|
+
for (const id of shown) {
|
|
746
|
+
if (placed.has(id)) continue
|
|
747
|
+
const own = custom.get(id)
|
|
748
|
+
const meta = own ?? SECTION_META[id as InternalSectionId]
|
|
749
|
+
pages.push({ id, title: meta.title, hint: meta.hint, icon: meta.icon, sections: [id] })
|
|
750
|
+
}
|
|
751
|
+
return pages
|
|
752
|
+
}
|
|
753
|
+
|
|
491
754
|
/** `"3000, 8080, "` → `[3000, 8080]`. Anything that isn't a number is dropped. */
|
|
492
755
|
function parsePorts(raw: string): number[] {
|
|
493
756
|
return raw
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
// What a section holds, read off the value — never stored.
|
|
2
|
+
//
|
|
3
|
+
// One place for the question "is this section filled in, and how would you say
|
|
4
|
+
// it in three words?", because three surfaces ask it: the closed fold's summary
|
|
5
|
+
// (`advancedSummary`), and the `sidebar` layout's nav and section badges. They
|
|
6
|
+
// used to be one `switch` inside the fold; the sidebar needed the same answer
|
|
7
|
+
// for the sections the fold never held (a name, an image, repos).
|
|
8
|
+
|
|
9
|
+
import {
|
|
10
|
+
REQUIRED_SECTIONS,
|
|
11
|
+
isInternalSectionId,
|
|
12
|
+
type ProjectFormCustomSection,
|
|
13
|
+
type ProjectFormSectionId,
|
|
14
|
+
type ProjectFormValue,
|
|
15
|
+
type ProjectSecretRef,
|
|
16
|
+
} from "./types"
|
|
17
|
+
|
|
18
|
+
const plural = (n: number, word: string) => `${n} ${word}${n === 1 ? "" : "s"}`
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* A short label — `my-project`, `2 features`, `lifecycle` — when the section
|
|
22
|
+
* holds something, `null` when it's empty. A custom section answers through its
|
|
23
|
+
* own `summary`; one without it reads as always empty.
|
|
24
|
+
*/
|
|
25
|
+
export function sectionSummary<TValue extends ProjectFormValue>(
|
|
26
|
+
value: TValue,
|
|
27
|
+
id: ProjectFormSectionId,
|
|
28
|
+
/** Saved secrets count like drafts — an existing secret is still a secret. */
|
|
29
|
+
savedSecrets: ProjectSecretRef[] = [],
|
|
30
|
+
customSections: ProjectFormCustomSection<TValue>[] = []
|
|
31
|
+
): string | null {
|
|
32
|
+
if (!isInternalSectionId(id)) return customSections.find((s) => s.id === id)?.summary?.(value) ?? null
|
|
33
|
+
switch (id) {
|
|
34
|
+
case "identity":
|
|
35
|
+
return value.name.trim() || null
|
|
36
|
+
case "image":
|
|
37
|
+
return value.image ? (value.image.split("/").pop() ?? value.image) : null
|
|
38
|
+
case "repositories":
|
|
39
|
+
return value.repositories.length ? plural(value.repositories.length, "repo") : null
|
|
40
|
+
case "features":
|
|
41
|
+
return value.features.length ? plural(value.features.length, "feature") : null
|
|
42
|
+
case "extensions":
|
|
43
|
+
return value.vscodeExtensions.length ? plural(value.vscodeExtensions.length, "extension") : null
|
|
44
|
+
case "lifecycle":
|
|
45
|
+
return value.postCreateCommand || value.postStartCommand ? "lifecycle" : null
|
|
46
|
+
case "ports":
|
|
47
|
+
return value.forwardPorts.length ? `ports ${value.forwardPorts.join(", ")}` : null
|
|
48
|
+
case "prewarm":
|
|
49
|
+
return value.prewarmImages.length ? `${value.prewarmImages.length} prewarm` : null
|
|
50
|
+
case "docker":
|
|
51
|
+
return value.dockerInDocker ? "docker-in-docker" : null
|
|
52
|
+
case "secrets": {
|
|
53
|
+
const n = value.secrets.length + savedSecrets.filter((x) => !value.removedSecretIds.includes(x.id)).length
|
|
54
|
+
return n ? plural(n, "secret") : null
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** Required = in `REQUIRED_SECTIONS`, or a custom section that says so. */
|
|
60
|
+
export function isSectionRequired<TValue extends ProjectFormValue>(
|
|
61
|
+
id: ProjectFormSectionId,
|
|
62
|
+
customSections: ProjectFormCustomSection<TValue>[] = []
|
|
63
|
+
): boolean {
|
|
64
|
+
return isInternalSectionId(id)
|
|
65
|
+
? REQUIRED_SECTIONS.includes(id)
|
|
66
|
+
: !!customSections.find((s) => s.id === id)?.required
|
|
67
|
+
}
|
|
@@ -161,6 +161,26 @@ export interface ProjectFormCustomSection<TValue extends ProjectFormValue = Proj
|
|
|
161
161
|
summary?: (value: TValue) => string | null
|
|
162
162
|
/** A line in the build manifest, or `null`. Appended after the built-in rows. */
|
|
163
163
|
manifestRow?: (value: TValue) => ManifestRow | null
|
|
164
|
+
/**
|
|
165
|
+
* Marks the section as required in the `sidebar` layout: flagged in the nav,
|
|
166
|
+
* counted in the progress, and blocking submit while `summary` returns `null`
|
|
167
|
+
* — "filled" for a custom section *is* having a summary, so a required one
|
|
168
|
+
* without `summary` can never be satisfied.
|
|
169
|
+
*/
|
|
170
|
+
required?: boolean
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* One entry of the `sidebar` layout's navigation: a page of the form holding one
|
|
175
|
+
* or more sections. Sections not placed in any group get a page of their own,
|
|
176
|
+
* after the declared ones — a custom section is never lost for want of a group.
|
|
177
|
+
*/
|
|
178
|
+
export interface ProjectFormGroup {
|
|
179
|
+
id: string
|
|
180
|
+
title: string
|
|
181
|
+
hint?: string
|
|
182
|
+
icon?: ComponentType<{ className?: string }>
|
|
183
|
+
sections: ProjectFormSectionId[]
|
|
164
184
|
}
|
|
165
185
|
|
|
166
186
|
/** Internal ids, as a runtime set — what tells a custom id from a built-in one. */
|
|
@@ -207,6 +227,12 @@ export const EDIT_SECTIONS: ProjectFormSectionId[] = [
|
|
|
207
227
|
"secrets",
|
|
208
228
|
]
|
|
209
229
|
|
|
230
|
+
/**
|
|
231
|
+
* What the API refuses to create a project without: a name and a base image.
|
|
232
|
+
* Everything else has a working default — no repo is a valid (empty) workspace.
|
|
233
|
+
*/
|
|
234
|
+
export const REQUIRED_SECTIONS: InternalSectionId[] = ["identity", "image"]
|
|
235
|
+
|
|
210
236
|
/** An empty, complete value — the starting point of a creation form. */
|
|
211
237
|
export function emptyProjectFormValue(): ProjectFormValue {
|
|
212
238
|
return {
|
|
@@ -53,12 +53,15 @@ export interface NewTaskComposerProps {
|
|
|
53
53
|
/** The project's default model — what the chip says when nobody picked one. */
|
|
54
54
|
defaultModel?: string | null
|
|
55
55
|
/**
|
|
56
|
-
* The app's own fields, drawn as chips after the package's
|
|
57
|
-
* control (`newTaskChipClassName`); `label`
|
|
56
|
+
* The app's own fields, drawn as chips after the package's — or before them, with
|
|
57
|
+
* `placement: "lead"`: `render` should draw a compact control (`newTaskChipClassName`); `label`
|
|
58
|
+
* and `hint` become its tooltip.
|
|
58
59
|
*/
|
|
59
60
|
fields?: NewTaskCustomField[]
|
|
60
61
|
/** Every pick of an app field, as it happens — for fields whose options depend on another one. */
|
|
61
62
|
onFieldChange?: (id: string, value: unknown) => void
|
|
63
|
+
/** The model as it is typed or picked ("" = none) — for fields whose options depend on it. */
|
|
64
|
+
onModelChange?: (model: string) => void
|
|
62
65
|
/**
|
|
63
66
|
* What this member delegated with last time in this project: the branch and model chips start
|
|
64
67
|
* on it, over the defaults. Applied again — and the app fields' picks dropped, so their
|
|
@@ -227,6 +230,7 @@ export function NewTaskComposer({
|
|
|
227
230
|
defaultModel = null,
|
|
228
231
|
fields = [],
|
|
229
232
|
onFieldChange,
|
|
233
|
+
onModelChange,
|
|
230
234
|
remembered,
|
|
231
235
|
draftKey,
|
|
232
236
|
onSubmit,
|
|
@@ -372,6 +376,22 @@ export function NewTaskComposer({
|
|
|
372
376
|
/>
|
|
373
377
|
)}
|
|
374
378
|
|
|
379
|
+
{/* Fields the package's chips depend on — the harness, before the model it lists. */}
|
|
380
|
+
{fields.filter((f) => f.placement === "lead").map((f) => (
|
|
381
|
+
<span
|
|
382
|
+
key={f.id}
|
|
383
|
+
className="inline-flex"
|
|
384
|
+
data-slot="new-task-field"
|
|
385
|
+
data-field={f.id}
|
|
386
|
+
title={[f.label, typeof f.hint === "string" ? f.hint : null].filter(Boolean).join(" — ")}
|
|
387
|
+
>
|
|
388
|
+
{f.render(fieldValue(f), (v) => {
|
|
389
|
+
setPicked((prev) => ({ ...prev, [f.id]: v }))
|
|
390
|
+
onFieldChange?.(f.id, v)
|
|
391
|
+
})}
|
|
392
|
+
</span>
|
|
393
|
+
))}
|
|
394
|
+
|
|
375
395
|
<FreeTextChip
|
|
376
396
|
label="Base branch"
|
|
377
397
|
icon={<GitBranchIcon />}
|
|
@@ -386,14 +406,17 @@ export function NewTaskComposer({
|
|
|
386
406
|
label="Model"
|
|
387
407
|
icon={<PackageIcon />}
|
|
388
408
|
value={model}
|
|
389
|
-
onChange={
|
|
409
|
+
onChange={(next) => {
|
|
410
|
+
setModel(next)
|
|
411
|
+
onModelChange?.(next)
|
|
412
|
+
}}
|
|
390
413
|
placeholder={defaultModel ?? "harness default"}
|
|
391
414
|
groups={modelGroups.map((g) => ({ id: g.id, heading: g.label, items: g.models.map((m) => ({ value: m.value, label: m.label, meta: m.label })) }))}
|
|
392
415
|
searchPlaceholder="Any model id your harness understands"
|
|
393
416
|
mono
|
|
394
417
|
/>
|
|
395
418
|
|
|
396
|
-
{fields.map((f) => (
|
|
419
|
+
{fields.filter((f) => f.placement !== "lead").map((f) => (
|
|
397
420
|
<span
|
|
398
421
|
key={f.id}
|
|
399
422
|
className="inline-flex"
|
|
@@ -70,6 +70,12 @@ export interface NewTaskCustomField {
|
|
|
70
70
|
defaultValue?: unknown
|
|
71
71
|
/** Delegate stays disabled while it has no value (`undefined`, `null` or `""`). */
|
|
72
72
|
required?: boolean
|
|
73
|
+
/**
|
|
74
|
+
* Where the composer draws it: `lead` before the package's own chips (base branch, model) — for
|
|
75
|
+
* a field they depend on, like the harness whose models the model chip lists — `trail` (the
|
|
76
|
+
* default) after them. The dialog ignores it: its fields come after the package's.
|
|
77
|
+
*/
|
|
78
|
+
placement?: "lead" | "trail"
|
|
73
79
|
render: (value: unknown, onChange: (value: unknown) => void) => ReactNode
|
|
74
80
|
}
|
|
75
81
|
|
|
@@ -539,6 +539,20 @@ describe("NewTaskComposer — delegating where the conversation will be", () =>
|
|
|
539
539
|
expect(onSubmit.mock.calls[0]![0]).toEqual({ prompt: "Fix the login on Safari", files: [] })
|
|
540
540
|
})
|
|
541
541
|
|
|
542
|
+
it("draws a lead field before the package's chips — the harness before the model it lists", () => {
|
|
543
|
+
const onSubmit = vi.fn()
|
|
544
|
+
const harness = machine({ id: "harness", label: "Harness", defaultValue: "claude", placement: "lead" })
|
|
545
|
+
render(<NewTaskComposer defaultModel="claude-opus-5" fields={[machine(), harness]} onSubmit={onSubmit} />)
|
|
546
|
+
const order = [...document.querySelectorAll("[data-field], [aria-label='Model'], [aria-label='Base branch']")].map(
|
|
547
|
+
(el) => el.getAttribute("data-field") ?? el.getAttribute("aria-label"),
|
|
548
|
+
)
|
|
549
|
+
expect(order.indexOf("harness")).toBeLessThan(order.indexOf("Base branch") === -1 ? order.length : order.indexOf("Base branch"))
|
|
550
|
+
expect(order.indexOf("harness")).toBeLessThan(order.indexOf("machine"))
|
|
551
|
+
fireEvent.change(prompt(), { target: { value: "Fix it" } })
|
|
552
|
+
fireEvent.keyDown(prompt(), { key: "Enter" })
|
|
553
|
+
expect(onSubmit.mock.calls[0]![0].fields).toEqual({ machine: "worker", harness: "claude" })
|
|
554
|
+
})
|
|
555
|
+
|
|
542
556
|
it("org-wide, Delegate waits for a project and says so", () => {
|
|
543
557
|
const onSubmit = vi.fn()
|
|
544
558
|
render(<NewTaskComposer projects={[{ id: "p1", name: "spunto" }]} onSubmit={onSubmit} />)
|