@spunto/design-system 0.60.0 → 0.61.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/create-repo-dialog.test.tsx +115 -0
- package/src/components/projects/create-repo-dialog.tsx +191 -0
- package/src/components/projects/index.ts +3 -0
- package/src/components/projects/project-form.tsx +6 -1
- package/src/components/projects/repo-list.tsx +44 -2
- package/src/components/tasks/index.ts +4 -0
- package/src/components/tasks/shared.tsx +156 -0
- package/src/components/tasks/task-details.tsx +25 -2
- package/src/components/tasks/types.ts +25 -0
package/package.json
CHANGED
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* "New repository" in the repository list: offered only when a connected provider declares
|
|
3
|
+
* `createRepo` *and* the app wires creation, and a created repository lands as a row that is
|
|
4
|
+
* already picked — provider and workspace path included, since those are what a sandbox clones by.
|
|
5
|
+
*/
|
|
6
|
+
import { describe, it, expect, vi } from "vitest"
|
|
7
|
+
import { useState } from "react"
|
|
8
|
+
import { render, screen, fireEvent, waitFor } from "@testing-library/react"
|
|
9
|
+
import { RepoList, type GitProvider, type GitRepoOption } from "./repo-list"
|
|
10
|
+
import { repoNameFrom, type CreateRepoInput } from "./create-repo-dialog"
|
|
11
|
+
import type { ProjectRepo } from "./types"
|
|
12
|
+
|
|
13
|
+
const GITHUB: GitProvider = {
|
|
14
|
+
id: "github",
|
|
15
|
+
name: "GitHub",
|
|
16
|
+
connected: true,
|
|
17
|
+
accounts: [{ login: "acme" }, { login: "alice" }],
|
|
18
|
+
operations: ["listRepos", "cloneCredential", "createRepo"],
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function Harness({
|
|
22
|
+
providers = [GITHUB],
|
|
23
|
+
onCreateRepo,
|
|
24
|
+
onRepos,
|
|
25
|
+
}: {
|
|
26
|
+
providers?: GitProvider[]
|
|
27
|
+
onCreateRepo?: (input: CreateRepoInput) => Promise<GitRepoOption>
|
|
28
|
+
onRepos?: (r: ProjectRepo[]) => void
|
|
29
|
+
}) {
|
|
30
|
+
const [repos, setRepos] = useState<ProjectRepo[]>([])
|
|
31
|
+
return (
|
|
32
|
+
<RepoList
|
|
33
|
+
repos={repos}
|
|
34
|
+
onChange={(next) => {
|
|
35
|
+
setRepos(next)
|
|
36
|
+
onRepos?.(next)
|
|
37
|
+
}}
|
|
38
|
+
gitProviders={providers}
|
|
39
|
+
onCreateRepo={onCreateRepo}
|
|
40
|
+
suggestedRepoName="My new app"
|
|
41
|
+
/>
|
|
42
|
+
)
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const button = () => screen.queryByRole("button", { name: /new repository/i })
|
|
46
|
+
|
|
47
|
+
describe("New repository", () => {
|
|
48
|
+
it("is absent when no provider declares createRepo", () => {
|
|
49
|
+
render(<Harness providers={[{ ...GITHUB, operations: ["listRepos", "cloneCredential"] }]} onCreateRepo={vi.fn()} />)
|
|
50
|
+
expect(button()).toBeNull()
|
|
51
|
+
})
|
|
52
|
+
|
|
53
|
+
it("is absent when the app does not wire creation", () => {
|
|
54
|
+
render(<Harness />)
|
|
55
|
+
expect(button()).toBeNull()
|
|
56
|
+
})
|
|
57
|
+
|
|
58
|
+
it("is absent for a provider that is not connected", () => {
|
|
59
|
+
render(<Harness providers={[{ ...GITHUB, connected: false }]} onCreateRepo={vi.fn()} />)
|
|
60
|
+
expect(button()).toBeNull()
|
|
61
|
+
})
|
|
62
|
+
|
|
63
|
+
it("creates under the first account, named after the project, private, and adds the row", async () => {
|
|
64
|
+
const onCreateRepo = vi.fn(async (input: CreateRepoInput) => ({
|
|
65
|
+
provider: input.provider,
|
|
66
|
+
fullName: `${input.owner}/${input.name}`,
|
|
67
|
+
private: input.private,
|
|
68
|
+
}))
|
|
69
|
+
const onRepos = vi.fn()
|
|
70
|
+
render(<Harness onCreateRepo={onCreateRepo} onRepos={onRepos} />)
|
|
71
|
+
|
|
72
|
+
fireEvent.click(button()!)
|
|
73
|
+
expect((screen.getByLabelText("Repository name") as HTMLInputElement).value).toBe("my-new-app")
|
|
74
|
+
fireEvent.click(screen.getByRole("button", { name: "Create repository" }))
|
|
75
|
+
|
|
76
|
+
await waitFor(() => expect(onRepos).toHaveBeenCalled())
|
|
77
|
+
expect(onCreateRepo).toHaveBeenCalledWith({ provider: "github", owner: "acme", name: "my-new-app", private: true })
|
|
78
|
+
expect(onRepos.mock.lastCall![0]).toEqual([
|
|
79
|
+
expect.objectContaining({ provider: "github", project: "acme/my-new-app", workspacePath: "my-new-app" }),
|
|
80
|
+
])
|
|
81
|
+
await waitFor(() => expect(screen.queryByRole("dialog")).toBeNull())
|
|
82
|
+
})
|
|
83
|
+
|
|
84
|
+
it("keeps the dialog open on the app's error, and adds nothing", async () => {
|
|
85
|
+
const onCreateRepo = vi.fn(async () => {
|
|
86
|
+
throw new Error("acme/my-new-app already exists on GitHub")
|
|
87
|
+
})
|
|
88
|
+
const onRepos = vi.fn()
|
|
89
|
+
render(<Harness onCreateRepo={onCreateRepo} onRepos={onRepos} />)
|
|
90
|
+
|
|
91
|
+
fireEvent.click(button()!)
|
|
92
|
+
fireEvent.click(screen.getByRole("button", { name: "Create repository" }))
|
|
93
|
+
|
|
94
|
+
expect(await screen.findByText("acme/my-new-app already exists on GitHub")).toBeTruthy()
|
|
95
|
+
expect(screen.getByRole("dialog")).toBeTruthy()
|
|
96
|
+
expect(onRepos).not.toHaveBeenCalled()
|
|
97
|
+
})
|
|
98
|
+
|
|
99
|
+
it("refuses a name the forge would refuse before asking", () => {
|
|
100
|
+
const onCreateRepo = vi.fn()
|
|
101
|
+
render(<Harness onCreateRepo={onCreateRepo} />)
|
|
102
|
+
fireEvent.click(button()!)
|
|
103
|
+
fireEvent.change(screen.getByLabelText("Repository name"), { target: { value: "my app" } })
|
|
104
|
+
expect((screen.getByRole("button", { name: "Create repository" }) as HTMLButtonElement).disabled).toBe(true)
|
|
105
|
+
expect(onCreateRepo).not.toHaveBeenCalled()
|
|
106
|
+
})
|
|
107
|
+
})
|
|
108
|
+
|
|
109
|
+
describe("repoNameFrom", () => {
|
|
110
|
+
it("slugs a project name into a repository name", () => {
|
|
111
|
+
expect(repoNameFrom(" My new App! ")).toBe("my-new-app")
|
|
112
|
+
expect(repoNameFrom("api.v2_tools")).toBe("api.v2_tools")
|
|
113
|
+
expect(repoNameFrom("")).toBe("")
|
|
114
|
+
})
|
|
115
|
+
})
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
|
|
3
|
+
import { useState } from "react"
|
|
4
|
+
import { LockIcon } from "lucide-react"
|
|
5
|
+
|
|
6
|
+
import { Alert, AlertDescription } from "../alert"
|
|
7
|
+
import { Button } from "../button"
|
|
8
|
+
import {
|
|
9
|
+
Dialog,
|
|
10
|
+
DialogClose,
|
|
11
|
+
DialogContent,
|
|
12
|
+
DialogDescription,
|
|
13
|
+
DialogFooter,
|
|
14
|
+
DialogHeader,
|
|
15
|
+
DialogTitle,
|
|
16
|
+
} from "../dialog"
|
|
17
|
+
import { Input } from "../input"
|
|
18
|
+
import { Label } from "../label"
|
|
19
|
+
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "../select"
|
|
20
|
+
import { Spinner } from "../spinner"
|
|
21
|
+
import { Switch } from "../switch"
|
|
22
|
+
import type { GitProvider } from "./repo-list"
|
|
23
|
+
|
|
24
|
+
/** What the dialog asks the app to create. `provider` is a `GitProvider.id`, `owner` one of its accounts. */
|
|
25
|
+
export interface CreateRepoInput {
|
|
26
|
+
provider: string
|
|
27
|
+
owner: string
|
|
28
|
+
name: string
|
|
29
|
+
private: boolean
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** GitHub's own rule, checked before the round trip: letters, digits, `.`, `-`, `_`. */
|
|
33
|
+
const VALID_NAME = /^[A-Za-z0-9._-]{1,100}$/
|
|
34
|
+
|
|
35
|
+
/** A project name as a repository name: "My new app" → `my-new-app`. */
|
|
36
|
+
export function repoNameFrom(projectName: string): string {
|
|
37
|
+
return projectName
|
|
38
|
+
.trim()
|
|
39
|
+
.toLowerCase()
|
|
40
|
+
.replace(/[^a-z0-9._-]+/g, "-")
|
|
41
|
+
.replace(/^-+|-+$/g, "")
|
|
42
|
+
.slice(0, 100)
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export interface CreateRepoDialogProps {
|
|
46
|
+
open: boolean
|
|
47
|
+
onOpenChange: (open: boolean) => void
|
|
48
|
+
/** Providers that declare `createRepo`; their `accounts` are the owners offered. */
|
|
49
|
+
providers: GitProvider[]
|
|
50
|
+
/** The project's name — slugged into the repository name the field starts with. */
|
|
51
|
+
defaultName?: string
|
|
52
|
+
/** Rejects with a readable `Error` to keep the dialog open and show the message. */
|
|
53
|
+
onCreate: (input: CreateRepoInput) => Promise<void>
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Creating an empty repository at the forge without leaving the project form: owner, name,
|
|
58
|
+
* private by default. The repository is created with a README, which is what gives it a default
|
|
59
|
+
* branch to clone — said in the description, because that file appearing is otherwise a surprise.
|
|
60
|
+
*/
|
|
61
|
+
export function CreateRepoDialog({ open, onOpenChange, providers, defaultName = "", onCreate }: CreateRepoDialogProps) {
|
|
62
|
+
return (
|
|
63
|
+
<Dialog open={open} onOpenChange={onOpenChange}>
|
|
64
|
+
<DialogContent>
|
|
65
|
+
{/* Mounted with the popup, so every opening starts from the project's current name. */}
|
|
66
|
+
<CreateRepoBody providers={providers} defaultName={defaultName} onCreate={onCreate} onDone={() => onOpenChange(false)} />
|
|
67
|
+
</DialogContent>
|
|
68
|
+
</Dialog>
|
|
69
|
+
)
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function CreateRepoBody({
|
|
73
|
+
providers,
|
|
74
|
+
defaultName,
|
|
75
|
+
onCreate,
|
|
76
|
+
onDone,
|
|
77
|
+
}: {
|
|
78
|
+
providers: GitProvider[]
|
|
79
|
+
defaultName: string
|
|
80
|
+
onCreate: (input: CreateRepoInput) => Promise<void>
|
|
81
|
+
onDone: () => void
|
|
82
|
+
}) {
|
|
83
|
+
// Every account the providers reach, as one list — the forge is a property of the owner picked.
|
|
84
|
+
const owners = providers.flatMap((p) =>
|
|
85
|
+
(p.accounts ?? []).map((a) => ({ key: `${p.id}:${a.login}`, provider: p.id, login: a.login })),
|
|
86
|
+
)
|
|
87
|
+
const [owner, setOwner] = useState(owners[0]?.key ?? "")
|
|
88
|
+
const [name, setName] = useState(() => repoNameFrom(defaultName))
|
|
89
|
+
const [isPrivate, setPrivate] = useState(true)
|
|
90
|
+
const [busy, setBusy] = useState(false)
|
|
91
|
+
const [error, setError] = useState<string | null>(null)
|
|
92
|
+
|
|
93
|
+
const picked = owners.find((o) => o.key === owner)
|
|
94
|
+
const invalid = name !== "" && !VALID_NAME.test(name)
|
|
95
|
+
const canSubmit = !!picked && !!name && !invalid && !busy
|
|
96
|
+
|
|
97
|
+
async function submit() {
|
|
98
|
+
if (!canSubmit) return
|
|
99
|
+
setBusy(true)
|
|
100
|
+
setError(null)
|
|
101
|
+
try {
|
|
102
|
+
await onCreate({ provider: picked!.provider, owner: picked!.login, name, private: isPrivate })
|
|
103
|
+
onDone()
|
|
104
|
+
} catch (err) {
|
|
105
|
+
setError(err instanceof Error ? err.message : "Could not create the repository")
|
|
106
|
+
} finally {
|
|
107
|
+
setBusy(false)
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
return (
|
|
112
|
+
<>
|
|
113
|
+
<DialogHeader>
|
|
114
|
+
<DialogTitle>New repository</DialogTitle>
|
|
115
|
+
<DialogDescription>
|
|
116
|
+
Created empty with a README, so it has a default branch to clone. It is added to this project.
|
|
117
|
+
</DialogDescription>
|
|
118
|
+
</DialogHeader>
|
|
119
|
+
|
|
120
|
+
{/* No <form>: this renders in a portal inside the project form, and a submit event bubbles
|
|
121
|
+
through React portals — Enter here would have saved the project. */}
|
|
122
|
+
<div className="grid gap-4">
|
|
123
|
+
<div className="grid grid-cols-[minmax(0,2fr)_auto_minmax(0,3fr)] items-end gap-2">
|
|
124
|
+
<div className="grid gap-1.5">
|
|
125
|
+
<Label>Owner</Label>
|
|
126
|
+
<Select value={owner || null} onValueChange={(v) => setOwner((v as string | null) ?? "")}>
|
|
127
|
+
<SelectTrigger aria-label="Owner">
|
|
128
|
+
<SelectValue placeholder="Pick an account">
|
|
129
|
+
{(value: unknown) => owners.find((o) => o.key === value)?.login ?? "Pick an account"}
|
|
130
|
+
</SelectValue>
|
|
131
|
+
</SelectTrigger>
|
|
132
|
+
<SelectContent>
|
|
133
|
+
{owners.map((o) => (
|
|
134
|
+
<SelectItem key={o.key} value={o.key}>
|
|
135
|
+
{o.login}
|
|
136
|
+
</SelectItem>
|
|
137
|
+
))}
|
|
138
|
+
</SelectContent>
|
|
139
|
+
</Select>
|
|
140
|
+
</div>
|
|
141
|
+
<span className="pb-2 text-muted-foreground">/</span>
|
|
142
|
+
<div className="grid gap-1.5">
|
|
143
|
+
<Label htmlFor="new-repo-name">Repository name</Label>
|
|
144
|
+
<Input
|
|
145
|
+
id="new-repo-name"
|
|
146
|
+
className="font-mono text-sm"
|
|
147
|
+
value={name}
|
|
148
|
+
aria-invalid={invalid || !!error || undefined}
|
|
149
|
+
onChange={(e) => {
|
|
150
|
+
setName(e.target.value)
|
|
151
|
+
setError(null)
|
|
152
|
+
}}
|
|
153
|
+
onKeyDown={(e) => {
|
|
154
|
+
if (e.key === "Enter") {
|
|
155
|
+
e.preventDefault()
|
|
156
|
+
void submit()
|
|
157
|
+
}
|
|
158
|
+
}}
|
|
159
|
+
/>
|
|
160
|
+
</div>
|
|
161
|
+
</div>
|
|
162
|
+
{invalid && <p className="-mt-2 text-xs text-destructive">Letters, digits, “.”, “-” and “_” only.</p>}
|
|
163
|
+
|
|
164
|
+
<label className="flex items-center justify-between gap-4 rounded border p-3">
|
|
165
|
+
<span className="flex items-center gap-2 text-sm">
|
|
166
|
+
<LockIcon className="h-4 w-4 text-muted-foreground" />
|
|
167
|
+
<span>
|
|
168
|
+
Private
|
|
169
|
+
<span className="block text-xs text-muted-foreground">Only people you give access to can see it.</span>
|
|
170
|
+
</span>
|
|
171
|
+
</span>
|
|
172
|
+
<Switch checked={isPrivate} onCheckedChange={setPrivate} aria-label="Private" />
|
|
173
|
+
</label>
|
|
174
|
+
|
|
175
|
+
{error && (
|
|
176
|
+
<Alert variant="error">
|
|
177
|
+
<AlertDescription>{error}</AlertDescription>
|
|
178
|
+
</Alert>
|
|
179
|
+
)}
|
|
180
|
+
</div>
|
|
181
|
+
|
|
182
|
+
<DialogFooter>
|
|
183
|
+
<DialogClose render={<Button type="button" variant="outline" size="sm" />}>Cancel</DialogClose>
|
|
184
|
+
<Button type="button" size="sm" disabled={!canSubmit} onClick={() => void submit()}>
|
|
185
|
+
{busy && <Spinner className="mr-1.5 h-3.5 w-3.5" />}
|
|
186
|
+
{busy ? "Creating…" : "Create repository"}
|
|
187
|
+
</Button>
|
|
188
|
+
</DialogFooter>
|
|
189
|
+
</>
|
|
190
|
+
)
|
|
191
|
+
}
|
|
@@ -46,6 +46,9 @@ export type { BuildManifestProps, ManifestRow } from "./build-manifest"
|
|
|
46
46
|
export { RepoList, deriveFromGitUrl } from "./repo-list"
|
|
47
47
|
export type { RepoListProps, GitRepoOption, GitProvider, RepoFieldRender } from "./repo-list"
|
|
48
48
|
|
|
49
|
+
export { CreateRepoDialog, repoNameFrom } from "./create-repo-dialog"
|
|
50
|
+
export type { CreateRepoDialogProps, CreateRepoInput } from "./create-repo-dialog"
|
|
51
|
+
|
|
49
52
|
export { SecretList } from "./secret-list"
|
|
50
53
|
export type { SecretListProps } from "./secret-list"
|
|
51
54
|
|
|
@@ -28,7 +28,7 @@ import { BuildManifest, type ManifestRow } from "./build-manifest"
|
|
|
28
28
|
import { Field, FormSection, type SectionAccent } from "./form-section"
|
|
29
29
|
import { FormNav, SectionStatusBadge, type FormNavItem } from "./form-nav"
|
|
30
30
|
import { isSectionRequired, sectionSummary } from "./section-status"
|
|
31
|
-
import { RepoList, type GitProvider, type GitRepoOption, type RepoFieldRender } from "./repo-list"
|
|
31
|
+
import { RepoList, type GitProvider, type GitRepoOption, type RepoFieldRender, type RepoListProps } from "./repo-list"
|
|
32
32
|
import { SecretList } from "./secret-list"
|
|
33
33
|
import {
|
|
34
34
|
CREATE_SECTIONS,
|
|
@@ -190,6 +190,8 @@ export interface ProjectFormProps<TValue extends ProjectFormValue = ProjectFormV
|
|
|
190
190
|
gitRepos?: GitRepoOption[]
|
|
191
191
|
/** App-level combobox for the repo field; without it, a plain input + datalist. */
|
|
192
192
|
renderRepoField?: RepoFieldRender
|
|
193
|
+
/** Creates an empty repository (providers declaring `createRepo`); absent → no "New repository". */
|
|
194
|
+
onCreateRepo?: RepoListProps["onCreateRepo"]
|
|
193
195
|
|
|
194
196
|
/** Searches Open VSX (or any marketplace). Absent → extensions are typed by hand. */
|
|
195
197
|
onSearchExtensions?: (query: string) => Promise<VscodeExtensionEntry[]>
|
|
@@ -268,6 +270,7 @@ export function ProjectForm<TValue extends ProjectFormValue = ProjectFormValue>(
|
|
|
268
270
|
gitProviders,
|
|
269
271
|
gitRepos,
|
|
270
272
|
renderRepoField,
|
|
273
|
+
onCreateRepo,
|
|
271
274
|
onSearchExtensions,
|
|
272
275
|
savedSecrets,
|
|
273
276
|
extras,
|
|
@@ -608,6 +611,8 @@ export function ProjectForm<TValue extends ProjectFormValue = ProjectFormValue>(
|
|
|
608
611
|
gitProviders={gitProviders}
|
|
609
612
|
gitRepos={gitRepos}
|
|
610
613
|
renderRepoField={renderRepoField}
|
|
614
|
+
onCreateRepo={onCreateRepo}
|
|
615
|
+
suggestedRepoName={value.name}
|
|
611
616
|
/>
|
|
612
617
|
)
|
|
613
618
|
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
"use client"
|
|
2
2
|
|
|
3
|
-
import type
|
|
4
|
-
import { GitBranchIcon, Trash2Icon } from "lucide-react"
|
|
3
|
+
import { useState, type ReactNode } from "react"
|
|
4
|
+
import { GitBranchIcon, PlusIcon, Trash2Icon } from "lucide-react"
|
|
5
5
|
|
|
6
6
|
import { cn } from "../../utils"
|
|
7
7
|
import { Button } from "../button"
|
|
8
8
|
import { Input } from "../input"
|
|
9
|
+
import { CreateRepoDialog, type CreateRepoInput } from "./create-repo-dialog"
|
|
9
10
|
import type { ProjectRepo } from "./types"
|
|
10
11
|
|
|
11
12
|
/** A repository the user can pick, and which provider can reach it. */
|
|
@@ -65,6 +66,14 @@ export interface RepoListProps {
|
|
|
65
66
|
/** Repositories reachable across every connected provider. */
|
|
66
67
|
gitRepos?: GitRepoOption[]
|
|
67
68
|
renderRepoField?: RepoFieldRender
|
|
69
|
+
/**
|
|
70
|
+
* Creates an empty repository on a provider that declares `createRepo`, and resolves with it —
|
|
71
|
+
* the new row is added already picked. Rejecting with an `Error` keeps the dialog open on its
|
|
72
|
+
* message. Absent: no "New repository" button, whatever the providers declare.
|
|
73
|
+
*/
|
|
74
|
+
onCreateRepo?: (input: CreateRepoInput) => Promise<GitRepoOption>
|
|
75
|
+
/** Pre-fills the new repository's name — the project name, slugged. */
|
|
76
|
+
suggestedRepoName?: string
|
|
68
77
|
className?: string
|
|
69
78
|
}
|
|
70
79
|
|
|
@@ -133,13 +142,19 @@ export function RepoList({
|
|
|
133
142
|
gitProviders = [],
|
|
134
143
|
gitRepos = [],
|
|
135
144
|
renderRepoField,
|
|
145
|
+
onCreateRepo,
|
|
146
|
+
suggestedRepoName = "",
|
|
136
147
|
className,
|
|
137
148
|
}: RepoListProps) {
|
|
149
|
+
const [creating, setCreating] = useState(false)
|
|
138
150
|
// A provider is only offerable if it can actually list or clone. Read from `operations` rather
|
|
139
151
|
// than from a provider id, so a forge added tomorrow shows up here with no change to this file.
|
|
140
152
|
const pickable = gitProviders.filter((p) => p.operations?.includes("cloneCredential") ?? true)
|
|
141
153
|
const connected = pickable.filter((p) => p.connected)
|
|
142
154
|
const hasRawGitRepos = repos.some((r) => r.provider === RAW_GIT)
|
|
155
|
+
// A provider offers creation by declaring it, like everything else here — never by its id. And
|
|
156
|
+
// only with an account to create under: the dialog has nothing to offer otherwise.
|
|
157
|
+
const creatable = connected.filter((p) => p.operations?.includes("createRepo") && p.accounts?.length)
|
|
143
158
|
|
|
144
159
|
const providerOf = (repo: ProjectRepo) => pickable.find((p) => p.id === repo.provider)
|
|
145
160
|
/**
|
|
@@ -311,8 +326,35 @@ export function RepoList({
|
|
|
311
326
|
<GitBranchIcon className="mr-1 h-4 w-4" />
|
|
312
327
|
Add Git URL
|
|
313
328
|
</Button>
|
|
329
|
+
{onCreateRepo && creatable.length > 0 && (
|
|
330
|
+
<Button type="button" variant="outline" size="sm" onClick={() => setCreating(true)}>
|
|
331
|
+
<PlusIcon className="mr-1 h-4 w-4" />
|
|
332
|
+
New repository
|
|
333
|
+
</Button>
|
|
334
|
+
)}
|
|
314
335
|
</div>
|
|
315
336
|
|
|
337
|
+
{onCreateRepo && creatable.length > 0 && (
|
|
338
|
+
<CreateRepoDialog
|
|
339
|
+
open={creating}
|
|
340
|
+
onOpenChange={setCreating}
|
|
341
|
+
providers={creatable}
|
|
342
|
+
defaultName={suggestedRepoName}
|
|
343
|
+
onCreate={async (input) => {
|
|
344
|
+
const created = await onCreateRepo(input)
|
|
345
|
+
onChange([
|
|
346
|
+
...repos,
|
|
347
|
+
{
|
|
348
|
+
id: localRepoId(repos),
|
|
349
|
+
provider: created.provider,
|
|
350
|
+
project: created.fullName,
|
|
351
|
+
workspacePath: created.fullName.split("/")[1] ?? created.fullName,
|
|
352
|
+
},
|
|
353
|
+
])
|
|
354
|
+
}}
|
|
355
|
+
/>
|
|
356
|
+
)}
|
|
357
|
+
|
|
316
358
|
<p className="text-xs text-muted-foreground">
|
|
317
359
|
Cloned into <code>/workspace/<path></code> at worker startup, on the branch set here (empty = the
|
|
318
360
|
remote's default).
|
|
@@ -86,6 +86,7 @@ export type { TaskDiffPanelProps } from "./diff-panel"
|
|
|
86
86
|
export { TaskTerminalPanel } from "./terminal-panel"
|
|
87
87
|
export type { TaskTerminalPanelProps } from "./terminal-panel"
|
|
88
88
|
export { TaskPullRequest } from "./pull-request"
|
|
89
|
+
export { TaskSharedFiles, TaskSharedLinks } from "./shared"
|
|
89
90
|
export { TaskSessionUsage, formatCost, formatTokens } from "./session-usage"
|
|
90
91
|
export { TaskCommandLog } from "./command-log"
|
|
91
92
|
export { TaskBoot, TaskMachine, bootSteps, workerLabel } from "./machine"
|
|
@@ -116,6 +117,9 @@ export type {
|
|
|
116
117
|
TaskPullRequestData,
|
|
117
118
|
TaskPullRequests,
|
|
118
119
|
TaskRepoDiff,
|
|
120
|
+
TaskSharedData,
|
|
121
|
+
TaskSharedFile,
|
|
122
|
+
TaskSharedLink,
|
|
119
123
|
TaskSessionUsageData,
|
|
120
124
|
TaskState,
|
|
121
125
|
} from "./types"
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
|
|
3
|
+
// What circulated in a conversation — the links either side wrote, the files passed — as two
|
|
4
|
+
// lists in the details column (docs/tasks.md § « Ce qui a circulé dans la conversation »).
|
|
5
|
+
//
|
|
6
|
+
// Newest first, the order the API hands them in: the link someone comes back for is usually the
|
|
7
|
+
// PR or the preview the agent gave at the end of its last turn, not the one from an hour ago.
|
|
8
|
+
// Each row says who brought it (the same two markers as the timeline) and when, so "the doc I
|
|
9
|
+
// pasted" and "the page the agent opened" can be told apart without reading the session again.
|
|
10
|
+
|
|
11
|
+
import { useState, type ReactNode } from "react"
|
|
12
|
+
import { DownloadIcon, ExternalLinkIcon, SparklesIcon, UserIcon } from "lucide-react"
|
|
13
|
+
|
|
14
|
+
import { formatRelativeTime } from "../../utils"
|
|
15
|
+
import { fileKind, formatBytes, isPreviewable } from "./attachments"
|
|
16
|
+
import type { AttachmentUrl, TaskSharedFile, TaskSharedLink } from "./types"
|
|
17
|
+
|
|
18
|
+
/** Rows shown before « Show all » — the column is glanced at, not read. */
|
|
19
|
+
const FOLDED = 6
|
|
20
|
+
|
|
21
|
+
function Who({ mine }: { mine: boolean }) {
|
|
22
|
+
return mine ? (
|
|
23
|
+
<UserIcon aria-label="Shared by a member" className="h-3 w-3 shrink-0 text-muted-foreground" />
|
|
24
|
+
) : (
|
|
25
|
+
<SparklesIcon aria-label="Shared by the agent" className="h-3 w-3 shrink-0 text-muted-foreground" />
|
|
26
|
+
)
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function Folded<T>({ items, render }: { items: T[]; render: (item: T) => ReactNode }) {
|
|
30
|
+
const [all, setAll] = useState(false)
|
|
31
|
+
const shown = all ? items : items.slice(0, FOLDED)
|
|
32
|
+
return (
|
|
33
|
+
<>
|
|
34
|
+
<ul className="space-y-1.5">{shown.map(render)}</ul>
|
|
35
|
+
{items.length > FOLDED && (
|
|
36
|
+
<button
|
|
37
|
+
type="button"
|
|
38
|
+
onClick={() => setAll((v) => !v)}
|
|
39
|
+
className="mt-2 text-[11px] text-muted-foreground transition-colors hover:text-foreground"
|
|
40
|
+
>
|
|
41
|
+
{all ? "Show fewer" : `Show all ${items.length}`}
|
|
42
|
+
</button>
|
|
43
|
+
)}
|
|
44
|
+
</>
|
|
45
|
+
)
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** `github.com/o/r/pull/9` — the host is what tells two links apart at a glance. */
|
|
49
|
+
function shortUrl(url: string): { host: string; rest: string } {
|
|
50
|
+
try {
|
|
51
|
+
const u = new URL(url)
|
|
52
|
+
const rest = `${u.pathname === "/" ? "" : u.pathname}${u.search}${u.hash}`
|
|
53
|
+
return { host: u.host.replace(/^www\./, ""), rest }
|
|
54
|
+
} catch {
|
|
55
|
+
return { host: url, rest: "" }
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export function TaskSharedLinks({ links, className }: { links: TaskSharedLink[]; className?: string }) {
|
|
60
|
+
if (links.length === 0) return null
|
|
61
|
+
return (
|
|
62
|
+
<div className={className}>
|
|
63
|
+
<Folded
|
|
64
|
+
items={links}
|
|
65
|
+
render={(link) => {
|
|
66
|
+
const { host, rest } = shortUrl(link.url)
|
|
67
|
+
return (
|
|
68
|
+
<li key={link.url} className="min-w-0">
|
|
69
|
+
<a
|
|
70
|
+
href={link.url}
|
|
71
|
+
target="_blank"
|
|
72
|
+
rel="noreferrer"
|
|
73
|
+
title={link.url}
|
|
74
|
+
className="group/link flex min-w-0 items-start gap-1.5 rounded text-xs"
|
|
75
|
+
>
|
|
76
|
+
<span className="mt-0.5">
|
|
77
|
+
<Who mine={link.role === "user"} />
|
|
78
|
+
</span>
|
|
79
|
+
<span className="min-w-0 flex-1">
|
|
80
|
+
<span className="flex min-w-0 items-center gap-1 text-primary group-hover/link:underline">
|
|
81
|
+
<span className="truncate">{link.label ?? `${host}${rest}`}</span>
|
|
82
|
+
<ExternalLinkIcon className="h-3 w-3 shrink-0" />
|
|
83
|
+
</span>
|
|
84
|
+
<span className="block truncate text-[10px] text-muted-foreground">
|
|
85
|
+
{link.label ? `${host} · ` : ""}
|
|
86
|
+
{formatRelativeTime(link.lastTs)}
|
|
87
|
+
{link.count > 1 && ` · ×${link.count}`}
|
|
88
|
+
</span>
|
|
89
|
+
</span>
|
|
90
|
+
</a>
|
|
91
|
+
</li>
|
|
92
|
+
)
|
|
93
|
+
}}
|
|
94
|
+
/>
|
|
95
|
+
</div>
|
|
96
|
+
)
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export function TaskSharedFiles({
|
|
100
|
+
files,
|
|
101
|
+
attachmentUrl,
|
|
102
|
+
className,
|
|
103
|
+
}: {
|
|
104
|
+
files: TaskSharedFile[]
|
|
105
|
+
attachmentUrl: AttachmentUrl
|
|
106
|
+
className?: string
|
|
107
|
+
}) {
|
|
108
|
+
if (files.length === 0) return null
|
|
109
|
+
return (
|
|
110
|
+
<div className={className}>
|
|
111
|
+
<Folded
|
|
112
|
+
items={files}
|
|
113
|
+
render={(file) => {
|
|
114
|
+
const image = isPreviewable(file.mediaType)
|
|
115
|
+
return (
|
|
116
|
+
<li key={file.id} className="min-w-0">
|
|
117
|
+
<a
|
|
118
|
+
href={attachmentUrl(file.id)}
|
|
119
|
+
// Images open (the API serves them with their own type); everything else is
|
|
120
|
+
// answered as a download, and the attribute names it before any header arrives.
|
|
121
|
+
{...(image ? { target: "_blank", rel: "noreferrer" } : { download: file.filename ?? undefined })}
|
|
122
|
+
title={file.filename ?? undefined}
|
|
123
|
+
className="group/file flex min-w-0 items-center gap-2 rounded text-xs"
|
|
124
|
+
>
|
|
125
|
+
{image ? (
|
|
126
|
+
<img
|
|
127
|
+
src={attachmentUrl(file.id)}
|
|
128
|
+
alt=""
|
|
129
|
+
loading="lazy"
|
|
130
|
+
className="h-7 w-7 shrink-0 rounded border bg-muted/40 object-cover"
|
|
131
|
+
/>
|
|
132
|
+
) : (
|
|
133
|
+
<span className="flex h-7 w-7 shrink-0 items-center justify-center rounded bg-muted text-[8px] font-semibold text-muted-foreground">
|
|
134
|
+
{fileKind(file.filename ?? "", file.mediaType)}
|
|
135
|
+
</span>
|
|
136
|
+
)}
|
|
137
|
+
<span className="min-w-0 flex-1">
|
|
138
|
+
<span className="block truncate group-hover/file:underline">{file.filename ?? (image ? "Image" : "Attachment")}</span>
|
|
139
|
+
<span className="flex items-center gap-1 text-[10px] text-muted-foreground">
|
|
140
|
+
<Who mine={file.origin === "user"} />
|
|
141
|
+
{formatBytes(file.bytes)} · {formatRelativeTime(file.createdAt)}
|
|
142
|
+
</span>
|
|
143
|
+
</span>
|
|
144
|
+
{image ? (
|
|
145
|
+
<ExternalLinkIcon className="h-3 w-3 shrink-0 text-muted-foreground/60 group-hover/file:text-foreground" />
|
|
146
|
+
) : (
|
|
147
|
+
<DownloadIcon className="h-3 w-3 shrink-0 text-muted-foreground/60 group-hover/file:text-foreground" />
|
|
148
|
+
)}
|
|
149
|
+
</a>
|
|
150
|
+
</li>
|
|
151
|
+
)
|
|
152
|
+
}}
|
|
153
|
+
/>
|
|
154
|
+
</div>
|
|
155
|
+
)
|
|
156
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use client"
|
|
2
2
|
|
|
3
3
|
// Everything that is a *fact about* a task rather than a moment in it — branch, cost, the pull
|
|
4
|
-
// request, the machine, the prompt, what ran — in one component with two shapes:
|
|
4
|
+
// request, what was shared in the conversation, the machine, the prompt, what ran — in one component with two shapes:
|
|
5
5
|
//
|
|
6
6
|
// - `sidebar`: the cockpit's right column, each block a fold, glanced at without pushing the
|
|
7
7
|
// work off screen;
|
|
@@ -20,8 +20,9 @@ import { cn, formatRelativeTime } from "../../utils"
|
|
|
20
20
|
import { TaskCommandLog } from "./command-log"
|
|
21
21
|
import { TaskPullRequest } from "./pull-request"
|
|
22
22
|
import { TaskSessionUsage } from "./session-usage"
|
|
23
|
+
import { TaskSharedFiles, TaskSharedLinks } from "./shared"
|
|
23
24
|
import { isLiveTaskState, taskSpan } from "./task-state"
|
|
24
|
-
import type { TaskCommand, TaskItem, TaskPendingAction, TaskPullRequests, TaskSessionUsageData } from "./types"
|
|
25
|
+
import type { AttachmentUrl, TaskCommand, TaskItem, TaskPendingAction, TaskPullRequests, TaskSessionUsageData, TaskSharedData } from "./types"
|
|
25
26
|
|
|
26
27
|
/** Set by `TaskCockpitMobile` around its sheet, so Drop can close it. @internal */
|
|
27
28
|
export const TaskDetailsSheetContext = createContext<{ close: () => void } | null>(null)
|
|
@@ -34,6 +35,12 @@ export interface TaskDetailsProps {
|
|
|
34
35
|
usage?: TaskSessionUsageData | null
|
|
35
36
|
/** What the forge says about the branch. Absent or `supported: false` → no block at all. */
|
|
36
37
|
pullRequests?: TaskPullRequests | null
|
|
38
|
+
/**
|
|
39
|
+
* The links and files that circulated in the conversation (`GET .../shared`). Each list is its
|
|
40
|
+
* own block, absent while empty. Files need `attachmentUrl` to be drawn.
|
|
41
|
+
*/
|
|
42
|
+
shared?: TaskSharedData | null
|
|
43
|
+
attachmentUrl?: AttachmentUrl
|
|
37
44
|
/** The Machine block's content — typically a `TaskMachine`. */
|
|
38
45
|
machine?: ReactNode
|
|
39
46
|
/** Every command the platform ran for the task, oldest first. */
|
|
@@ -123,6 +130,8 @@ export function TaskDetails({
|
|
|
123
130
|
variant = "sidebar",
|
|
124
131
|
usage,
|
|
125
132
|
pullRequests,
|
|
133
|
+
shared,
|
|
134
|
+
attachmentUrl,
|
|
126
135
|
machine,
|
|
127
136
|
commands = [],
|
|
128
137
|
protocol = "none",
|
|
@@ -217,6 +226,20 @@ export function TaskDetails({
|
|
|
217
226
|
</Block>
|
|
218
227
|
)}
|
|
219
228
|
|
|
229
|
+
{/* After the PR, before the machine: what the conversation handed over is what a reader
|
|
230
|
+
comes back for — the preview URL, the doc pasted at the start, the screenshot. */}
|
|
231
|
+
{shared && shared.links.length > 0 && (
|
|
232
|
+
<Block variant={variant} title="Shared links" hint={String(shared.links.length)}>
|
|
233
|
+
<TaskSharedLinks links={shared.links} />
|
|
234
|
+
</Block>
|
|
235
|
+
)}
|
|
236
|
+
|
|
237
|
+
{shared && attachmentUrl && shared.files.length > 0 && (
|
|
238
|
+
<Block variant={variant} title="Shared files" hint={String(shared.files.length)}>
|
|
239
|
+
<TaskSharedFiles files={shared.files} attachmentUrl={attachmentUrl} />
|
|
240
|
+
</Block>
|
|
241
|
+
)}
|
|
242
|
+
|
|
220
243
|
{machine && (
|
|
221
244
|
<Block variant={variant} title="Machine">
|
|
222
245
|
{machine}
|
|
@@ -237,6 +237,31 @@ export interface TaskPullRequests {
|
|
|
237
237
|
repos: { repo: string; pullRequest: TaskPullRequestData | null; error?: string | null }[]
|
|
238
238
|
}
|
|
239
239
|
|
|
240
|
+
// ── Shared in the conversation ──────────────────────────────────────────────────────────────
|
|
241
|
+
|
|
242
|
+
/** A link written in the conversation (`GET .../tasks/{id}/shared`), deduplicated on its URL. */
|
|
243
|
+
export interface TaskSharedLink {
|
|
244
|
+
url: string
|
|
245
|
+
/** A markdown link's text; null for a bare URL. */
|
|
246
|
+
label: string | null
|
|
247
|
+
/** Who wrote it first. */
|
|
248
|
+
role: "user" | "assistant"
|
|
249
|
+
count: number
|
|
250
|
+
/** When it was last written — the list is newest first. */
|
|
251
|
+
lastTs: string
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
/** A file attached to, or shown in, the conversation. */
|
|
255
|
+
export interface TaskSharedFile extends TaskFileRef {
|
|
256
|
+
origin: "user" | "agent"
|
|
257
|
+
createdAt: string
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
export interface TaskSharedData {
|
|
261
|
+
links: TaskSharedLink[]
|
|
262
|
+
files: TaskSharedFile[]
|
|
263
|
+
}
|
|
264
|
+
|
|
240
265
|
// ── Machine ──────────────────────────────────────────────────────────────────────────────────
|
|
241
266
|
|
|
242
267
|
/** The node a task's worker lives on. */
|