@spunto/design-system 0.78.0 → 0.79.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/package.json +1 -1
- package/src/components/projects/lifecycle-commands.tsx +7 -4
- package/src/components/projects/panel-types.ts +1 -0
- package/src/components/projects/project-form-lifecycle.test.tsx +40 -0
- package/src/components/projects/project-form.tsx +14 -2
- package/src/components/projects/project-panel.tsx +2 -1
- package/src/components/projects/section-status.ts +1 -1
- package/src/components/projects/types.ts +5 -0
package/package.json
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// devcontainer lifecycle commands — `postCreate` / `postStart`.
|
|
1
|
+
// devcontainer lifecycle commands — `postCreate` / `postStart` — and Spunto's `postSnapshot`.
|
|
2
2
|
//
|
|
3
3
|
// Generalised from Lite's local `LifecycleRow`; the dashboard wrote the same
|
|
4
4
|
// block out twice by hand.
|
|
@@ -34,17 +34,20 @@ export function LifecycleCommand({ label, command, className }: LifecycleCommand
|
|
|
34
34
|
export interface LifecycleCommandsProps {
|
|
35
35
|
postCreateCommand?: string | null
|
|
36
36
|
postStartCommand?: string | null
|
|
37
|
+
/** Run once in a sandbox started from a snapshot. */
|
|
38
|
+
postSnapshotCommand?: string | null
|
|
37
39
|
className?: string
|
|
38
40
|
}
|
|
39
41
|
|
|
40
|
-
/**
|
|
41
|
-
export function LifecycleCommands({ postCreateCommand, postStartCommand, className }: LifecycleCommandsProps) {
|
|
42
|
-
if (!postCreateCommand && !postStartCommand) return null
|
|
42
|
+
/** The lifecycle blocks, each rendered only when the project defines it. */
|
|
43
|
+
export function LifecycleCommands({ postCreateCommand, postStartCommand, postSnapshotCommand, className }: LifecycleCommandsProps) {
|
|
44
|
+
if (!postCreateCommand && !postStartCommand && !postSnapshotCommand) return null
|
|
43
45
|
|
|
44
46
|
return (
|
|
45
47
|
<div data-slot="lifecycle-commands" className={cn("space-y-1.5", className)}>
|
|
46
48
|
{postCreateCommand && <LifecycleCommand label="postCreate" command={postCreateCommand} />}
|
|
47
49
|
{postStartCommand && <LifecycleCommand label="postStart" command={postStartCommand} />}
|
|
50
|
+
{postSnapshotCommand && <LifecycleCommand label="postSnapshot" command={postSnapshotCommand} />}
|
|
48
51
|
</div>
|
|
49
52
|
)
|
|
50
53
|
}
|
|
@@ -47,6 +47,7 @@ export interface ProjectPanelProject {
|
|
|
47
47
|
forwardPorts?: (number | string)[]
|
|
48
48
|
postCreateCommand?: string | null
|
|
49
49
|
postStartCommand?: string | null
|
|
50
|
+
postSnapshotCommand?: string | null
|
|
50
51
|
/** Public half of the project's SSH deploy key (RFC 0013). */
|
|
51
52
|
deployPublicKey?: string | null
|
|
52
53
|
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The lifecycle section's third command, `postSnapshotCommand`, is Spunto's own: offered only to an
|
|
3
|
+
* app whose value holds it (`""` included), so a form without it (Lite) does not show a field it
|
|
4
|
+
* has nowhere to save.
|
|
5
|
+
*/
|
|
6
|
+
import { describe, it, expect } from "vitest"
|
|
7
|
+
import { useState } from "react"
|
|
8
|
+
import { render, screen, fireEvent } from "@testing-library/react"
|
|
9
|
+
import { ProjectForm } from "./project-form"
|
|
10
|
+
import { emptyProjectFormValue, type ProjectFormValue } from "./types"
|
|
11
|
+
|
|
12
|
+
function Harness({ initial, onValue }: { initial: ProjectFormValue; onValue?: (v: ProjectFormValue) => void }) {
|
|
13
|
+
const [value, setValue] = useState(initial)
|
|
14
|
+
return (
|
|
15
|
+
<ProjectForm
|
|
16
|
+
value={value}
|
|
17
|
+
onChange={(v) => {
|
|
18
|
+
setValue(v)
|
|
19
|
+
onValue?.(v)
|
|
20
|
+
}}
|
|
21
|
+
sections={["lifecycle"]}
|
|
22
|
+
defaultAdvancedOpen
|
|
23
|
+
/>
|
|
24
|
+
)
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
describe("ProjectForm — lifecycle commands", () => {
|
|
28
|
+
it("offers no post-snapshot command to a value without one", () => {
|
|
29
|
+
render(<Harness initial={emptyProjectFormValue()} />)
|
|
30
|
+
expect(screen.getByLabelText(/Post-start command/)).toBeTruthy()
|
|
31
|
+
expect(screen.queryByLabelText(/Post-snapshot command/)).toBeNull()
|
|
32
|
+
})
|
|
33
|
+
|
|
34
|
+
it("offers it, and edits it, when the value holds one", () => {
|
|
35
|
+
let last: ProjectFormValue | null = null
|
|
36
|
+
render(<Harness initial={{ ...emptyProjectFormValue(), postSnapshotCommand: "" }} onValue={(v) => (last = v)} />)
|
|
37
|
+
fireEvent.change(screen.getByLabelText(/Post-snapshot command/), { target: { value: "./catch-up.sh" } })
|
|
38
|
+
expect(last!.postSnapshotCommand).toBe("./catch-up.sh")
|
|
39
|
+
})
|
|
40
|
+
})
|
|
@@ -656,6 +656,18 @@ export function ProjectForm<TValue extends ProjectFormValue = ProjectFormValue>(
|
|
|
656
656
|
onChange={(e) => patch({ postStartCommand: e.target.value })}
|
|
657
657
|
/>
|
|
658
658
|
</Field>
|
|
659
|
+
{value.postSnapshotCommand !== undefined && (
|
|
660
|
+
<Field label="Post-snapshot command" htmlFor="post-snapshot" hint="Runs once in a sandbox started from a snapshot, after it fetched">
|
|
661
|
+
<Input
|
|
662
|
+
id="post-snapshot"
|
|
663
|
+
name="postSnapshotCommand"
|
|
664
|
+
placeholder="./catch-up.sh"
|
|
665
|
+
className="font-mono text-xs"
|
|
666
|
+
value={value.postSnapshotCommand}
|
|
667
|
+
onChange={(e) => patch({ postSnapshotCommand: e.target.value })}
|
|
668
|
+
/>
|
|
669
|
+
</Field>
|
|
670
|
+
)}
|
|
659
671
|
</div>
|
|
660
672
|
)
|
|
661
673
|
|
|
@@ -781,9 +793,9 @@ export function manifestRows<TValue extends ProjectFormValue>(
|
|
|
781
793
|
rows.push({
|
|
782
794
|
label: "lifecycle",
|
|
783
795
|
value:
|
|
784
|
-
[value.postCreateCommand && "create", value.postStartCommand && "start"].filter(Boolean).join(" + ") ||
|
|
796
|
+
[value.postCreateCommand && "create", value.postStartCommand && "start", value.postSnapshotCommand && "snapshot"].filter(Boolean).join(" + ") ||
|
|
785
797
|
"default",
|
|
786
|
-
done: !!(value.postCreateCommand || value.postStartCommand),
|
|
798
|
+
done: !!(value.postCreateCommand || value.postStartCommand || value.postSnapshotCommand),
|
|
787
799
|
})
|
|
788
800
|
if (shown.has("ports"))
|
|
789
801
|
rows.push({ label: "ports", value: value.forwardPorts.join(", ") || "—", done: value.forwardPorts.length > 0 })
|
|
@@ -264,11 +264,12 @@ export function ProjectPanel({
|
|
|
264
264
|
</PanelSection>
|
|
265
265
|
)}
|
|
266
266
|
|
|
267
|
-
{(project.postCreateCommand || project.postStartCommand) && (
|
|
267
|
+
{(project.postCreateCommand || project.postStartCommand || project.postSnapshotCommand) && (
|
|
268
268
|
<PanelSection title="Lifecycle">
|
|
269
269
|
<LifecycleCommands
|
|
270
270
|
postCreateCommand={project.postCreateCommand}
|
|
271
271
|
postStartCommand={project.postStartCommand}
|
|
272
|
+
postSnapshotCommand={project.postSnapshotCommand}
|
|
272
273
|
/>
|
|
273
274
|
</PanelSection>
|
|
274
275
|
)}
|
|
@@ -42,7 +42,7 @@ export function sectionSummary<TValue extends ProjectFormValue>(
|
|
|
42
42
|
case "extensions":
|
|
43
43
|
return value.vscodeExtensions.length ? plural(value.vscodeExtensions.length, "extension") : null
|
|
44
44
|
case "lifecycle":
|
|
45
|
-
return value.postCreateCommand || value.postStartCommand ? "lifecycle" : null
|
|
45
|
+
return value.postCreateCommand || value.postStartCommand || value.postSnapshotCommand ? "lifecycle" : null
|
|
46
46
|
case "ports":
|
|
47
47
|
return value.forwardPorts.length ? `ports ${value.forwardPorts.join(", ")}` : null
|
|
48
48
|
case "prewarm":
|
|
@@ -94,6 +94,11 @@ export interface ProjectFormValue {
|
|
|
94
94
|
vscodeExtensions: string[]
|
|
95
95
|
postCreateCommand: string
|
|
96
96
|
postStartCommand: string
|
|
97
|
+
/**
|
|
98
|
+
* Run once in a sandbox started from a snapshot (Spunto's own, not devcontainer's). The field is
|
|
99
|
+
* offered only to an app that has it: present in its value — `""` included — not `undefined`.
|
|
100
|
+
*/
|
|
101
|
+
postSnapshotCommand?: string
|
|
97
102
|
/** Secrets typed in this session. */
|
|
98
103
|
secrets: ProjectSecretDraft[]
|
|
99
104
|
/** Ids of already-saved secrets the user asked to remove. */
|