Skip to content

Commit ac8c526

Browse files
authored
feat(desktop): make missing project checkouts actionable (#2159)
1 parent a6432ab commit ac8c526

7 files changed

Lines changed: 103 additions & 48 deletions

File tree

‎desktop/src/features/projects/ui/ProjectDetailScreen.tsx‎

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,9 @@ export function ProjectDetailScreen(props: ProjectDetailScreenProps) {
281281
description:
282282
error instanceof Error ? error.message : "The Git fetch failed.",
283283
});
284+
return;
284285
}
286+
toast.success("Remote state refreshed.");
285287
}, [repoSnapshotQuery, repoStateQuery, repoSyncStatusQuery]);
286288
// Compact branch + remote/local controls shared by the readme and Files
287289
// tab headers.
@@ -301,6 +303,12 @@ export function ProjectDetailScreen(props: ProjectDetailScreenProps) {
301303
? "Local"
302304
: "Local missing",
303305
remoteLabel: repoSnapshotQuery.isLoading ? "Remote checking" : "Remote",
306+
onCloneLocal: project?.cloneUrls[0]
307+
? () => {
308+
void handleCloneRepo();
309+
}
310+
: undefined,
311+
clonePending: cloneRepoMutation.isPending,
304312
canPush: repoSyncStatusQuery.data?.canPush ?? false,
305313
onPush: () => {
306314
void handlePushLocalRepo();
@@ -813,16 +821,6 @@ export function ProjectDetailScreen(props: ProjectDetailScreenProps) {
813821

814822
<WorkspaceTabs
815823
key={`${project.id}:${tabsResetKey}`}
816-
cloneAction={
817-
!hasLocalCheckout && project.cloneUrls[0]
818-
? {
819-
onClone: () => {
820-
void handleCloneRepo();
821-
},
822-
pending: cloneRepoMutation.isPending,
823-
}
824-
: undefined
825-
}
826824
commitDiff={commitDiffQuery.data}
827825
commitDiffError={commitDiffQuery.error}
828826
commitDiffLoading={commitDiffQuery.isLoading}

‎desktop/src/features/projects/ui/ProjectRepositorySource.tsx‎

Lines changed: 36 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { Button } from "@/shared/ui/button";
1313
import {
1414
DropdownMenu,
1515
DropdownMenuContent,
16+
DropdownMenuItem,
1617
DropdownMenuRadioGroup,
1718
DropdownMenuRadioItem,
1819
DropdownMenuTrigger,
@@ -47,12 +48,12 @@ export function RepositoryBranchDropdown({
4748
<Button
4849
className={
4950
compact
50-
? "h-7 max-w-full gap-1.5 rounded-md bg-muted px-3 font-mono text-sm font-medium hover:bg-muted/80"
51-
: "h-6 max-w-full gap-1.5 px-2 font-mono text-sm font-semibold"
51+
? "h-7 max-w-full gap-1.5 rounded-md px-3 font-mono text-sm font-medium hover:border-input"
52+
: "h-6 max-w-full gap-1.5 px-2 font-mono text-sm font-semibold hover:border-input"
5253
}
5354
size="sm"
5455
type="button"
55-
variant="ghost"
56+
variant="outline"
5657
>
5758
<GitBranch className="h-4 w-4 shrink-0 text-muted-foreground" />
5859
<span className="truncate">{branch}</span>
@@ -82,6 +83,9 @@ export type RepoSourceHeaderControls = {
8283
localDisabled: boolean;
8384
localLabel: string;
8485
remoteLabel: string;
86+
/** Clones the repository when no local checkout is available. */
87+
onCloneLocal?: () => void;
88+
clonePending?: boolean;
8589
/** Push of local commits, available when the local checkout is ahead. */
8690
canPush?: boolean;
8791
onPush?: () => void;
@@ -110,15 +114,16 @@ export function RepoSourceDropdown({
110114
controls: RepoSourceHeaderControls;
111115
}) {
112116
const isLocal = controls.source === "local";
117+
const cloneLocal = controls.localDisabled && controls.onCloneLocal;
113118
const SourceIcon = isLocal ? HardDrive : Cloud;
114119
return (
115120
<DropdownMenu>
116121
<DropdownMenuTrigger asChild>
117122
<Button
118-
className="h-7 max-w-full shrink-0 gap-1.5 rounded-md bg-muted px-3 text-sm font-medium hover:bg-muted/80"
123+
className="h-7 max-w-full shrink-0 gap-1.5 rounded-md px-3 text-sm font-medium hover:border-input"
119124
size="sm"
120125
type="button"
121-
variant="ghost"
126+
variant="outline"
122127
>
123128
<SourceIcon className="h-4 w-4 shrink-0 text-muted-foreground" />
124129
<span className="truncate">
@@ -138,14 +143,33 @@ export function RepoSourceDropdown({
138143
<Cloud className="mr-1.5 h-3.5 w-3.5 text-muted-foreground" />
139144
{controls.remoteLabel}
140145
</DropdownMenuRadioItem>
141-
<DropdownMenuRadioItem
142-
disabled={controls.localDisabled}
143-
value="local"
144-
>
145-
<HardDrive className="mr-1.5 h-3.5 w-3.5 text-muted-foreground" />
146-
{controls.localLabel}
147-
</DropdownMenuRadioItem>
146+
{!cloneLocal ? (
147+
<DropdownMenuRadioItem
148+
disabled={controls.localDisabled}
149+
value="local"
150+
>
151+
<HardDrive className="mr-1.5 h-3.5 w-3.5 text-muted-foreground" />
152+
{controls.localLabel}
153+
</DropdownMenuRadioItem>
154+
) : null}
148155
</DropdownMenuRadioGroup>
156+
{cloneLocal ? (
157+
<DropdownMenuItem
158+
className="group"
159+
disabled={controls.clonePending}
160+
onSelect={controls.onCloneLocal}
161+
>
162+
{controls.clonePending ? (
163+
<Loader2 className="animate-spin text-muted-foreground" />
164+
) : (
165+
<DownloadCloud className="text-muted-foreground" />
166+
)}
167+
<span className="text-muted-foreground">{controls.localLabel}</span>
168+
<span className="ml-auto rounded-md border border-input/60 bg-background px-2 py-0.5 text-xs font-medium text-foreground shadow-xs group-focus:border-input">
169+
{controls.clonePending ? "Cloning…" : "Clone"}
170+
</span>
171+
</DropdownMenuItem>
172+
) : null}
149173
</DropdownMenuContent>
150174
</DropdownMenu>
151175
);

‎desktop/src/features/projects/ui/ProjectWorkspaceTabs.tsx‎

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import {
22
CircleDot,
3-
Download,
43
GitPullRequest,
54
Plus,
65
RefreshCw,
@@ -48,11 +47,6 @@ import {
4847
} from "./CreateIssueDialog";
4948
import { PROJECT_PANEL_ACTION_BUTTON_CLASS } from "./projectPanelStyles";
5049

51-
type CloneRepositoryAction = {
52-
onClone: () => void;
53-
pending: boolean;
54-
};
55-
5650
type CreatePullRequestAction = {
5751
projects: Project[];
5852
reposDir?: string | null;
@@ -106,7 +100,6 @@ function WorkItemListHeader({
106100
}
107101

108102
export function WorkspaceTabs({
109-
cloneAction,
110103
commitDiff,
111104
commitDiffError,
112105
commitDiffLoading,
@@ -142,7 +135,6 @@ export function WorkspaceTabs({
142135
terminalTitle,
143136
viewerGitIdentity,
144137
}: {
145-
cloneAction?: CloneRepositoryAction;
146138
commitDiff: ProjectRepoDiff | null | undefined;
147139
commitDiffError: unknown;
148140
commitDiffLoading: boolean;
@@ -276,19 +268,6 @@ export function WorkspaceTabs({
276268
<SquareTerminal className="h-[1.125rem] w-[1.125rem]" />
277269
</Button>
278270
) : null}
279-
{cloneAction ? (
280-
<Button
281-
className="h-8 shrink-0 gap-1.5"
282-
disabled={cloneAction.pending}
283-
onClick={cloneAction.onClone}
284-
size="sm"
285-
title="Clone repository"
286-
variant="outline"
287-
>
288-
<Download className="h-4 w-4" />
289-
{cloneAction.pending ? "Cloning…" : "Clone"}
290-
</Button>
291-
) : null}
292271
{updatePullRequestAction ? (
293272
<Button
294273
className="h-8 shrink-0 gap-1.5"

‎desktop/src/features/projects/ui/ProjectsView.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -559,7 +559,7 @@ export function ProjectsView() {
559559
<PageHeader
560560
className="pointer-events-auto mb-8"
561561
description="Set up and manage your projects."
562-
title={activeCommunity?.name || "Relay"}
562+
title="Projects"
563563
/>
564564
);
565565

‎desktop/src/testing/e2eBridge.ts‎

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9281,12 +9281,33 @@ export function maybeInstallE2eTauriMocks() {
92819281
pulled: true,
92829282
message: "Pulled main from remote.",
92839283
};
9284-
case "clone_project_repository":
9284+
case "clone_project_repository": {
9285+
const path = "/tmp/buzz/REPOS/mock-project";
9286+
const commit = "0123456789abcdef0123456789abcdef01234567";
9287+
window.__BUZZ_E2E_PROJECT_REPO_SYNC_STATUS__ = {
9288+
local_path: path,
9289+
local_branch: "main",
9290+
local_head: commit,
9291+
local_short_head: commit.slice(0, 7),
9292+
remote_branch: "main",
9293+
remote_head: commit,
9294+
remote_short_head: commit.slice(0, 7),
9295+
merge_base: commit,
9296+
ahead_count: 0,
9297+
behind_count: 0,
9298+
has_uncommitted_changes: false,
9299+
has_untracked_files: false,
9300+
can_push: false,
9301+
push_block_reason: "Local branch is already pushed.",
9302+
can_pull: false,
9303+
pull_block_reason: "Local branch is up to date.",
9304+
};
92859305
return {
9286-
path: "/tmp/buzz/REPOS/mock-project",
9306+
path,
92879307
cloned: true,
92889308
message: "Cloned repository.",
92899309
};
9310+
}
92909311
case "sign_project_pull_request_review_request": {
92919312
const { input } = payload as {
92929313
input: {

‎desktop/tests/e2e/project-commit-detail.spec.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ test("top-level project lists align dates and overflow actions", async ({
2727
await installMockBridge(page);
2828
await page.goto("/", { waitUntil: "domcontentloaded" });
2929
await page.getByTestId("open-projects-view").click();
30+
await expect(
31+
page.getByRole("heading", { level: 1, name: "Projects" }),
32+
).toBeVisible();
3033

3134
async function trailingPositions(row: import("@playwright/test").Locator) {
3235
await waitForAnimations(page);

‎desktop/tests/e2e/project-pr-review.spec.ts‎

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -327,13 +327,43 @@ test("viewer without repository ownership cannot merge", async ({ page }) => {
327327
);
328328
});
329329

330-
test("project without a checkout can be cloned", async ({ page }) => {
330+
test("project without a checkout offers fetch feedback and dropdown cloning", async ({
331+
page,
332+
}) => {
331333
await enableProjectsFeature(page);
332334
await installMockBridge(page);
333335
await openBuzzProject(page);
334336

335-
await page.getByRole("button", { name: "Clone", exact: true }).click();
337+
await expect(
338+
page.getByRole("button", { name: "Remote", exact: true }),
339+
).toBeVisible();
340+
await expect(
341+
page.getByRole("button", { name: "Remote", exact: true }),
342+
).toHaveClass(/\bborder-input\/40\b/);
343+
await expect(page.getByRole("button", { name: /main/ })).toHaveClass(
344+
/\bborder-input\/40\b/,
345+
);
346+
await expect(
347+
page.getByRole("button", { name: "Clone", exact: true }),
348+
).toHaveCount(0);
349+
await page.getByRole("button", { name: "Fetch", exact: true }).click();
350+
await expect(page.getByText("Remote state refreshed.")).toBeVisible();
351+
352+
await page.getByRole("button", { name: "Remote", exact: true }).click();
353+
const cloneItem = page.getByRole("menuitem", {
354+
name: "Local missing Clone",
355+
});
356+
await expect(cloneItem.getByText("Local missing")).toHaveClass(
357+
/text-muted-foreground/,
358+
);
359+
await expect(cloneItem.getByText("Clone", { exact: true })).toHaveClass(
360+
/\bborder-input\/60\b/,
361+
);
362+
await cloneItem.click();
336363
await expect(page.getByText("Cloned repository.")).toBeVisible();
364+
await expect(
365+
page.getByRole("button", { name: "Local", exact: true }),
366+
).toBeVisible();
337367
const commands = await page.evaluate(
338368
() => window.__BUZZ_E2E_COMMANDS__ ?? [],
339369
);

0 commit comments

Comments
 (0)