Skip to content

Commit 19d7a9e

Browse files
feat(web,mobile): jj terminology, unsupported-repo state and shared vcs actions
Co-authored-by: Лев Федорец <[email protected]>
1 parent 9bc3914 commit 19d7a9e

116 files changed

Lines changed: 6011 additions & 1326 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎apps/mobile/src/features/review/ReviewSheet.tsx‎

Lines changed: 42 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import { settlePromise, squashAtomCommandFailure } from "@t3tools/client-runtime/state/runtime";
22
import { AsyncResult } from "effect/reactivity";
3+
import { getVcsTerminology, type VcsTerminology } from "@t3tools/shared/vcs";
4+
import { selectKind, selectUnsupportedReason, vcsEnvironment } from "../../state/vcs";
5+
import { useEnvironmentQuerySelector } from "../../state/query";
36
import type { EnvironmentId, ThreadId } from "@t3tools/contracts";
47
import { formatDiffCount } from "@t3tools/client-runtime/diff-count";
58
import { useNavigation, type StaticScreenProps } from "@react-navigation/native";
@@ -72,6 +75,7 @@ import { reportShowcaseSceneRendered } from "../showcase/showcaseRenderSignal";
7275
function ReviewHeader(
7376
props: Parameters<typeof useReviewHeaderPresentation>[0] & {
7477
readonly iconColor: string;
78+
readonly vcsTerminology: VcsTerminology;
7579
readonly sectionMenu: ReturnType<typeof buildReviewSectionMenu>;
7680
readonly showSectionToolbar: boolean;
7781
readonly showChangedFilesToggle: boolean;
@@ -124,8 +128,19 @@ function ReviewHeader(
124128
id: "sections",
125129
inline: true,
126130
items: [
127-
sectionAction(props.sectionMenu.branchChanges, "Changes"),
128-
sectionAction(props.sectionMenu.workingTree, "Uncommitted"),
131+
sectionAction(
132+
props.sectionMenu.branchChanges,
133+
props.vcsTerminology.preserveReviewSectionTitles
134+
? (props.sectionMenu.branchChanges?.title ?? "Changes")
135+
: "Changes",
136+
),
137+
sectionAction(
138+
props.sectionMenu.workingTree,
139+
props.vcsTerminology.preserveReviewSectionTitles
140+
? (props.sectionMenu.workingTree?.title ??
141+
props.vcsTerminology.workingTreeNounTitle)
142+
: "Uncommitted",
143+
),
129144
sectionAction(props.sectionMenu.latestTurn, "Latest turn"),
130145
],
131146
},
@@ -456,6 +471,14 @@ export function ReviewSheet(props: ReviewSheetProps) {
456471
const topContentInset = Platform.OS === "ios" ? safeArea.top : 0;
457472
const bottomContentInset =
458473
Platform.OS === "ios" ? safeArea.bottom + 8 : Math.max(insets.bottom, 18) + 18;
474+
const vcsStatusAtom =
475+
selectedThreadCwd === null
476+
? null
477+
: vcsEnvironment.status({ environmentId, input: { cwd: selectedThreadCwd } });
478+
const vcsKind = useEnvironmentQuerySelector(vcsStatusAtom, selectKind);
479+
const vcsTerminology = getVcsTerminology(vcsKind);
480+
const vcsUnsupportedReason = useEnvironmentQuerySelector(vcsStatusAtom, selectUnsupportedReason);
481+
const vcsActionsSupported = vcsUnsupportedReason === null;
459482

460483
useEffect(() => {
461484
showAuxiliaryPane("inspector");
@@ -469,15 +492,16 @@ export function ReviewSheet(props: ReviewSheetProps) {
469492
isSelectedSectionPending,
470493
diffPreviewRevision,
471494
} = useReviewSections({
472-
enabled: isEnvironmentReady,
495+
enabled: isEnvironmentReady && vcsActionsSupported,
473496
environmentId,
474497
threadId,
475498
reviewCache,
499+
vcsKind,
476500
});
477501
useReviewDiffPrewarming({
478502
threadKey: reviewCache.threadKey,
479-
sections: reviewSections,
480-
selectedSectionId: selectedSection?.id ?? null,
503+
sections: vcsActionsSupported ? reviewSections : [],
504+
selectedSectionId: vcsActionsSupported ? (selectedSection?.id ?? null) : null,
481505
});
482506
const {
483507
headerDiffSummary,
@@ -489,8 +513,8 @@ export function ReviewSheet(props: ReviewSheetProps) {
489513
} = useReviewDiffData({
490514
threadKey: reviewCache.threadKey,
491515
environmentId,
492-
cwd: selectedThreadCwd,
493-
selectedSection,
516+
cwd: vcsActionsSupported ? selectedThreadCwd : null,
517+
selectedSection: vcsActionsSupported ? selectedSection : null,
494518
revision: diffPreviewRevision,
495519
draftMessage,
496520
});
@@ -681,6 +705,16 @@ export function ReviewSheet(props: ReviewSheetProps) {
681705
.join(" · ");
682706
const headerTitleText = selectedSection?.title ?? "Review changes";
683707

708+
if (!vcsActionsSupported) {
709+
return (
710+
<ScreenContent>
711+
<Text accessibilityRole="alert" className="p-4 text-sm text-danger-foreground">
712+
{vcsUnsupportedReason}
713+
</Text>
714+
</ScreenContent>
715+
);
716+
}
717+
684718
return (
685719
<>
686720
<ReviewHeader
@@ -690,6 +724,7 @@ export function ReviewSheet(props: ReviewSheetProps) {
690724
subtitle={headerSubtitle}
691725
androidSubtitle={androidHeaderSubtitle}
692726
iconColor={headerIcon}
727+
vcsTerminology={vcsTerminology}
693728
selectedThreadCwd={selectedThreadCwd}
694729
sectionMenu={sectionMenu}
695730
selectedSection={selectedSection}

‎apps/mobile/src/features/review/reviewModel.test.ts‎

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,59 @@ describe("buildReviewSectionItems", () => {
146146
]);
147147
expect(getDefaultReviewSectionId(items)).toBe("git:branch-range");
148148
});
149+
150+
it("names a missing base with the project's ref noun", () => {
151+
const [section] = buildReviewSectionItems({
152+
checkpoints: [],
153+
gitSections: [
154+
{
155+
id: "branch-range",
156+
kind: "branch-range",
157+
title: "Bookmark changes",
158+
baseRef: null,
159+
headRef: null,
160+
diff: "",
161+
diffHash: "h",
162+
truncated: false,
163+
},
164+
],
165+
turnDiffById: {},
166+
loadingTurnIds: {},
167+
loadingGitSections: false,
168+
vcsKind: "jj",
169+
});
170+
171+
expect(section?.subtitle).toBe("Base bookmark unavailable");
172+
});
173+
it("uses jj working copy language while loading and after preview arrives", () => {
174+
const input = {
175+
checkpoints: [],
176+
turnDiffById: {},
177+
loadingTurnIds: {},
178+
loadingGitSections: true,
179+
vcsKind: "jj" as const,
180+
};
181+
expect(buildReviewSectionItems({ ...input, gitSections: [] })[0]?.title).toBe(
182+
"Against base branch",
183+
);
184+
const items = buildReviewSectionItems({
185+
...input,
186+
loadingGitSections: false,
187+
gitSections: [
188+
{
189+
id: "working-tree",
190+
kind: "working-tree",
191+
title: "Working copy",
192+
baseRef: "@-",
193+
headRef: "@",
194+
diff: "",
195+
diffHash: "h",
196+
truncated: false,
197+
},
198+
],
199+
});
200+
expect(items[0]?.subtitle).toBe("Working copy changes");
201+
});
149202
});
150203

151204
describe("buildReviewParsedDiff", () => {

‎apps/mobile/src/features/review/reviewModel.ts‎

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import { parsePatchFiles } from "@pierre/diffs/utils/parsePatchFiles";
22
import type { ChangeTypes, FileDiffMetadata } from "@pierre/diffs/types";
33
import type { ThreadCheckpointSummary } from "@t3tools/client-runtime/state/thread-checkpoints";
4-
import type { ReviewDiffPreviewSource } from "@t3tools/contracts";
4+
import { getVcsTerminology, type VcsTerminology } from "@t3tools/shared/vcs";
5+
import type { ReviewDiffPreviewSource, VcsDriverKind } from "@t3tools/contracts";
56
import * as Arr from "effect/Array";
67
import { pipe } from "effect/Function";
78
import * as Order from "effect/Order";
@@ -10,7 +11,6 @@ export type ReviewSectionKind = "turn" | "working-tree" | "branch-range";
1011

1112
const CHANGES_SECTION_ID = "git:branch-range";
1213
const CHANGES_TITLE = "Changes";
13-
const UNCOMMITTED_SUBTITLE = "Staged, unstaged, and untracked files";
1414

1515
export interface ReviewSectionItem {
1616
readonly id: string;
@@ -121,14 +121,16 @@ const readyCheckpointOrder = Order.make<ThreadCheckpointSummary>(
121121
compareCheckpointTurnCountDescending,
122122
);
123123

124-
function gitSubtitle(section: ReviewDiffPreviewSource): string | null {
124+
function gitSubtitle(section: ReviewDiffPreviewSource, terminology: VcsTerminology): string | null {
125125
if (section.kind === "working-tree") {
126-
return UNCOMMITTED_SUBTITLE;
126+
return terminology.preserveReviewSectionTitles
127+
? `${terminology.workingTreeNounTitle} changes`
128+
: "Staged, unstaged, and untracked files";
127129
}
128130
if (section.baseRef) {
129131
return `${section.baseRef} ... ${section.headRef ?? "HEAD"}`;
130132
}
131-
return "Base branch unavailable";
133+
return `Base ${terminology.refNoun} unavailable`;
132134
}
133135

134136
function stripTrailingNewline(value: string): string {
@@ -416,7 +418,9 @@ export function buildReviewSectionItems(input: {
416418
readonly turnDiffById: Readonly<Record<string, string | undefined>>;
417419
readonly loadingTurnIds: Readonly<Record<string, boolean | undefined>>;
418420
readonly loadingGitSections: boolean;
421+
readonly vcsKind?: VcsDriverKind | null;
419422
}): ReadonlyArray<ReviewSectionItem> {
423+
const terminology = getVcsTerminology(input.vcsKind);
420424
const turnItems = getReadyReviewCheckpoints(input.checkpoints).map<ReviewSectionItem>(
421425
(checkpoint) => {
422426
const id = getReviewSectionIdForCheckpoint(checkpoint);
@@ -435,7 +439,7 @@ export function buildReviewSectionItems(input: {
435439
id: `git:${section.kind}`,
436440
kind: section.kind,
437441
title: section.title,
438-
subtitle: gitSubtitle(section),
442+
subtitle: gitSubtitle(section, terminology),
439443
diff: section.diff,
440444
source: section,
441445
...(section.files ? { files: section.files } : {}),
@@ -449,7 +453,7 @@ export function buildReviewSectionItems(input: {
449453
{
450454
id: CHANGES_SECTION_ID,
451455
kind: "branch-range",
452-
title: CHANGES_TITLE,
456+
title: terminology.preserveReviewSectionTitles ? "Against base branch" : CHANGES_TITLE,
453457
subtitle: null,
454458
diff: null,
455459
isLoading: true,

‎apps/mobile/src/features/review/useReviewSections.ts‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
deriveThreadCheckpointSummaries,
88
type ThreadCheckpointSummary,
99
} from "@t3tools/client-runtime/state/thread-checkpoints";
10-
import type { EnvironmentId, ThreadId } from "@t3tools/contracts";
10+
import type { EnvironmentId, ThreadId, VcsDriverKind } from "@t3tools/contracts";
1111

1212
import { useCheckpointDiff } from "../../state/queries";
1313
import { useEnvironmentQuery } from "../../state/query";
@@ -35,8 +35,10 @@ export function useReviewSections(input: {
3535
readonly environmentId?: EnvironmentId;
3636
readonly threadId?: ThreadId;
3737
readonly reviewCache: ReviewCacheForThread;
38+
readonly vcsKind?: VcsDriverKind | null;
3839
}) {
3940
const { environmentId, reviewCache, threadId } = input;
41+
const vcsKind = input.vcsKind ?? null;
4042
const enabled = input.enabled ?? true;
4143
const fileAccessSession = useEnvironmentQuery(
4244
environmentId === undefined ? null : environmentSession.sessionStateAtom(environmentId),
@@ -94,6 +96,7 @@ export function useReviewSections(input: {
9496
turnDiffById: reviewCache.turnDiffById,
9597
loadingTurnIds,
9698
loadingGitSections: fileAccess.isPending || diffPreview.isPending,
99+
vcsKind,
97100
});
98101
// Keep the selected section while its grant loads, without displaying cached host files.
99102
return fileAccess.isPending
@@ -110,6 +113,7 @@ export function useReviewSections(input: {
110113
readyCheckpoints,
111114
reviewCache.gitSections,
112115
reviewCache.turnDiffById,
116+
vcsKind,
113117
]);
114118
const selectedSection = useMemo(
115119
() =>

‎apps/mobile/src/features/settings/ScheduledTaskPickerScreens.tsx‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { useVcsTerminology } from "../../state/vcs";
12
import { useNavigation } from "@react-navigation/native";
23
import * as Haptics from "expo-haptics";
34
import { useMemo, useState } from "react";
@@ -114,6 +115,10 @@ export function ScheduledTaskBranchPickerRouteScreen() {
114115
cwd: project?.workspaceRoot ?? null,
115116
query: debouncedQuery,
116117
});
118+
const vcsTerminology = useVcsTerminology(
119+
project?.environmentId ?? null,
120+
project?.workspaceRoot ?? null,
121+
);
117122
const visibleBranches = branches.refs.filter(
118123
(branch) => !branch.isRemote && branch.name.toLowerCase().includes(query.trim().toLowerCase()),
119124
);
@@ -122,7 +127,7 @@ export function ScheduledTaskBranchPickerRouteScreen() {
122127

123128
return (
124129
<BranchPickerScreen
125-
title="Base branch"
130+
title={`Base ${vcsTerminology.refNoun}`}
126131
project={project}
127132
branches={visibleBranches}
128133
selectedBranchName={editor.draft.baseRef}

‎apps/mobile/src/features/settings/SettingsServerControlsRouteScreen.test.tsx‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// @vitest-environment jsdom
22
import { DEFAULT_SERVER_SETTINGS, type ServerSettingsPatch } from "@t3tools/contracts";
3+
import { DEFAULT_VCS_TERMINOLOGY } from "@t3tools/shared/vcs";
34
import * as Cause from "effect/Cause";
45
import { AsyncResult } from "effect/reactivity";
56
import type { ReactNode } from "react";
@@ -53,6 +54,7 @@ vi.mock("../../state/session", () => ({
5354
useEnvironmentsWithScope: () => new Set(mocks.targets.map((target) => target.environmentId)),
5455
}));
5556
vi.mock("../../state/server", () => ({ serverEnvironment: { updateSettings: {} } }));
57+
vi.mock("../../state/vcs", () => ({ useVcsTerminology: () => DEFAULT_VCS_TERMINOLOGY }));
5658
vi.mock("../../state/use-atom-command", () => ({
5759
useAtomCommand: () => mocks.updateSettings,
5860
}));

‎apps/mobile/src/features/settings/SettingsServerControlsRouteScreen.tsx‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ import {
3939
type ScopedMobileSettingsTarget,
4040
} from "./settings-scoped-server";
4141
import { PullRequestGlyph } from "../pull-requests/pullRequestGlyphs";
42+
import { useVcsTerminology } from "../../state/vcs";
4243

4344
type SettingsPage = "new-threads" | "source-control" | "agent-behavior" | "maintenance";
4445

@@ -142,6 +143,15 @@ function ServerSettingsDetail(props: { readonly page: SettingsPage }) {
142143
const navigation = useNavigation();
143144
const { selectedTargets, projectGroups, selectedProjectKey } = useSettingsEnvironmentFilter();
144145
const selectedProject = projectGroups.find((group) => group.key === selectedProjectKey);
146+
const terminologyProjects = selectedProject?.members.filter((member) =>
147+
selectedTargets.some((target) => target.environmentId === member.project.environmentId),
148+
);
149+
const terminologyProject =
150+
terminologyProjects?.length === 1 ? terminologyProjects[0]?.project : undefined;
151+
const vcsTerminology = useVcsTerminology(
152+
terminologyProject?.environmentId ?? null,
153+
terminologyProject?.workspaceRoot ?? null,
154+
);
145155
const writableEnvironments = useEnvironmentsWithScope(selectedTargets, AuthSettingsWriteScope);
146156
const projectSelected = selectedProjectKey !== null;
147157
const targets = resolveMobileSettingsTargets(
@@ -363,6 +373,7 @@ function ServerSettingsDetail(props: { readonly page: SettingsPage }) {
363373
instructions={uniform("branchNameInstructions")}
364374
disabled={disabledFor("branchNamingMode")}
365375
onChange={write}
376+
terminology={vcsTerminology}
366377
/>
367378
<SettingsSection title="Pull requests">
368379
<SettingsSwitchRow

0 commit comments

Comments
 (0)