@gogitcms/design-system 0.16.0-next.1 → 0.16.0-next.11

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 (31) hide show
  1. package/package.json +1 -1
  2. package/src/__tests__/ApplyChangesModal.test.tsx +48 -0
  3. package/src/__tests__/BranchDeletedModal.test.tsx +42 -0
  4. package/src/__tests__/ContentBrowser.fieldfocus.test.tsx +109 -0
  5. package/src/__tests__/ContentBrowser.forms.test.tsx +47 -1
  6. package/src/__tests__/ContentBrowser.history.test.tsx +385 -0
  7. package/src/__tests__/ContentBrowser.historycollab.test.tsx +433 -0
  8. package/src/__tests__/ContentBrowser.references.test.tsx +179 -0
  9. package/src/__tests__/ContentBrowser.slotmedia.test.tsx +150 -0
  10. package/src/__tests__/MediaField.test.tsx +18 -0
  11. package/src/__tests__/ProtectedBranchModal.test.tsx +68 -0
  12. package/src/components/ApplyChangesModal.tsx +70 -21
  13. package/src/components/BranchDeletedModal.tsx +111 -0
  14. package/src/components/ChangeDetail.tsx +94 -11
  15. package/src/components/CollabField.tsx +71 -0
  16. package/src/components/ContentBrowser.tsx +494 -77
  17. package/src/components/DocumentDetails.tsx +0 -0
  18. package/src/components/DocumentHistory.tsx +408 -0
  19. package/src/components/MediaField.tsx +62 -0
  20. package/src/components/MediaPreview.tsx +14 -1
  21. package/src/components/MediaPreview.web.tsx +18 -3
  22. package/src/components/Notifications.tsx +146 -28
  23. package/src/components/ProtectedBranchModal.tsx +136 -0
  24. package/src/components/ReferenceField.tsx +0 -0
  25. package/src/components/primitives.tsx +46 -1
  26. package/src/fieldComponents.ts +2 -2
  27. package/src/history.ts +82 -0
  28. package/src/icons.ts +1 -0
  29. package/src/index.ts +28 -3
  30. package/src/media.ts +15 -0
  31. package/src/references.ts +97 -0
@@ -0,0 +1,150 @@
1
+ import React from "react";
2
+ import { render, screen, fireEvent, act } from "@testing-library/react";
3
+ import { ThemeProvider } from "../ThemeProvider";
4
+ import {
5
+ ContentBrowser,
6
+ type CmsEntry,
7
+ type CmsNavSection,
8
+ type EntryField,
9
+ type FieldSlotArgs,
10
+ } from "../components/ContentBrowser";
11
+ import type { MediaApi, MediaAsset, MediaResolution } from "../media";
12
+
13
+ // Force the desktop layout (jsdom reports width 0 → mobile otherwise).
14
+ jest.mock("../ThemeProvider", () => {
15
+ const actual = jest.requireActual("../ThemeProvider");
16
+ return { ...actual, useResponsive: () => ({ width: 1300, height: 900, isDesktop: true, isMobile: false }) };
17
+ });
18
+
19
+ const hero: MediaAsset = {
20
+ id: "m1",
21
+ set: "uploads",
22
+ repoPath: "public/uploads/hero.png",
23
+ publicPath: "/uploads/hero.png",
24
+ cdnPath: "https://cdn.example.com/uploads/hero.png",
25
+ mimeType: "image/png",
26
+ extension: "png",
27
+ kind: "image",
28
+ size: 2048,
29
+ width: 800,
30
+ height: 600,
31
+ pending: false,
32
+ url: "https://store.example.com/signed/hero.png",
33
+ };
34
+
35
+ function makeApi(over: Partial<MediaApi> = {}): MediaApi {
36
+ return {
37
+ sets: [{ name: "uploads", path: "public/uploads/**/*", mimeTypes: [], count: 1 }],
38
+ resolve: jest.fn(async (paths: string[]): Promise<MediaResolution[]> =>
39
+ paths.map((p) => ({ input: p, media: hero, aliasKind: "public", ambiguous: false, candidates: [] })),
40
+ ),
41
+ byId: jest.fn(async () => hero),
42
+ list: jest.fn(async () => [hero]),
43
+ ...over,
44
+ };
45
+ }
46
+
47
+ const sections: CmsNavSection[] = [
48
+ { title: "Content", items: [{ key: "posts", label: "Posts", icon: "newspaper" }] },
49
+ ];
50
+
51
+ const bodyField: EntryField = {
52
+ name: "body",
53
+ label: "Body",
54
+ type: "string",
55
+ component: "body",
56
+ source: "body",
57
+ format: "markdown",
58
+ value: "",
59
+ };
60
+
61
+ function renderWith(entry: CmsEntry, api: MediaApi | undefined, renderField: (a: FieldSlotArgs) => React.ReactNode) {
62
+ render(
63
+ <ThemeProvider>
64
+ <ContentBrowser
65
+ workspace={{ name: "acme/site", initials: "AC", branch: "main", changed: 0 }}
66
+ sections={sections}
67
+ activeNavKey="posts"
68
+ onSelectNav={() => {}}
69
+ entries={[entry]}
70
+ userInitials="ED"
71
+ media={api}
72
+ renderField={renderField}
73
+ />
74
+ </ThemeProvider>,
75
+ );
76
+ }
77
+
78
+ // A slot control that exposes what it received: a button to open the picker
79
+ // and a place to show what the pick settled with.
80
+ function makeSlot() {
81
+ const seen: { media?: FieldSlotArgs["media"] } = {};
82
+ const renderField = (args: FieldSlotArgs) => {
83
+ if (args.field.component !== "body") return undefined;
84
+ seen.media = args.media;
85
+ return <button data-testid="slot-control">custom body</button>;
86
+ };
87
+ return { seen, renderField };
88
+ }
89
+
90
+ test("a slot-rendered field receives media access that opens the picker and resolves paths", async () => {
91
+ const api = makeApi();
92
+ const { seen, renderField } = makeSlot();
93
+ const entry: CmsEntry = { id: "a", path: "content/posts/a.md", title: "Alpha", body: "", fields: [bodyField] };
94
+ renderWith(entry, api, renderField);
95
+
96
+ await screen.findByTestId("slot-control");
97
+ expect(seen.media).toBeDefined();
98
+
99
+ // Resolution is bound to the open document, like a media field's.
100
+ const resolved = await seen.media!.resolve(["/uploads/hero.png"]);
101
+ expect(resolved[0].media).toEqual(hero);
102
+ expect(api.resolve).toHaveBeenCalledWith(["/uploads/hero.png"], "content/posts/a.md");
103
+
104
+ // pick() opens the picker; choosing a row settles it with the asset and the
105
+ // path in the field's store_as form (public by default).
106
+ let pending: Promise<{ asset: MediaAsset; path: string } | null>;
107
+ act(() => {
108
+ pending = seen.media!.pick({ kinds: ["image", "svg"] });
109
+ });
110
+ const row = await screen.findByTestId(`media-row-${hero.id}`);
111
+ expect(api.list).toHaveBeenCalledWith(expect.objectContaining({ set: "uploads", kinds: ["image", "svg"] }));
112
+ fireEvent.click(row);
113
+ await expect(pending!).resolves.toEqual({ asset: hero, path: "/uploads/hero.png" });
114
+ });
115
+
116
+ test("dismissing the picker settles pick() with null", async () => {
117
+ const api = makeApi();
118
+ const { seen, renderField } = makeSlot();
119
+ const entry: CmsEntry = { id: "a", path: "content/posts/a.md", title: "Alpha", body: "", fields: [bodyField] };
120
+ renderWith(entry, api, renderField);
121
+ await screen.findByTestId("slot-control");
122
+
123
+ let pending: Promise<unknown>;
124
+ act(() => {
125
+ pending = seen.media!.pick();
126
+ });
127
+ await screen.findByTestId(`media-row-${hero.id}`);
128
+ fireEvent.click(screen.getByLabelText("Close"));
129
+ await expect(pending!).resolves.toBeNull();
130
+ });
131
+
132
+ test("the schema-less body gets media access bound to its document", async () => {
133
+ const api = makeApi();
134
+ const { seen, renderField } = makeSlot();
135
+ const entry: CmsEntry = { id: "a", path: "content/posts/a.md", title: "Alpha", body: "hello" };
136
+ renderWith(entry, api, renderField);
137
+ await screen.findByTestId("slot-control");
138
+
139
+ expect(seen.media).toBeDefined();
140
+ await seen.media!.resolve(["./hero.png"]);
141
+ expect(api.resolve).toHaveBeenCalledWith(["./hero.png"], "content/posts/a.md");
142
+ });
143
+
144
+ test("without a media api the slot receives no media handle", async () => {
145
+ const { seen, renderField } = makeSlot();
146
+ const entry: CmsEntry = { id: "a", path: "content/posts/a.md", title: "Alpha", body: "", fields: [bodyField] };
147
+ renderWith(entry, undefined, renderField);
148
+ await screen.findByTestId("slot-control");
149
+ expect(seen.media).toBeUndefined();
150
+ });
@@ -183,3 +183,21 @@ describe("pathForStoreAs", () => {
183
183
  expect(pathForStoreAs(manual, "public")).toBe("files/manual.pdf");
184
184
  });
185
185
  });
186
+
187
+ // The gap this closes: the picker row asked the preview for its compact form,
188
+ // and compact rendered the file chip for every kind — so an image showed as a
189
+ // filename squeezed into a 48px square instead of a thumbnail.
190
+ test("the picker shows a thumbnail for images and an icon for other kinds", async () => {
191
+ const api = makeApi();
192
+ renderField(<MediaField shape="string" value="" onChange={jest.fn()} set="uploads" />, api);
193
+
194
+ fireEvent.click(screen.getByTestId("media-choose"));
195
+ await screen.findByTestId(`media-row-${hero.id}`);
196
+
197
+ const thumb = screen.getByTestId(`media-thumb-${hero.id}`);
198
+ expect(thumb.tagName).toBe("IMG");
199
+ expect(thumb).toHaveAttribute("src", hero.url);
200
+ // The PDF row has no thumbnail: it gets the kind icon instead.
201
+ expect(screen.queryByTestId(`media-thumb-${manual.id}`)).not.toBeInTheDocument();
202
+ expect(screen.getByTestId(`media-row-${manual.id}`)).toBeInTheDocument();
203
+ });
@@ -0,0 +1,68 @@
1
+ import React from "react";
2
+ import { render, screen, fireEvent } from "@testing-library/react";
3
+ import { ThemeProvider } from "../ThemeProvider";
4
+ import { ProtectedBranchModal } from "../components/ProtectedBranchModal";
5
+
6
+ const wrap = (ui: React.ReactElement) => <ThemeProvider>{ui}</ThemeProvider>;
7
+
8
+ const base = { branch: "main", onCreate: () => {}, onCancel: () => {} };
9
+
10
+ test("it names the branch, the document, and offers the one remedy", () => {
11
+ render(wrap(<ProtectedBranchModal {...base} documentLabel="Hello world" />));
12
+
13
+ const modal = screen.getByTestId("protected-branch-modal");
14
+ expect(modal).toHaveTextContent("This branch is protected");
15
+ expect(modal).toHaveTextContent("main");
16
+ expect(modal).toHaveTextContent("Hello world");
17
+ expect(modal).toHaveTextContent("Branched from main");
18
+ expect(screen.getByTestId("protected-branch-submit")).toHaveTextContent("Create branch and save");
19
+ });
20
+
21
+ test("the suggested name prefills the field and submits", () => {
22
+ const onCreate = jest.fn();
23
+ render(wrap(<ProtectedBranchModal {...base} suggestedName="edit/hello" onCreate={onCreate} />));
24
+
25
+ expect(screen.getByTestId("protected-branch-name")).toHaveValue("edit/hello");
26
+ fireEvent.click(screen.getByTestId("protected-branch-submit"));
27
+ expect(onCreate).toHaveBeenCalledWith("edit/hello");
28
+ });
29
+
30
+ // The author's own name wins: a suggestion arriving late (the host resolves the
31
+ // document a render after the modal opens) must not overwrite what they typed.
32
+ test("a late suggestion does not overwrite a typed name", () => {
33
+ const { rerender } = render(wrap(<ProtectedBranchModal {...base} />));
34
+ fireEvent.change(screen.getByTestId("protected-branch-name"), { target: { value: "mine" } });
35
+ rerender(wrap(<ProtectedBranchModal {...base} suggestedName="edit/hello" />));
36
+ expect(screen.getByTestId("protected-branch-name")).toHaveValue("mine");
37
+ });
38
+
39
+ test("an empty name cannot be submitted", () => {
40
+ const onCreate = jest.fn();
41
+ render(wrap(<ProtectedBranchModal {...base} onCreate={onCreate} />));
42
+ fireEvent.click(screen.getByTestId("protected-branch-submit"));
43
+ expect(onCreate).not.toHaveBeenCalled();
44
+ });
45
+
46
+ // While the branch is being created there is no way out but forward: cancelling
47
+ // mid-flight would abandon a save whose branch may already exist.
48
+ test("busy disables both actions and hides the close control", () => {
49
+ const onCreate = jest.fn();
50
+ render(wrap(<ProtectedBranchModal {...base} suggestedName="edit/hello" busy onCreate={onCreate} />));
51
+
52
+ expect(screen.getByTestId("protected-branch-submit")).toHaveTextContent("Creating…");
53
+ expect(screen.queryByTestId("protected-branch-close")).not.toBeInTheDocument();
54
+ fireEvent.click(screen.getByTestId("protected-branch-submit"));
55
+ expect(onCreate).not.toHaveBeenCalled();
56
+ });
57
+
58
+ test("the server's message is shown so a rejected name can be corrected", () => {
59
+ render(wrap(<ProtectedBranchModal {...base} error={`branch "edit/hello" already exists`} />));
60
+ expect(screen.getByTestId("protected-branch-error")).toHaveTextContent("already exists");
61
+ });
62
+
63
+ test("cancel dismisses", () => {
64
+ const onCancel = jest.fn();
65
+ render(wrap(<ProtectedBranchModal {...base} onCancel={onCancel} />));
66
+ fireEvent.click(screen.getByTestId("protected-branch-cancel"));
67
+ expect(onCancel).toHaveBeenCalledTimes(1);
68
+ });
@@ -35,6 +35,15 @@ export type ApplyChangesModalProps = {
35
35
  progress?: MergeProgress;
36
36
  /** A short summary of what will be merged, shown on the confirmation step. */
37
37
  summary?: string;
38
+ /**
39
+ * Why this apply cannot push to the target directly and opens a change
40
+ * request instead — the target is protected, or the caller cannot publish
41
+ * every project on the branch. When set, the confirmation step describes the
42
+ * review that will happen rather than a merge commit that will not, and the
43
+ * needs_review panel gives this reason when there are no code conflicts to
44
+ * list. Absent for an ordinary direct merge.
45
+ */
46
+ reviewReason?: string;
38
47
  /** Number of unresolved conflicts, shown on the conflicted state. */
39
48
  conflictCount?: number;
40
49
  /**
@@ -99,7 +108,7 @@ function StepRow({ label, state }: { label: string; state: "done" | "active" | "
99
108
  * (spinner → green check), then shows a success panel with the commit + stats,
100
109
  * or an error. Read-only: it reflects a run the host drives via a subscription.
101
110
  */
102
- export function ApplyChangesModal({ sourceBranch, targetBranch, progress, summary, conflictCount, changeRequestOpen, changeRequestUrl, creatingChangeRequest, onConfirm, onReviewConflicts, onCreateChangeRequest, onViewChangeRequest, onClose, onDone }: ApplyChangesModalProps) {
111
+ export function ApplyChangesModal({ sourceBranch, targetBranch, progress, summary, reviewReason, conflictCount, changeRequestOpen, changeRequestUrl, creatingChangeRequest, onConfirm, onReviewConflicts, onCreateChangeRequest, onViewChangeRequest, onClose, onDone }: ApplyChangesModalProps) {
103
112
  const t = useTheme();
104
113
  const done = onDone ?? onClose;
105
114
  const [explanation, setExplanation] = useState("");
@@ -121,6 +130,13 @@ export function ApplyChangesModal({ sourceBranch, targetBranch, progress, summar
121
130
  const status = progress?.status;
122
131
  const conflicted = status === "conflicted";
123
132
  const needsReview = status === "needs_review";
133
+ // A needs_review run either lists code files a developer must resolve, or
134
+ // lists nothing because the merge was clean and simply may not be pushed by
135
+ // this run (a protected target, or partial project access). The two need
136
+ // different words: the second is not a conflict and naming it one would send
137
+ // the editor looking for files that are not there.
138
+ const escalationFiles = progress?.escalationFiles ?? [];
139
+ const codeConflicts = escalationFiles.length > 0;
124
140
  const terminal = status === "succeeded" || status === "failed" || conflicted || needsReview;
125
141
  const current = progress ? stepOrder[progress.step] : 0;
126
142
 
@@ -201,30 +217,63 @@ export function ApplyChangesModal({ sourceBranch, targetBranch, progress, summar
201
217
  // Confirmation step: spell out the irreversible, outward-facing effects
202
218
  // before anything is pushed to the remote.
203
219
  <View testID="apply-confirm" style={{ gap: t.space(3) }}>
204
- <Text variant="body" color="secondary">
205
- {`This merges ${sourceBranch} into ${targetBranch}, commits the result, and pushes a merge commit to origin/${targetBranch}.`}
206
- </Text>
207
- <Text variant="body" color="secondary">
208
- {`${sourceBranch} is then deleted. This can’t be undone.`}
209
- </Text>
220
+ {reviewReason ? (
221
+ // The run will stop before the push, so promising a merge commit
222
+ // on origin here would be describing something that will not
223
+ // happen. Say what will: a review, and nothing on the target
224
+ // until it is approved.
225
+ <>
226
+ <Text variant="body" color="secondary" testID="apply-confirm-review">
227
+ {`This merges ${sourceBranch} into ${targetBranch} in the CMS and opens a pull request for review. Nothing is pushed to origin/${targetBranch} until it is approved.`}
228
+ </Text>
229
+ <Text variant="body" color="secondary">{reviewReason}</Text>
230
+ </>
231
+ ) : (
232
+ <>
233
+ <Text variant="body" color="secondary">
234
+ {`This merges ${sourceBranch} into ${targetBranch}, commits the result, and pushes a merge commit to origin/${targetBranch}.`}
235
+ </Text>
236
+ <Text variant="body" color="secondary">
237
+ {`${sourceBranch} is then deleted. This can’t be undone.`}
238
+ </Text>
239
+ </>
240
+ )}
210
241
  {summary ? <Text variant="monoSm" color="tertiary">{summary}</Text> : null}
211
242
  </View>
212
243
  ) : needsReview ? (
213
- // Content merged, but code/config files conflict. A content editor can't
214
- // resolve these — collect an explanation and escalate to a developer.
244
+ // Content merged, but the run may not push it. Either code/config
245
+ // files conflict — a content editor can't resolve these — or the
246
+ // target can't take a direct push from this run. Both collect an
247
+ // explanation and escalate through a pull request.
215
248
  <View testID="merge-needs-review" style={{ gap: t.space(3) }}>
216
- <View style={{ flexDirection: "row", alignItems: "center", gap: t.space(2) }}>
217
- <Icon name="gitPullRequest" size={16} color={t.color.diffDelFg} />
218
- <Text variant="body" weight="medium">Code conflicts need a developer</Text>
219
- </View>
220
- <Text variant="body" color="secondary">
221
- {`The content merged cleanly, but these files changed on both ${sourceBranch} and ${targetBranch} and need a developer to resolve:`}
222
- </Text>
223
- <View style={{ gap: 2, padding: t.space(2), borderRadius: t.radius.md, backgroundColor: t.color.diffDelBg }}>
224
- {(progress?.escalationFiles ?? []).map((f) => (
225
- <Text key={f} variant="monoSm" color={t.color.diffDelFg} testID={`escalation-file-${f}`}>{f}</Text>
226
- ))}
227
- </View>
249
+ {codeConflicts ? (
250
+ <>
251
+ <View style={{ flexDirection: "row", alignItems: "center", gap: t.space(2) }}>
252
+ <Icon name="gitPullRequest" size={16} color={t.color.diffDelFg} />
253
+ <Text variant="body" weight="medium">Code conflicts need a developer</Text>
254
+ </View>
255
+ <Text variant="body" color="secondary">
256
+ {`The content merged cleanly, but these files changed on both ${sourceBranch} and ${targetBranch} and need a developer to resolve:`}
257
+ </Text>
258
+ <View style={{ gap: 2, padding: t.space(2), borderRadius: t.radius.md, backgroundColor: t.color.diffDelBg }}>
259
+ {escalationFiles.map((f) => (
260
+ <Text key={f} variant="monoSm" color={t.color.diffDelFg} testID={`escalation-file-${f}`}>{f}</Text>
261
+ ))}
262
+ </View>
263
+ </>
264
+ ) : (
265
+ <>
266
+ <View style={{ flexDirection: "row", alignItems: "center", gap: t.space(2) }}>
267
+ <Icon name="gitPullRequest" size={16} color={t.color.textSecondary} />
268
+ <Text variant="body" weight="medium">This merge needs a review</Text>
269
+ </View>
270
+ <Text variant="body" color="secondary" testID="merge-needs-review-reason">
271
+ {`The content merged cleanly and nothing was pushed to ${targetBranch}. ` +
272
+ (reviewReason ?? `Someone with the authority to publish it has to approve it.`) +
273
+ ` Opening a change request creates a pull request for that review.`}
274
+ </Text>
275
+ </>
276
+ )}
228
277
  <Input
229
278
  value={explanation}
230
279
  onChangeText={setExplanation}
@@ -0,0 +1,111 @@
1
+ import React from "react";
2
+ import { View, ScrollView } from "react-native";
3
+ import { useTheme } from "../ThemeProvider";
4
+ import { Text } from "./Text";
5
+ import { Icon } from "./Icon";
6
+ import { Button } from "./Button";
7
+ import type { BranchRef } from "./BranchMenu";
8
+
9
+ export type BranchDeletedModalProps = {
10
+ /**
11
+ * The branch that no longer exists. Omitted when only its id is known — a
12
+ * link into a branch that was deleted before the page loaded.
13
+ */
14
+ branch?: string;
15
+ /** "owner/name", when the host knows it. */
16
+ repository?: string;
17
+ /** The branches still connected, to switch to. The deleted one is not among them. */
18
+ branches: BranchRef[];
19
+ /** Open the editor on `branch` instead. */
20
+ onSwitch: (branch: BranchRef) => void;
21
+ /**
22
+ * Leave this repository for the picker. Offered as the way out when there is
23
+ * no other branch to switch to; omitted → the list is the only exit.
24
+ */
25
+ onChooseRepository?: () => void;
26
+ testID?: string;
27
+ };
28
+
29
+ /**
30
+ * Shown when the branch the editor is on stops existing — deleted on the
31
+ * provider, or disconnected from the CMS — while someone is looking at it.
32
+ *
33
+ * It is a modal rather than a redirect because the screen behind it may hold
34
+ * work in progress. Nothing on it can be saved to this branch any more, but
35
+ * bouncing the user to another branch without a word would make that content
36
+ * vanish mid-thought; the modal says what happened and leaves the page visible
37
+ * while they decide where to go. It cannot be dismissed into the dead branch,
38
+ * because there is nothing there to go back to: every exit is another branch.
39
+ */
40
+ export function BranchDeletedModal({
41
+ branch, repository, branches, onSwitch, onChooseRepository, testID,
42
+ }: BranchDeletedModalProps) {
43
+ const t = useTheme();
44
+ const title = branch ? `${branch} was deleted` : "This branch no longer exists";
45
+ const where = repository ? ` in ${repository}` : "";
46
+ const detail = branch
47
+ ? `The ${branch} branch${where} was deleted on the remote or disconnected from the CMS, and its content was removed with it. Nothing on this screen can be saved to it any more.`
48
+ : `The branch this link points to${where} was deleted on the remote or disconnected from the CMS, so there is nothing here to edit.`;
49
+ const hasOthers = branches.length > 0;
50
+
51
+ return (
52
+ <View
53
+ testID={testID ?? "branch-deleted-modal"}
54
+ style={{
55
+ position: "absolute", top: 0, left: 0, right: 0, bottom: 0, zIndex: 50,
56
+ alignItems: "center", justifyContent: "center", padding: t.space(4),
57
+ backgroundColor: "rgba(0,0,0,0.45)",
58
+ }}
59
+ >
60
+ <View
61
+ style={{
62
+ width: 460, maxWidth: "100%", maxHeight: "100%", gap: t.space(4), padding: t.space(5),
63
+ borderRadius: t.radius.lg, borderWidth: 1, borderColor: t.color.borderDefault,
64
+ backgroundColor: t.color.surfaceRaised,
65
+ }}
66
+ >
67
+ <View style={{ flexDirection: "row", alignItems: "center", gap: t.space(2) }}>
68
+ <Icon name="alert" size={16} color={t.color.diffDelFg} />
69
+ <Text variant="h3" weight="semibold" testID="branch-deleted-title">{title}</Text>
70
+ </View>
71
+
72
+ <Text variant="body" color="secondary">{detail}</Text>
73
+
74
+ {hasOthers ? (
75
+ <>
76
+ <Text variant="sm" weight="semibold">Switch to another branch to keep working</Text>
77
+ <ScrollView style={{ maxHeight: 280 }} contentContainerStyle={{ gap: t.space(2) }}>
78
+ {branches.map((b) => (
79
+ <Button
80
+ key={b.id}
81
+ title={b.name}
82
+ fullWidth
83
+ onPress={() => onSwitch(b)}
84
+ testID={`branch-deleted-switch-${b.id}`}
85
+ />
86
+ ))}
87
+ </ScrollView>
88
+ </>
89
+ ) : (
90
+ <Text variant="sm" color="secondary" testID="branch-deleted-none">
91
+ {repository
92
+ ? `No other branch of ${repository} is connected to the CMS.`
93
+ : "No other branch of this repository is connected to the CMS."}
94
+ </Text>
95
+ )}
96
+
97
+ {onChooseRepository ? (
98
+ <View style={{ flexDirection: "row", justifyContent: "flex-end" }}>
99
+ <Button
100
+ title="Choose a repository"
101
+ variant={hasOthers ? "ghost" : "primary"}
102
+ size="md"
103
+ onPress={onChooseRepository}
104
+ testID="branch-deleted-choose-repository"
105
+ />
106
+ </View>
107
+ ) : null}
108
+ </View>
109
+ </View>
110
+ );
111
+ }
@@ -5,7 +5,7 @@ import { Text } from "./Text";
5
5
  import { Icon } from "./Icon";
6
6
  import { Input } from "./Input";
7
7
  import { Button } from "./Button";
8
- import { Badge, DiffStat } from "./primitives";
8
+ import { Badge, CheckBox, DiffStat } from "./primitives";
9
9
 
10
10
  /** How one field differs between the branch and its base. */
11
11
  export type FieldChangeKind = "added" | "removed" | "changed" | "unchanged";
@@ -38,7 +38,15 @@ export type DocumentChange = {
38
38
  path: string;
39
39
  /** The base branch's path, for a rename. */
40
40
  previousPath?: string;
41
- status: "A" | "M" | "D" | "R";
41
+ /**
42
+ * A/M/D/R are git's letters, so a branch comparison renders them untranslated.
43
+ * "U" (unchanged) has no place in a diff of two branches — an unchanged
44
+ * document is not a change — but it is a real answer for a document version:
45
+ * the newest commit in a document's history is usually still what the document
46
+ * is, and saying "Unchanged" is more useful than an empty diff with no
47
+ * explanation.
48
+ */
49
+ status: "A" | "M" | "D" | "R" | "U";
42
50
  label: string;
43
51
  /** Ordered to match the content model's schema, so it reads like the editor. */
44
52
  fields: FieldChange[];
@@ -79,13 +87,35 @@ export type ChangeDetailProps = {
79
87
  */
80
88
  conflicts?: FieldConflict[];
81
89
  onResolveConflict?: (conflict: FieldConflict, choice: ConflictChoice, override?: unknown) => void;
90
+
91
+ /**
92
+ * Per-field selection, for a caller that does something with a subset of the
93
+ * diff — restoring fields from a past version, in the history pane.
94
+ *
95
+ * Only CHANGED fields get a box: an unchanged field's two sides are the same
96
+ * value, so selecting it could only ever be a no-op dressed up as a choice.
97
+ * The body is selectable under the name BODY_FIELD.
98
+ *
99
+ * Omitting onToggleField leaves the diff exactly as it was — a read-only
100
+ * comparison, which is what the changes surface wants.
101
+ */
102
+ selectedFields?: readonly string[];
103
+ onToggleField?: (name: string) => void;
82
104
  };
83
105
 
106
+ /**
107
+ * The name the body answers to in `selectedFields` — the document body is a
108
+ * selectable "field" here but has no entry in `fields`, and a real frontmatter
109
+ * key could otherwise collide with whatever plain string we picked.
110
+ */
111
+ export const BODY_FIELD = "\u0000body";
112
+
84
113
  const STATUS_LABEL: Record<DocumentChange["status"], string> = {
85
114
  A: "Added",
86
115
  M: "Modified",
87
116
  D: "Deleted",
88
117
  R: "Renamed",
118
+ U: "Unchanged",
89
119
  };
90
120
 
91
121
  /** Renders a field value the way the editor would show it, not as raw JSON. */
@@ -142,14 +172,29 @@ function ContextValue({ value }: { value: unknown }) {
142
172
  );
143
173
  }
144
174
 
145
- function FieldRow({ field }: { field: FieldChange }) {
175
+ function FieldRow({
176
+ field,
177
+ selected,
178
+ onToggle,
179
+ }: {
180
+ field: FieldChange;
181
+ // Both present or both absent: selection is offered only for a changed field
182
+ // whose caller wants it (see ChangeDetailProps.onToggleField).
183
+ selected?: boolean;
184
+ onToggle?: () => void;
185
+ }) {
146
186
  const t = useTheme();
147
187
  const changed = field.kind !== "unchanged";
148
188
  return (
149
189
  <View testID={`change-field-${field.name}`} style={{ gap: t.space(2) }}>
150
- <Text variant="label" color="tertiary">
151
- {(field.label || field.name).toUpperCase()}
152
- </Text>
190
+ <View style={{ flexDirection: "row", alignItems: "center", gap: t.space(2) }}>
191
+ {onToggle ? (
192
+ <CheckBox value={!!selected} onToggle={onToggle} testID={`restore-field-${field.name}`} />
193
+ ) : null}
194
+ <Text variant="label" color="tertiary">
195
+ {(field.label || field.name).toUpperCase()}
196
+ </Text>
197
+ </View>
153
198
  {changed ? (
154
199
  <View
155
200
  style={{
@@ -285,7 +330,17 @@ function ConflictSide({ label, value, chosen }: { label: string; value: unknown;
285
330
  * stacked blocks rather than a single line — the whole before and the whole
286
331
  * after, each tinted, so a reviewer can read them.
287
332
  */
288
- function BodyDiff({ before, after }: { before?: string | null; after?: string | null }) {
333
+ function BodyDiff({
334
+ before,
335
+ after,
336
+ selected,
337
+ onToggle,
338
+ }: {
339
+ before?: string | null;
340
+ after?: string | null;
341
+ selected?: boolean;
342
+ onToggle?: () => void;
343
+ }) {
289
344
  const t = useTheme();
290
345
  if ((before ?? "") === (after ?? "")) {
291
346
  if (!after) return null;
@@ -298,7 +353,12 @@ function BodyDiff({ before, after }: { before?: string | null; after?: string |
298
353
  }
299
354
  return (
300
355
  <View testID="change-body" style={{ gap: t.space(2) }}>
301
- <Text variant="label" color="tertiary">BODY</Text>
356
+ <View style={{ flexDirection: "row", alignItems: "center", gap: t.space(2) }}>
357
+ {onToggle ? (
358
+ <CheckBox value={!!selected} onToggle={onToggle} testID="restore-field-body" />
359
+ ) : null}
360
+ <Text variant="label" color="tertiary">BODY</Text>
361
+ </View>
302
362
  <View
303
363
  style={{
304
364
  borderRadius: t.radius.md,
@@ -374,8 +434,21 @@ function AssetPreview({ preview }: { preview: ChangePreview }) {
374
434
  * context. Strictly read-only — editing happens on the Edit surface, and this
375
435
  * view describes a comparison rather than a document you can save.
376
436
  */
377
- export function ChangeDetail({ change, loading, emptyMessage = "Select a change", conflicts, onResolveConflict }: ChangeDetailProps) {
437
+ export function ChangeDetail({
438
+ change,
439
+ loading,
440
+ emptyMessage = "Select a change",
441
+ conflicts,
442
+ onResolveConflict,
443
+ selectedFields,
444
+ onToggleField,
445
+ }: ChangeDetailProps) {
378
446
  const t = useTheme();
447
+ const chosen = new Set(selectedFields ?? []);
448
+ // A field offers a box only when the caller wants selection AND there is
449
+ // something to select — an unchanged field's two sides are the same value.
450
+ const toggleFor = (name: string, changed: boolean) =>
451
+ onToggleField && changed ? () => onToggleField(name) : undefined;
379
452
 
380
453
  // Conflicts keyed by field name (and a body flag), so each field can check for
381
454
  // one as it renders. The body conflict is looked up separately.
@@ -445,7 +518,12 @@ export function ChangeDetail({ change, loading, emptyMessage = "Select a change"
445
518
  onResolve={onResolveConflict ? (choice, override) => onResolveConflict(conflict, choice, override) : undefined}
446
519
  />
447
520
  ) : (
448
- <FieldRow key={f.name} field={f} />
521
+ <FieldRow
522
+ key={f.name}
523
+ field={f}
524
+ selected={chosen.has(f.name)}
525
+ onToggle={toggleFor(f.name, f.kind !== "unchanged")}
526
+ />
449
527
  );
450
528
  })}
451
529
  {/* Conflicts on fields the schema-ordered diff didn't surface (rare). */}
@@ -464,7 +542,12 @@ export function ChangeDetail({ change, loading, emptyMessage = "Select a change"
464
542
  onResolve={onResolveConflict ? (choice, override) => onResolveConflict(bodyConflict!, choice, override) : undefined}
465
543
  />
466
544
  ) : (
467
- <BodyDiff before={change.bodyBefore} after={change.bodyAfter} />
545
+ <BodyDiff
546
+ before={change.bodyBefore}
547
+ after={change.bodyAfter}
548
+ selected={chosen.has(BODY_FIELD)}
549
+ onToggle={toggleFor(BODY_FIELD, (change.bodyBefore ?? "") !== (change.bodyAfter ?? ""))}
550
+ />
468
551
  )}
469
552
  </ScrollView>
470
553
  </View>