ref0-git 0.3.0 → 0.4.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.
Files changed (210) hide show
  1. package/app/apps/github/.dev.vars.example +2 -1
  2. package/app/apps/github/generated/git-rest.ts +191 -25
  3. package/app/apps/github/generated/routeTree.gen.ts +21 -0
  4. package/app/apps/github/package.json +1 -1
  5. package/app/apps/github/src/branches/branch-list.tsx +8 -4
  6. package/app/apps/github/src/branches/branches.ts +10 -5
  7. package/app/apps/github/src/camo/addresses.ts +120 -0
  8. package/app/apps/github/src/camo/client.ts +125 -0
  9. package/app/apps/github/src/camo/fetch.ts +201 -0
  10. package/app/apps/github/src/camo/lookup.ts +23 -0
  11. package/app/apps/github/src/camo/node.ts +50 -0
  12. package/app/apps/github/src/camo/proxy.ts +116 -0
  13. package/app/apps/github/src/camo/sign-images.ts +307 -0
  14. package/app/apps/github/src/camo/signing.ts +80 -0
  15. package/app/apps/github/src/clients/allowed.ts +111 -18
  16. package/app/apps/github/src/clients/clients.ts +76 -61
  17. package/app/apps/github/src/clients/transport.ts +13 -0
  18. package/app/apps/github/src/code/code-tree.tsx +3 -1
  19. package/app/apps/github/src/code/file-view.tsx +15 -6
  20. package/app/apps/github/src/code/files.ts +26 -19
  21. package/app/apps/github/src/code/go-to-file.tsx +2 -1
  22. package/app/apps/github/src/code/load.ts +41 -23
  23. package/app/apps/github/src/code/markdown-files.ts +13 -2
  24. package/app/apps/github/src/code/ref-pages.ts +14 -5
  25. package/app/apps/github/src/code/ref-switcher.tsx +4 -3
  26. package/app/apps/github/src/code/refs.ts +42 -8
  27. package/app/apps/github/src/code/repo-home.tsx +6 -2
  28. package/app/apps/github/src/code/repo.ts +12 -6
  29. package/app/apps/github/src/code/saved.ts +5 -3
  30. package/app/apps/github/src/code/trees.ts +11 -9
  31. package/app/apps/github/src/components/markdown/markdown.css +6 -0
  32. package/app/apps/github/src/components/markdown/markdown.tsx +95 -10
  33. package/app/apps/github/src/components/owner-card.tsx +3 -1
  34. package/app/apps/github/src/components/repos/your-repos.tsx +3 -1
  35. package/app/apps/github/src/components/shell/owner-repos.tsx +7 -12
  36. package/app/apps/github/src/components/shell/repo-switcher.tsx +10 -16
  37. package/app/apps/github/src/components/signin/device-card.tsx +9 -2
  38. package/app/apps/github/src/components/user-avatar.tsx +2 -1
  39. package/app/apps/github/src/context/context.ts +13 -0
  40. package/app/apps/github/src/diffs/blobs.ts +37 -14
  41. package/app/apps/github/src/diffs/diff-job.ts +53 -0
  42. package/app/apps/github/src/diffs/diff-worker.ts +6 -0
  43. package/app/apps/github/src/diffs/diffing.ts +136 -0
  44. package/app/apps/github/src/diffs/files.ts +4 -3
  45. package/app/apps/github/src/diffs/hunks.tsx +101 -53
  46. package/app/apps/github/src/diffs/patch.ts +20 -11
  47. package/app/apps/github/src/history/commit-diff.ts +10 -5
  48. package/app/apps/github/src/history/commit-list.tsx +3 -1
  49. package/app/apps/github/src/history/commit-page.tsx +4 -2
  50. package/app/apps/github/src/history/history.ts +12 -10
  51. package/app/apps/github/src/hooks/allowed.ts +9 -9
  52. package/app/apps/github/src/hooks/avatars.ts +3 -3
  53. package/app/apps/github/src/hooks/open-counts.ts +5 -4
  54. package/app/apps/github/src/hooks/profiles.ts +26 -12
  55. package/app/apps/github/src/hooks/repos.ts +78 -25
  56. package/app/apps/github/src/inbox/count.ts +30 -29
  57. package/app/apps/github/src/inbox/inbox-item.tsx +3 -1
  58. package/app/apps/github/src/inbox/inbox-page.tsx +5 -2
  59. package/app/apps/github/src/inbox/marks.ts +26 -15
  60. package/app/apps/github/src/inbox/release-tags.ts +7 -6
  61. package/app/apps/github/src/inbox/subjects.ts +5 -4
  62. package/app/apps/github/src/inbox/subscription-controls.tsx +14 -5
  63. package/app/apps/github/src/inbox/subscriptions.ts +95 -35
  64. package/app/apps/github/src/inbox/threads.ts +6 -6
  65. package/app/apps/github/src/issues/changes.ts +40 -16
  66. package/app/apps/github/src/issues/counts.ts +8 -5
  67. package/app/apps/github/src/issues/issue-list.tsx +20 -6
  68. package/app/apps/github/src/issues/issue-page.tsx +30 -14
  69. package/app/apps/github/src/issues/issues.ts +195 -46
  70. package/app/apps/github/src/issues/label-dialog.tsx +8 -11
  71. package/app/apps/github/src/issues/labels-page.tsx +35 -3
  72. package/app/apps/github/src/issues/milestone-dialog.tsx +197 -0
  73. package/app/apps/github/src/issues/milestones-page.tsx +269 -0
  74. package/app/apps/github/src/issues/new-issue.tsx +3 -1
  75. package/app/apps/github/src/issues/sidebar.tsx +8 -6
  76. package/app/apps/github/src/markdown/README.md +22 -17
  77. package/app/apps/github/src/markdown/context.ts +83 -10
  78. package/app/apps/github/src/markdown/images.ts +3 -2
  79. package/app/apps/github/src/markdown/lookup.ts +9 -8
  80. package/app/apps/github/src/markdown/page-budget.ts +50 -0
  81. package/app/apps/github/src/markdown/patches.ts +74 -32
  82. package/app/apps/github/src/markdown/query.ts +7 -2
  83. package/app/apps/github/src/markdown/remote.ts +106 -0
  84. package/app/apps/github/src/markdown/render.ts +101 -24
  85. package/app/apps/github/src/markdown/texts.ts +43 -0
  86. package/app/apps/github/src/markdown/words-module.d.ts +5 -0
  87. package/app/apps/github/src/markdown/words-plugin.ts +135 -0
  88. package/app/apps/github/src/names/repos.ts +1 -1
  89. package/app/apps/github/src/palette/palette.tsx +7 -4
  90. package/app/apps/github/src/palette/rows.tsx +54 -33
  91. package/app/apps/github/src/palette/server.ts +5 -5
  92. package/app/apps/github/src/palette/targets.ts +1 -0
  93. package/app/apps/github/src/policy.ts +131 -61
  94. package/app/apps/github/src/private-repos.ts +2 -2
  95. package/app/apps/github/src/pulls/compare-page.tsx +6 -3
  96. package/app/apps/github/src/pulls/files-tab.tsx +480 -214
  97. package/app/apps/github/src/pulls/held-summary.ts +178 -0
  98. package/app/apps/github/src/pulls/live.ts +6 -4
  99. package/app/apps/github/src/pulls/merge-box.tsx +17 -10
  100. package/app/apps/github/src/pulls/pull-list.tsx +6 -3
  101. package/app/apps/github/src/pulls/pull-page.tsx +19 -10
  102. package/app/apps/github/src/pulls/pull.ts +68 -40
  103. package/app/apps/github/src/pulls/pulls.ts +39 -22
  104. package/app/apps/github/src/pulls/review-drafts.ts +131 -0
  105. package/app/apps/github/src/pulls/review.ts +374 -99
  106. package/app/apps/github/src/pulls/threads.tsx +152 -0
  107. package/app/apps/github/src/queue/queue-page.tsx +15 -8
  108. package/app/apps/github/src/queue/queue.ts +35 -20
  109. package/app/apps/github/src/releases/latest-release.tsx +3 -1
  110. package/app/apps/github/src/releases/overview.tsx +4 -2
  111. package/app/apps/github/src/releases/release-form.tsx +8 -5
  112. package/app/apps/github/src/releases/release-list.tsx +8 -5
  113. package/app/apps/github/src/releases/release-view.tsx +1 -0
  114. package/app/apps/github/src/releases/releases.ts +33 -23
  115. package/app/apps/github/src/releases/tag-list.tsx +3 -1
  116. package/app/apps/github/src/router.tsx +5 -2
  117. package/app/apps/github/src/routes/$owner/$repo/_code/blob/$.tsx +7 -1
  118. package/app/apps/github/src/routes/$owner/$repo/_code/tree/$.tsx +6 -1
  119. package/app/apps/github/src/routes/$owner/$repo/_releases/releases/index.tsx +2 -1
  120. package/app/apps/github/src/routes/$owner/$repo/_releases/tags.tsx +1 -1
  121. package/app/apps/github/src/routes/$owner/$repo/branches.tsx +5 -1
  122. package/app/apps/github/src/routes/$owner/$repo/commit/$sha.tsx +1 -1
  123. package/app/apps/github/src/routes/$owner/$repo/commits/$.tsx +6 -1
  124. package/app/apps/github/src/routes/$owner/$repo/index.tsx +1 -1
  125. package/app/apps/github/src/routes/$owner/$repo/issues/$number.tsx +4 -2
  126. package/app/apps/github/src/routes/$owner/$repo/issues/index.tsx +2 -2
  127. package/app/apps/github/src/routes/$owner/$repo/issues/new.tsx +5 -2
  128. package/app/apps/github/src/routes/$owner/$repo/labels.tsx +2 -1
  129. package/app/apps/github/src/routes/$owner/$repo/milestones.tsx +36 -0
  130. package/app/apps/github/src/routes/$owner/$repo/pull/$number/route.tsx +4 -2
  131. package/app/apps/github/src/routes/$owner/$repo/pulls/index.tsx +2 -2
  132. package/app/apps/github/src/routes/$owner/$repo/queue.tsx +2 -1
  133. package/app/apps/github/src/routes/$owner/$repo/releases/edit/$.tsx +5 -2
  134. package/app/apps/github/src/routes/$owner/$repo/releases/new.tsx +2 -1
  135. package/app/apps/github/src/routes/$owner/$repo/releases/tag/$.tsx +4 -2
  136. package/app/apps/github/src/routes/$owner/$repo/route.tsx +9 -5
  137. package/app/apps/github/src/routes/$owner/$repo/settings/hooks/index.tsx +3 -1
  138. package/app/apps/github/src/routes/$owner/$repo/settings/index.tsx +3 -1
  139. package/app/apps/github/src/routes/-nav.tsx +10 -2
  140. package/app/apps/github/src/routes/-root-testing.ts +29 -6
  141. package/app/apps/github/src/routes/__root.tsx +9 -4
  142. package/app/apps/github/src/routes/index.tsx +3 -1
  143. package/app/apps/github/src/routes/orgs/$owner/route.tsx +4 -1
  144. package/app/apps/github/src/routes/orgs/$owner/settings.tsx +4 -1
  145. package/app/apps/github/src/seed/acme.ts +1 -1
  146. package/app/apps/github/src/seed/seed.ts +199 -110
  147. package/app/apps/github/src/server.ts +24 -15
  148. package/app/apps/github/src/settings/account-avatar.tsx +4 -1
  149. package/app/apps/github/src/settings/general-settings.tsx +3 -1
  150. package/app/apps/github/src/settings/general.ts +4 -4
  151. package/app/apps/github/src/settings/hook-form.tsx +3 -1
  152. package/app/apps/github/src/settings/hook-list.tsx +5 -2
  153. package/app/apps/github/src/settings/hooks.ts +7 -7
  154. package/app/apps/github/src/settings/org-settings.tsx +3 -1
  155. package/app/apps/github/src/settings/orgs.ts +21 -11
  156. package/app/apps/github/src/settings/settings-layout.tsx +3 -1
  157. package/app/apps/github/src/signin/approval.ts +4 -3
  158. package/app/apps/github/src/signin/auth.ts +9 -2
  159. package/app/apps/github/src/signin/device-code.ts +8 -3
  160. package/app/apps/github/src/signin/device-prompt.ts +28 -3
  161. package/app/apps/github/src/signin/revoke.ts +36 -0
  162. package/app/apps/github/tsconfig.json +4 -1
  163. package/app/apps/github/vite.config.ts +8 -0
  164. package/app/pnpm-workspace.yaml +9 -5
  165. package/app/tsconfig.base.json +1 -0
  166. package/dist/cli/child.mjs +1 -1
  167. package/dist/cli/credentials.mjs +4 -4
  168. package/dist/cli/documents.mjs +32 -22
  169. package/dist/cli/events.mjs +1 -1
  170. package/dist/cli/failure.mjs +20 -7
  171. package/dist/cli/folders.mjs +2 -2
  172. package/dist/cli/git-remote-ref0.mjs +47 -22
  173. package/dist/cli/git.mjs +1 -1
  174. package/dist/cli/helpers.mjs +2 -2
  175. package/dist/cli/hosts.mjs +3 -3
  176. package/dist/cli/output.mjs +2 -2
  177. package/dist/cli/prompt.mjs +1 -1
  178. package/dist/cli/queue.mjs +7 -7
  179. package/dist/cli/ref0-git.mjs +2 -2
  180. package/dist/cli/repos.mjs +35 -18
  181. package/dist/cli/resources.mjs +5 -5
  182. package/dist/cli/retry-after.mjs +8 -0
  183. package/dist/cli/setup.mjs +172 -66
  184. package/dist/cli/sign-in.mjs +65 -23
  185. package/dist/cli/sign-ins.mjs +4 -4
  186. package/dist/cli/sqlite.mjs +2 -2
  187. package/dist/cli/tokens.mjs +3 -3
  188. package/dist/cli/vendor.mjs +1 -1
  189. package/dist/init/app.mjs +18 -20
  190. package/dist/init/choices.mjs +1 -1
  191. package/dist/init/cloudflare.mjs +15 -19
  192. package/dist/init/create.mjs +3 -2
  193. package/dist/init/detect.mjs +4 -4
  194. package/dist/init/files.mjs +120 -13
  195. package/dist/init/frameworks.mjs +16 -0
  196. package/dist/init/git-module.mjs +22 -7
  197. package/dist/init/jsonc.mjs +9 -7
  198. package/dist/init/metadata.mjs +9 -3
  199. package/dist/init/mounts.mjs +13 -10
  200. package/dist/init/next.mjs +2 -2
  201. package/dist/init/node-app.mjs +3 -3
  202. package/dist/init/node.mjs +42 -45
  203. package/dist/init/nuxt.mjs +153 -27
  204. package/dist/init/stores.mjs +14 -9
  205. package/dist/init/sveltekit.mjs +4 -2
  206. package/dist/init/template.mjs +9 -6
  207. package/dist/init/templates.mjs +63 -47
  208. package/dist/init/vercel.mjs +37 -37
  209. package/dist/init/versions.mjs +3 -3
  210. package/package.json +6 -5
@@ -1,8 +1,11 @@
1
- import { useQuery } from '@tanstack/react-query';
1
+ import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
2
2
  import { PencilIcon, TagIcon } from 'lucide-react';
3
3
  import { useState } from 'react';
4
+ import { toast } from 'sonner';
4
5
 
6
+ import { useClients } from '../clients/clients.ts';
5
7
  import type { RepoPlace } from '../code/places.ts';
8
+ import { ConfirmAction } from '../components/confirm-action.tsx';
6
9
  import { Alert, AlertDescription } from '../components/ui/alert.tsx';
7
10
  import { Button } from '../components/ui/button.tsx';
8
11
  import {
@@ -14,7 +17,7 @@ import {
14
17
  } from '../components/ui/empty.tsx';
15
18
  import { Skeleton } from '../components/ui/skeleton.tsx';
16
19
  import { useAllowed } from '../hooks/allowed.ts';
17
- import { vocabularyOf, type Label } from './issues.ts';
20
+ import { deleteLabel, readIssuesAgain, vocabularyKey, vocabularyOf, type Label } from './issues.ts';
18
21
  import { LabelDialog } from './label-dialog.tsx';
19
22
  import { LabelBadge } from './parts.tsx';
20
23
  import { CreateButton } from '../components/create-button.tsx';
@@ -26,15 +29,28 @@ type Open = { readonly editing: Label | undefined } | undefined;
26
29
  /**
27
30
  * The repo's labels, by name, each with its description: someone the drop-in lets make one gets
28
31
  * New label, and someone it lets change one gets each one's Edit. Both open the label's Dialog.
32
+ * Someone it lets delete one gets each one's Delete, which asks first.
29
33
  */
30
34
  export function LabelsPage({ place }: { readonly place: RepoPlace }) {
31
- const vocabulary = useQuery(vocabularyOf(place));
35
+ const clients = useClients();
36
+ const vocabulary = useQuery(vocabularyOf(clients, place));
32
37
  const allowed = useAllowed(place);
33
38
  const [open, setOpen] = useState<Open>();
34
39
  const labels = [...(vocabulary.data?.labels ?? [])].sort((one, other) =>
35
40
  one.name.localeCompare(other.name),
36
41
  );
37
42
  const canEdit = allowed.has('label.update');
43
+ const canDelete = allowed.has('label.delete');
44
+ const client = useQueryClient();
45
+ const deleted = useMutation({
46
+ mutationFn: (name: string) => deleteLabel(clients, place, name),
47
+ onSuccess: async (_, name) => {
48
+ toast.success(`Deleted the label ${name}`);
49
+ await client.invalidateQueries({ queryKey: vocabularyKey(place) });
50
+ // The issues and pull requests that held it show it no more, so each is read again.
51
+ await readIssuesAgain(client, place);
52
+ },
53
+ });
38
54
 
39
55
  return (
40
56
  <div className="flex flex-col gap-3">
@@ -52,6 +68,11 @@ export function LabelsPage({ place }: { readonly place: RepoPlace }) {
52
68
  ) : undefined
53
69
  }
54
70
  />
71
+ {deleted.error !== null && (
72
+ <Alert variant="destructive">
73
+ <AlertDescription>{deleted.error.message}</AlertDescription>
74
+ </Alert>
75
+ )}
55
76
  {vocabulary.error !== null ? (
56
77
  <Alert variant="destructive">
57
78
  <AlertDescription>
@@ -98,6 +119,17 @@ export function LabelsPage({ place }: { readonly place: RepoPlace }) {
98
119
  Edit
99
120
  </Button>
100
121
  )}
122
+ {canDelete && (
123
+ <ConfirmAction
124
+ label="Delete"
125
+ title={`Delete the label ${label.name}?`}
126
+ description="It comes off every issue and pull request that has it. This can’t be undone."
127
+ confirm="Delete label"
128
+ className={canEdit ? '' : 'ms-auto'}
129
+ disabled={deleted.isPending}
130
+ onConfirm={() => deleted.mutate(label.name)}
131
+ />
132
+ )}
101
133
  </li>
102
134
  ))}
103
135
  </ul>
@@ -0,0 +1,197 @@
1
+ import { useMutation, useQueryClient } from '@tanstack/react-query';
2
+ import { type FormEvent, useState } from 'react';
3
+ import { toast } from 'sonner';
4
+
5
+ import { useClients } from '../clients/clients.ts';
6
+ import type { RepoPlace } from '../code/places.ts';
7
+ import { Alert, AlertDescription } from '../components/ui/alert.tsx';
8
+ import { Button } from '../components/ui/button.tsx';
9
+ import {
10
+ Dialog,
11
+ DialogContent,
12
+ DialogDescription,
13
+ DialogFooter,
14
+ DialogHeader,
15
+ DialogTitle,
16
+ } from '../components/ui/dialog.tsx';
17
+ import {
18
+ Field,
19
+ FieldDescription,
20
+ FieldError,
21
+ FieldGroup,
22
+ FieldLabel,
23
+ } from '../components/ui/field.tsx';
24
+ import { Input } from '../components/ui/input.tsx';
25
+ import { Textarea } from '../components/ui/textarea.tsx';
26
+ import {
27
+ createMilestone,
28
+ editMilestone,
29
+ readIssuesAgain,
30
+ vocabularyKey,
31
+ type MilestoneDetail,
32
+ } from './issues.ts';
33
+
34
+ /** The longest title and description the drop-in keeps for a milestone. */
35
+ const longest = { title: 256, description: 1024 } as const;
36
+
37
+ /**
38
+ * A milestone's Dialog, for a new one and for changing one, `editing`: its title, its due date and
39
+ * its description. `taken` is the repo's milestones' titles, which a new title can't be.
40
+ */
41
+ export function MilestoneDialog({
42
+ place,
43
+ editing,
44
+ taken,
45
+ open,
46
+ onOpenChange,
47
+ }: {
48
+ readonly place: RepoPlace;
49
+ readonly editing: MilestoneDetail | undefined;
50
+ readonly taken: readonly string[];
51
+ readonly open: boolean;
52
+ readonly onOpenChange: (open: boolean) => void;
53
+ }) {
54
+ return (
55
+ <Dialog open={open} onOpenChange={onOpenChange}>
56
+ <DialogContent className="sm:max-w-md">
57
+ <DialogHeader>
58
+ <DialogTitle>{editing === undefined ? 'New milestone' : 'Edit milestone'}</DialogTitle>
59
+ <DialogDescription>
60
+ Milestones gather this repository's issues and pull requests toward a date.
61
+ </DialogDescription>
62
+ </DialogHeader>
63
+ {/* The form mounts with the dialog, so each opening starts from what it's given. */}
64
+ <MilestoneForm
65
+ place={place}
66
+ editing={editing}
67
+ taken={taken}
68
+ onDone={() => onOpenChange(false)}
69
+ />
70
+ </DialogContent>
71
+ </Dialog>
72
+ );
73
+ }
74
+
75
+ /** The Dialog's form, which makes or changes the milestone. */
76
+ function MilestoneForm({
77
+ place,
78
+ editing,
79
+ taken,
80
+ onDone,
81
+ }: {
82
+ readonly place: RepoPlace;
83
+ readonly editing: MilestoneDetail | undefined;
84
+ readonly taken: readonly string[];
85
+ readonly onDone: () => void;
86
+ }) {
87
+ const clients = useClients();
88
+ const client = useQueryClient();
89
+ const [title, setTitle] = useState(editing?.title ?? '');
90
+ // The day the drop-in's due date falls on in UTC, as the date field writes it.
91
+ const [due, setDue] = useState(editing?.dueOn?.slice(0, 10) ?? '');
92
+ const [description, setDescription] = useState(editing?.description ?? '');
93
+ const [tried, setTried] = useState(false);
94
+
95
+ const trimmed = title.trim();
96
+ const clashes = taken.some((held) => held === trimmed && held !== editing?.title);
97
+ const titleProblem =
98
+ trimmed === ''
99
+ ? 'Give the milestone a title.'
100
+ : clashes
101
+ ? `There's a milestone titled ${trimmed} already.`
102
+ : undefined;
103
+ const fields = {
104
+ title: trimmed,
105
+ description: description.trim() === '' ? null : description.trim(),
106
+ due: due === '' ? null : due,
107
+ };
108
+
109
+ const save = useMutation({
110
+ mutationFn: () =>
111
+ editing === undefined
112
+ ? createMilestone(clients, place, fields)
113
+ : editMilestone(clients, place, editing.number, fields),
114
+ onSuccess: async (saved) => {
115
+ toast.success(
116
+ editing === undefined
117
+ ? `Created the milestone ${saved.title}`
118
+ : `Saved the milestone ${saved.title}`,
119
+ );
120
+ onDone();
121
+ await client.invalidateQueries({ queryKey: vocabularyKey(place) });
122
+
123
+ // A new title shows on every issue and pull request in the milestone, so each is read again.
124
+ if (editing !== undefined) await readIssuesAgain(client, place);
125
+ },
126
+ });
127
+
128
+ const submit = (event: FormEvent<HTMLFormElement>) => {
129
+ event.preventDefault();
130
+ setTried(true);
131
+
132
+ if (titleProblem !== undefined || save.isPending) return;
133
+
134
+ save.mutate();
135
+ };
136
+
137
+ return (
138
+ <form
139
+ noValidate
140
+ aria-label="Milestone"
141
+ onSubmit={submit}
142
+ className="flex min-w-0 flex-col gap-4"
143
+ >
144
+ <FieldGroup>
145
+ <Field data-invalid={tried && titleProblem !== undefined}>
146
+ <FieldLabel htmlFor="milestone-title" required>
147
+ Title
148
+ </FieldLabel>
149
+ <Input
150
+ id="milestone-title"
151
+ required
152
+ autoComplete="off"
153
+ maxLength={longest.title}
154
+ aria-invalid={tried && titleProblem !== undefined}
155
+ value={title}
156
+ onChange={(event) => setTitle(event.target.value)}
157
+ />
158
+ {tried && <FieldError>{titleProblem}</FieldError>}
159
+ </Field>
160
+ <Field>
161
+ <FieldLabel htmlFor="milestone-due">Due date</FieldLabel>
162
+ <Input
163
+ id="milestone-due"
164
+ type="date"
165
+ className="w-fit"
166
+ value={due}
167
+ onChange={(event) => setDue(event.target.value)}
168
+ />
169
+ <FieldDescription>Optional.</FieldDescription>
170
+ </Field>
171
+ <Field>
172
+ <FieldLabel htmlFor="milestone-description">Description</FieldLabel>
173
+ <Textarea
174
+ id="milestone-description"
175
+ maxLength={longest.description}
176
+ value={description}
177
+ onChange={(event) => setDescription(event.target.value)}
178
+ />
179
+ <FieldDescription>Optional.</FieldDescription>
180
+ </Field>
181
+ </FieldGroup>
182
+ {save.isError && (
183
+ <Alert variant="destructive">
184
+ <AlertDescription>{save.error.message}</AlertDescription>
185
+ </Alert>
186
+ )}
187
+ <DialogFooter>
188
+ <Button type="button" variant="outline" onClick={onDone}>
189
+ Cancel
190
+ </Button>
191
+ <Button type="submit" disabled={save.isPending}>
192
+ {editing === undefined ? 'Create milestone' : 'Save changes'}
193
+ </Button>
194
+ </DialogFooter>
195
+ </form>
196
+ );
197
+ }
@@ -0,0 +1,269 @@
1
+ import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
2
+ import { MilestoneIcon, PencilIcon } from 'lucide-react';
3
+ import { useState } from 'react';
4
+ import { toast } from 'sonner';
5
+
6
+ import { Go } from '../code/controls.tsx';
7
+ import { useClients } from '../clients/clients.ts';
8
+ import type { RepoPlace } from '../code/places.ts';
9
+ import { ConfirmAction } from '../components/confirm-action.tsx';
10
+ import { CreateButton } from '../components/create-button.tsx';
11
+ import { ListToolbar } from '../components/list-toolbar.tsx';
12
+ import { RelativeTime } from '../components/relative-time.tsx';
13
+ import { Alert, AlertDescription } from '../components/ui/alert.tsx';
14
+ import { Button } from '../components/ui/button.tsx';
15
+ import {
16
+ Empty,
17
+ EmptyDescription,
18
+ EmptyHeader,
19
+ EmptyMedia,
20
+ EmptyTitle,
21
+ } from '../components/ui/empty.tsx';
22
+ import { Skeleton } from '../components/ui/skeleton.tsx';
23
+ import { useAllowed } from '../hooks/allowed.ts';
24
+ import type { Tabbed } from './counts.ts';
25
+ import { issuesHref, StateTabs } from './issue-list.tsx';
26
+ import {
27
+ deleteMilestone,
28
+ editMilestone,
29
+ milestonesOf,
30
+ readIssuesAgain,
31
+ vocabularyKey,
32
+ type MilestoneDetail,
33
+ } from './issues.ts';
34
+ import { MilestoneDialog } from './milestone-dialog.tsx';
35
+ import { defaultQuery, filterOf, queryOf } from './search.ts';
36
+
37
+ /** A due date as GitHub words it, in UTC, the same on the server and in every browser. */
38
+ const dueDay = new Intl.DateTimeFormat('en', { dateStyle: 'long', timeZone: 'UTC' });
39
+
40
+ /** What a row's buttons do to its milestone. */
41
+ type Action = { readonly kind: 'close' | 'reopen' | 'delete'; readonly milestone: MilestoneDetail };
42
+
43
+ /** What the page's Dialog is open on: a new milestone, or one of the repo's being changed. */
44
+ type Open = { readonly editing: MilestoneDetail | undefined } | undefined;
45
+
46
+ /** The page's URL for the milestones in `state`. */
47
+ export const milestonesHref = (place: RepoPlace, state: Tabbed) =>
48
+ `/${place.owner}/${place.repo}/milestones${state === 'closed' ? '?state=closed' : ''}`;
49
+
50
+ /** How far along a milestone is: its closed issues and pull requests of all of them, in percent. */
51
+ const percentOf = ({ open, closed }: MilestoneDetail) =>
52
+ open + closed === 0 ? 0 : Math.floor((closed / (open + closed)) * 100);
53
+
54
+ /**
55
+ * The repo's milestones in `state`, open or closed, each with its due date, description and how far
56
+ * along its issues are, and its title linking to them. Someone the drop-in lets make one gets New
57
+ * milestone, someone it lets change one gets each one's Edit and Close or Reopen, and someone it
58
+ * lets delete one gets each one's Delete, which asks first.
59
+ */
60
+ export function MilestonesPage({
61
+ place,
62
+ state,
63
+ }: {
64
+ readonly place: RepoPlace;
65
+ readonly state: Tabbed;
66
+ }) {
67
+ const clients = useClients();
68
+ const milestones = useQuery(milestonesOf(clients, place));
69
+ const allowed = useAllowed(place);
70
+ const [open, setOpen] = useState<Open>();
71
+ const client = useQueryClient();
72
+ const all = milestones.data ?? [];
73
+ const shown = all.filter((milestone) => milestone.state === state);
74
+ const counts = {
75
+ open: all.filter((milestone) => milestone.state === 'open').length,
76
+ closed: all.filter((milestone) => milestone.state === 'closed').length,
77
+ };
78
+ const canEdit = allowed.has('milestone.update');
79
+ const canDelete = allowed.has('milestone.delete');
80
+
81
+ const acted = useMutation({
82
+ mutationFn: async ({ kind, milestone }: Action) => {
83
+ if (kind === 'delete') return deleteMilestone(clients, place, milestone.number);
84
+
85
+ const changed = { state: kind === 'close' ? 'closed' : 'open' } as const;
86
+ await editMilestone(clients, place, milestone.number, changed);
87
+ },
88
+ onSuccess: async (_, { kind, milestone }) => {
89
+ const done = { close: 'Closed', reopen: 'Reopened', delete: 'Deleted' }[kind];
90
+ toast.success(`${done} the milestone ${milestone.title}`);
91
+ await client.invalidateQueries({ queryKey: vocabularyKey(place) });
92
+ // Its issues and pull requests show it as it now is, or in no milestone.
93
+ await readIssuesAgain(client, place);
94
+ },
95
+ });
96
+
97
+ return (
98
+ <div className="flex flex-col gap-3">
99
+ <ListToolbar
100
+ heading={<h1 className="text-base font-semibold">Milestones</h1>}
101
+ buttons={
102
+ allowed.has('milestone.create') ? (
103
+ <CreateButton onClick={() => setOpen({ editing: undefined })}>
104
+ New milestone
105
+ </CreateButton>
106
+ ) : undefined
107
+ }
108
+ />
109
+ {acted.error !== null && (
110
+ <Alert variant="destructive">
111
+ <AlertDescription>{acted.error.message}</AlertDescription>
112
+ </Alert>
113
+ )}
114
+ {milestones.error !== null ? (
115
+ <Alert variant="destructive">
116
+ <AlertDescription>
117
+ {milestones.error.message}. Reload the page to try again.
118
+ </AlertDescription>
119
+ </Alert>
120
+ ) : milestones.data === undefined ? (
121
+ <Skeleton className="h-40" />
122
+ ) : (
123
+ <section aria-label="Milestone list" className="rounded-lg border">
124
+ <div className="border-b bg-muted/50 px-3 py-1.5">
125
+ <StateTabs
126
+ label="Milestone states"
127
+ current={state}
128
+ hrefOf={(each) => milestonesHref(place, each)}
129
+ counts={{ data: counts, isPending: false }}
130
+ />
131
+ </div>
132
+ {shown.length === 0 ? (
133
+ <Empty>
134
+ <EmptyHeader>
135
+ <EmptyMedia variant="icon">
136
+ <MilestoneIcon />
137
+ </EmptyMedia>
138
+ <EmptyTitle>No {state} milestones</EmptyTitle>
139
+ <EmptyDescription>
140
+ Milestones gather this repository's issues and pull requests toward a date.
141
+ </EmptyDescription>
142
+ </EmptyHeader>
143
+ </Empty>
144
+ ) : (
145
+ <ul aria-label="Milestones" className="divide-y">
146
+ {shown.map((milestone) => (
147
+ <li
148
+ key={milestone.number}
149
+ className="flex flex-col gap-3 px-4 py-3 sm:flex-row sm:gap-6"
150
+ >
151
+ <div className="flex min-w-0 flex-col gap-1 sm:basis-1/2">
152
+ <h2 className="text-sm font-semibold break-words">
153
+ <Go
154
+ href={issuesHref(
155
+ place,
156
+ queryOf({
157
+ ...filterOf(defaultQuery),
158
+ milestone: { kind: 'named', name: milestone.title },
159
+ }),
160
+ )}
161
+ className="hover:underline"
162
+ >
163
+ {milestone.title}
164
+ </Go>
165
+ </h2>
166
+ <span className="text-meta text-muted-foreground">
167
+ <Due milestone={milestone} />
168
+ </span>
169
+ {milestone.description !== null && (
170
+ <p className="text-sm whitespace-pre-wrap break-words text-muted-foreground">
171
+ {milestone.description}
172
+ </p>
173
+ )}
174
+ </div>
175
+ <div className="flex min-w-0 grow flex-col gap-2">
176
+ <div
177
+ role="progressbar"
178
+ aria-label={`${milestone.title} progress`}
179
+ aria-valuemin={0}
180
+ aria-valuemax={100}
181
+ aria-valuenow={percentOf(milestone)}
182
+ className="h-2 overflow-hidden rounded-full bg-muted"
183
+ >
184
+ <div
185
+ className="h-full bg-state-open"
186
+ style={{ width: `${percentOf(milestone)}%` }}
187
+ />
188
+ </div>
189
+ <span className="text-meta text-muted-foreground">
190
+ {percentOf(milestone)}% complete · {milestone.open} open · {milestone.closed}{' '}
191
+ closed
192
+ </span>
193
+ {(canEdit || canDelete) && (
194
+ <div className="flex flex-wrap gap-1">
195
+ {canEdit && (
196
+ <>
197
+ <Button
198
+ variant="ghost"
199
+ size="sm"
200
+ aria-label={`Edit ${milestone.title}`}
201
+ onClick={() => setOpen({ editing: milestone })}
202
+ >
203
+ <PencilIcon aria-hidden />
204
+ Edit
205
+ </Button>
206
+ <Button
207
+ variant="ghost"
208
+ size="sm"
209
+ aria-label={`${state === 'open' ? 'Close' : 'Reopen'} ${milestone.title}`}
210
+ disabled={acted.isPending}
211
+ onClick={() =>
212
+ acted.mutate({
213
+ kind: state === 'open' ? 'close' : 'reopen',
214
+ milestone,
215
+ })
216
+ }
217
+ >
218
+ {state === 'open' ? 'Close' : 'Reopen'}
219
+ </Button>
220
+ </>
221
+ )}
222
+ {canDelete && (
223
+ <ConfirmAction
224
+ label="Delete"
225
+ title={`Delete the milestone ${milestone.title}?`}
226
+ description="Its issues and pull requests stay, in no milestone. This can’t be undone."
227
+ confirm="Delete milestone"
228
+ disabled={acted.isPending}
229
+ onConfirm={() => acted.mutate({ kind: 'delete', milestone })}
230
+ />
231
+ )}
232
+ </div>
233
+ )}
234
+ </div>
235
+ </li>
236
+ ))}
237
+ </ul>
238
+ )}
239
+ </section>
240
+ )}
241
+ {open !== undefined && (
242
+ <MilestoneDialog
243
+ place={place}
244
+ editing={open.editing}
245
+ taken={all.map((milestone) => milestone.title)}
246
+ open
247
+ onOpenChange={(next) => {
248
+ if (!next) setOpen(undefined);
249
+ }}
250
+ />
251
+ )}
252
+ </div>
253
+ );
254
+ }
255
+
256
+ /** When a milestone is due, or when it was closed. */
257
+ function Due({ milestone }: { readonly milestone: MilestoneDetail }) {
258
+ if (milestone.state === 'closed' && milestone.closedAt !== null) {
259
+ return (
260
+ <>
261
+ Closed <RelativeTime at={milestone.closedAt} />
262
+ </>
263
+ );
264
+ }
265
+
266
+ return milestone.dueOn === null
267
+ ? 'No due date'
268
+ : `Due by ${dueDay.format(new Date(milestone.dueOn))}`;
269
+ }
@@ -2,6 +2,7 @@ import { useMutation, useQueryClient } from '@tanstack/react-query';
2
2
  import { useNavigate } from '@tanstack/react-router';
3
3
  import { useState } from 'react';
4
4
 
5
+ import { useClients } from '../clients/clients.ts';
5
6
  import type { RepoPlace } from '../code/places.ts';
6
7
  import { HotkeyHint, hotkeys } from '../components/hotkeys/hotkeys.tsx';
7
8
  import { Alert, AlertDescription } from '../components/ui/alert.tsx';
@@ -14,12 +15,13 @@ import { MarkdownEditor } from '../components/markdown/editor.tsx';
14
15
 
15
16
  /** A new issue's form: its title and text, previewed as it will show. */
16
17
  export function NewIssue({ place }: { readonly place: RepoPlace }) {
18
+ const clients = useClients();
17
19
  const client = useQueryClient();
18
20
  const navigate = useNavigate();
19
21
  const [title, setTitle] = useState('');
20
22
  const [body, setBody] = useState('');
21
23
  const created = useMutation({
22
- mutationFn: () => createIssue(place, { title: title.trim(), body }),
24
+ mutationFn: () => createIssue(clients, place, { title: title.trim(), body }),
23
25
  onSuccess: async (number) => {
24
26
  await client.invalidateQueries({ queryKey: ['issues', place.owner, place.repo] });
25
27
  await navigate({ href: issueHref(place, number) });
@@ -1,6 +1,7 @@
1
1
  import { useQuery } from '@tanstack/react-query';
2
2
  import { useState, type ReactNode } from 'react';
3
3
 
4
+ import { useClients } from '../clients/clients.ts';
4
5
  import type { RepoPlace } from '../code/places.ts';
5
6
  import { OwnerCard } from '../components/owner-card.tsx';
6
7
  import { Separator } from '../components/ui/separator.tsx';
@@ -65,7 +66,8 @@ export function Sidebar({
65
66
  readonly label?: string;
66
67
  readonly children?: ReactNode;
67
68
  }) {
68
- const vocabulary = useQuery(vocabularyOf(place)).data;
69
+ const clients = useClients();
70
+ const vocabulary = useQuery(vocabularyOf(clients, place)).data;
69
71
  const issue = useShown(place, held);
70
72
  const { commit, changing } = useChange(place, issue.number, holding);
71
73
  const editable = allowed.has('issue.update') && vocabulary !== undefined;
@@ -87,14 +89,14 @@ export function Sidebar({
87
89
  const picked = labels.take();
88
90
  if (picked === undefined || sameSet(picked, heldLabels)) return;
89
91
 
90
- commit(labelsChange(changing, picked.map(labelOf)));
92
+ commit(labelsChange(clients, changing, picked.map(labelOf)));
91
93
  };
92
94
 
93
95
  const closeAssignees = () => {
94
96
  const picked = assignees.take();
95
97
  if (picked === undefined || sameSet(picked, issue.assignees)) return;
96
98
 
97
- commit(assigneesChange(changing, picked));
99
+ commit(assigneesChange(clients, changing, picked));
98
100
  };
99
101
 
100
102
  // Whoever is assigned can be unassigned, though the repo no longer lists them as assignable.
@@ -105,7 +107,7 @@ export function Sidebar({
105
107
  const next = openMilestones.find((milestone) => String(milestone.number) === value) ?? null;
106
108
  if ((next?.number ?? null) === (issue.milestone?.number ?? null)) return;
107
109
 
108
- commit(milestoneChange(changing, next));
110
+ commit(milestoneChange(clients, changing, next));
109
111
  };
110
112
 
111
113
  return (
@@ -183,7 +185,7 @@ export function Sidebar({
183
185
  onOpenChange={(open) => {
184
186
  if (!open) setCreating(undefined);
185
187
  }}
186
- onSaved={(made) => commit(labelsChange(changing, [...issue.labels, made]))}
188
+ onSaved={(made) => commit(labelsChange(clients, changing, [...issue.labels, made]))}
187
189
  />
188
190
  )}
189
191
  {shownLabels.length === 0 ? (
@@ -217,7 +219,7 @@ export function Sidebar({
217
219
  allowed.has('milestone.create')
218
220
  ? {
219
221
  what: 'milestone',
220
- make: (name) => commit(milestoneChange(changing, null, name)),
222
+ make: (name) => commit(milestoneChange(clients, changing, null, name)),
221
223
  }
222
224
  : undefined
223
225
  }