Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export {
type WorkspacePullRequestSummary,
workspacePullRequests,
} from "./workspacePullRequests";
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { describe, expect, test } from "bun:test";
import {
type WorkspacePullRequestSummary,
workspacePullRequests,
} from "./workspacePullRequests";

const pr = (number: number, repo = "app"): WorkspacePullRequestSummary => ({
number,
title: `PR ${number}`,
state: "open",
url: `https://github.com/acme/${repo}/pull/${number}`,
});

describe("workspacePullRequests", () => {
test("falls back to the current PR on an older host", () => {
expect(workspacePullRequests(pr(1), undefined)).toEqual([pr(1)]);
});
test("keeps current first and deduplicates by repository URL, not number", () => {
expect(
workspacePullRequests(pr(2), [pr(1), pr(2), pr(1, "other")]),
).toEqual([pr(2), pr(1), pr(1, "other")]);
});
test("retains history when there is no current link", () => {
expect(workspacePullRequests(null, [pr(1)])).toEqual([pr(1)]);
expect(workspacePullRequests(null, undefined)).toEqual([]);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import type { PRState } from "renderer/screens/main/components/PRIcon/PRIcon";

export interface WorkspacePullRequestSummary {
url: string;
number: number;
title: string;
state: PRState;
}

export function workspacePullRequests(
current: WorkspacePullRequestSummary | null,
associated:
| readonly (WorkspacePullRequestSummary & { isDraft?: boolean })[]
| undefined,
): WorkspacePullRequestSummary[] {
const byUrl = new Map<string, WorkspacePullRequestSummary>();
if (current) byUrl.set(current.url, current);
for (const pr of associated ?? []) {
if (!byUrl.has(pr.url)) {
byUrl.set(
pr.url,
pr.isDraft && pr.state === "open" ? { ...pr, state: "draft" } : pr,
);
}
}
return [...byUrl.values()];
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
useRef,
useState,
} from "react";
import { DashboardSidebarWorkspacePullRequestsMenu } from "renderer/routes/_authenticated/_dashboard/components/DashboardSidebar/components/DashboardSidebarWorkspaceItem/components/DashboardSidebarWorkspacePullRequestsMenu";
import { useOptimisticActions } from "renderer/routes/_authenticated/hooks/useOptimisticActions";
import { RenameBranchDialog } from "renderer/screens/main/components/WorkspaceSidebar/WorkspaceListItem/components";
import {
Expand Down Expand Up @@ -225,7 +226,7 @@ export function DashboardSidebarWorkspaceItem({
ref={rowRef}
onMouseEnter={handleMouseEnter}
onMouseLeave={handleMouseLeave}
className="relative flex w-full justify-center"
className="relative flex w-full flex-col items-center"
>
{accentColor && (
<div
Expand Down Expand Up @@ -254,6 +255,13 @@ export function DashboardSidebarWorkspaceItem({
: undefined
}
/>
{!isPending && (
<DashboardSidebarWorkspacePullRequestsMenu
workspaceId={id}
pullRequests={workspace.pullRequests}
currentUrl={pullRequest?.url}
/>
)}
</div>
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { useFocusVisible } from "renderer/hooks/useFocusVisible";
import { HotkeyLabel } from "renderer/hotkeys";
import { usePullRequestLinkPolicy } from "renderer/lib/clickPolicy";
import { openPullRequestLink } from "renderer/lib/github/openPullRequestLink";
import { DashboardSidebarWorkspacePullRequestsMenu } from "renderer/routes/_authenticated/_dashboard/components/DashboardSidebar/components/DashboardSidebarWorkspaceItem/components/DashboardSidebarWorkspacePullRequestsMenu";
import { useDashboardSidebarWorkspacePorts } from "renderer/routes/_authenticated/_dashboard/components/DashboardSidebar/providers/DashboardSidebarPortsProvider";
import { navigateToV2Workspace } from "renderer/routes/_authenticated/_dashboard/utils/workspace-navigation";
import { ProjectThumbnail } from "renderer/routes/_authenticated/components/ProjectThumbnail";
Expand Down Expand Up @@ -445,6 +446,13 @@ export const DashboardSidebarExpandedWorkspaceRow = forwardRef<
</div>
)}
</div>
{!isPending && (
<DashboardSidebarWorkspacePullRequestsMenu
workspaceId={workspace.id}
pullRequests={workspace.pullRequests}
currentUrl={pullRequest?.url}
/>
)}
{ports.length > 0 && (
<DashboardSidebarRowEventBoundary>
<DashboardSidebarPortsChip ports={ports} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ import {
import { Separator } from "@superset/ui/separator";
import { toast } from "@superset/ui/sonner";
import { LuLoaderCircle, LuX } from "react-icons/lu";
import { useDashboardSidebarChipHoverSuppression } from "renderer/routes/_authenticated/_dashboard/components/DashboardSidebar/components/DashboardSidebarWorkspaceItem/hooks/useDashboardSidebarChipHoverSuppression";
import { useDashboardSidebarPortKill } from "renderer/routes/_authenticated/_dashboard/components/DashboardSidebar/hooks/useDashboardSidebarPortKill";
import type { DashboardSidebarPort } from "renderer/routes/_authenticated/_dashboard/components/DashboardSidebar/hooks/useDashboardSidebarPortsData";
import { useHoverCardSafeTriangle } from "renderer/routes/_authenticated/_dashboard/components/DashboardSidebar/hooks/useHoverCardSafeTriangle";
import { PortsCountIcon } from "renderer/routes/_authenticated/_dashboard/components/PortsCountIcon";
import { STROKE_WIDTH } from "renderer/screens/main/components/WorkspaceSidebar/constants";
import { useDashboardSidebarChipHoverSuppression } from "../../hooks/useDashboardSidebarChipHoverSuppression";
import { DashboardSidebarPortHoverRow } from "./components/DashboardSidebarPortHoverRow";

interface DashboardSidebarPortsChipProps {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import {
HoverCardTrigger,
} from "@superset/ui/hover-card";
import { cn } from "@superset/ui/utils";
import { useDashboardSidebarChipHoverSuppression } from "renderer/routes/_authenticated/_dashboard/components/DashboardSidebar/components/DashboardSidebarWorkspaceItem/hooks/useDashboardSidebarChipHoverSuppression";
import { STATUS_PRIORITY } from "shared/tabs-types";
import { useDashboardSidebarChipHoverSuppression } from "../../../../hooks/useDashboardSidebarChipHoverSuppression";
import type { DashboardSidebarRunningAgent } from "../../hooks/useDashboardSidebarWorkspaceRunningAgents";
import { DashboardSidebarAgentAvatar } from "./components/DashboardSidebarAgentAvatar";
import { DashboardSidebarAgentHoverRow } from "./components/DashboardSidebarAgentHoverRow";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ import {
} from "react-icons/lu";
import type { DiffStats } from "renderer/hooks/host-service/useDiffStats";
import { useHotkeyDisplay } from "renderer/hotkeys";
import { PullRequestStatusBadge } from "renderer/routes/_authenticated/_dashboard/components/PullRequestStatusBadge";
import type { DashboardSidebarWorkspace } from "../../../../types";
import { ChecksList } from "./components/ChecksList";
import { ChecksSummary } from "./components/ChecksSummary";
import { LinkedTaskSection } from "./components/LinkedTaskSection";
import { PullRequestStatusBadge } from "./components/PullRequestStatusBadge";
import { ReviewStatus } from "./components/ReviewStatus";

interface DashboardSidebarWorkspaceHoverCardContentProps {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
import { afterEach, expect, test } from "bun:test";
import {
createMemoryHistory,
createRootRoute,
createRouter,
RouterProvider,
} from "@tanstack/react-router";
import {
act,
cleanup,
fireEvent,
render,
waitFor,
within,
} from "@testing-library/react";
import {
DashboardSidebarHoverProvider,
useDashboardSidebarHover,
} from "../../../../providers/DashboardSidebarHoverProvider";
import type { DashboardSidebarWorkspace } from "../../../../types";
import { DashboardSidebarWorkspacePullRequestsMenu } from "./DashboardSidebarWorkspacePullRequestsMenu";

(
globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean }
).IS_REACT_ACT_ENVIRONMENT = true;
afterEach(cleanup);

test("a PR menu suppresses a pending workspace hover and releases it on close", async () => {
let pendingOpen: (() => void) | undefined;
const originalSetTimeout = globalThis.setTimeout;
globalThis.setTimeout = ((
...[callback, delay, ...args]: Parameters<typeof setTimeout>
) => {
if (delay === 400) {
pendingOpen = () => callback(...args);
return originalSetTimeout(() => {}, 0);
}
return originalSetTimeout(callback, delay, ...args);
}) as typeof setTimeout;
const hover: { current: ReturnType<typeof useDashboardSidebarHover> | null } =
{ current: null };
function Row() {
hover.current = useDashboardSidebarHover();
return (
<div
data-testid="row"
role="treeitem"
tabIndex={0}
onMouseEnter={(event) =>
hover.current?.requestOpen("ws", event.currentTarget, {
workspace: { id: "ws" } as DashboardSidebarWorkspace,
})
}
>
<DashboardSidebarWorkspacePullRequestsMenu
workspaceId="ws"
currentUrl="https://github.com/acme/app/pull/1"
pullRequests={[1, 2].map((number) => ({
number,
title: `PR ${number}`,
state: "open",
url: `https://github.com/acme/app/pull/${number}`,
}))}
/>
</div>
);
}
const root = createRootRoute({
component: () => (
<DashboardSidebarHoverProvider>
<Row />
</DashboardSidebarHoverProvider>
),
});
const router = createRouter({
routeTree: root,
history: createMemoryHistory({ initialEntries: ["/"] }),
});
try {
render(<RouterProvider router={router} />);
await act(async () => {
await router.load();
});
fireEvent.mouseEnter(within(document.body).getByTestId("row"));
expect(pendingOpen).toBeDefined();
fireEvent.keyDown(
within(document.body).getByRole("button", {
name: "Open pull requests (2)",
}),
{ key: "Enter" },
);
const menu = await within(document.body).findByRole("menu");
act(() => pendingOpen?.());
expect(hover.current?.hoverCardSuppressed).toBe(true);
expect(hover.current?.hoveredId).toBeNull();
fireEvent.keyDown(menu, { key: "Escape" });
await waitFor(() => expect(hover.current?.hoverCardSuppressed).toBe(false));
} finally {
globalThis.setTimeout = originalSetTimeout;
}
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import type { WorkspacePullRequestSummary } from "renderer/lib/github/workspacePullRequests";
import { WorkspacePullRequestsMenu } from "renderer/routes/_authenticated/_dashboard/components/WorkspacePullRequestsMenu";
import { useDashboardSidebarChipHoverSuppression } from "../../hooks/useDashboardSidebarChipHoverSuppression";

interface DashboardSidebarWorkspacePullRequestsMenuProps {
workspaceId: string;
pullRequests: readonly WorkspacePullRequestSummary[] | undefined;
currentUrl?: string | null;
}

export function DashboardSidebarWorkspacePullRequestsMenu(
props: DashboardSidebarWorkspacePullRequestsMenuProps,
) {
const { onOpenChange } = useDashboardSidebarChipHoverSuppression();
return <WorkspacePullRequestsMenu {...props} onOpenChange={onOpenChange} />;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { DashboardSidebarWorkspacePullRequestsMenu } from "./DashboardSidebarWorkspacePullRequestsMenu";
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ const cloudRow = makeWorkspace({
hostIsOnline: null,
isMine: true,
projectId: "stale",
pullRequests: [7, 8].map((number) => ({
number,
url: `https://github.com/acme/app/pull/${number}`,
title: `PR ${number}`,
state: "open",
})),
});
const local = makeWorkspace({ id: "w1", name: "fix-login" });
const cloudRowById = new Map([["c1", cloudRow]]);
Expand Down Expand Up @@ -89,5 +95,6 @@ describe("applyCloudSidebarRows", () => {
expect(pinned?.hostType).toBe("cloud");
expect(pinned?.isPinned).toBe(true);
expect(pinned?.projectName).toBe("Superset");
expect(pinned?.pullRequests).toBe(cloudRow.pullRequests);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,43 @@ describe("buildCloudSidebarWorkspaces", () => {
expect(rows[0]?.lastActivityAt).toBe(DATE.getTime());
});

it.each([
true,
false,
])("keeps all cloud PRs for existing project=%s", (knownProject) => {
const prs = [
makePullRequest({ isDraft: true }),
makePullRequest({
number: 8,
url: "https://github.com/acme/app/pull/8",
state: "closed",
}),
makePullRequest({
number: 7,
url: "https://github.com/acme/other/pull/7",
state: "merged",
}),
];
const layout = build({
cloudWorkspaces: [makeCloudWorkspace({ id: "ws-1" })],
projects: knownProject
? [{ id: "p1", githubOwner: "acme", githubRepoName: "app" }]
: [],
repoFullNameById: new Map([["ws-1", "acme/app"]]),
pullRequestsById: new Map([["ws-1", [...prs, ...prs]]]),
});
const row = knownProject
? layout.byProjectId.get("p1")?.[0]
: layout.repoProjects[0]?.cloudWorkspaces[0];
expect(row?.pullRequest?.number).toBe(7);
expect(row?.pullRequest?.state).toBe("draft");
expect(row?.pullRequests?.map((pr) => [pr.url, pr.state])).toEqual([
[prs[0]?.url, "draft"],
[prs[1]?.url, "closed"],
[prs[2]?.url, "merged"],
]);
});

it("badges the workspace's first pull request, on the live branch", () => {
const pullRequest = makePullRequest({ isDraft: true });
const layout = build({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import type {
} from "@superset/shared/pull-request";
import { resolveProjectIconUrl } from "renderer/hooks/host-projects/resolveProjectIconUrl";
import { cloudRepoProjectId } from "renderer/lib/github/cloudRepoProjectId";
import { workspacePullRequests } from "renderer/lib/github/workspacePullRequests";
import { getV2WorkspaceDisplayName } from "renderer/utils/getV2WorkspaceDisplayName";
import type {
DashboardSidebarWorkspace,
Expand Down Expand Up @@ -149,6 +150,10 @@ export function buildCloudSidebarWorkspaces({
name: getV2WorkspaceDisplayName({ name: workspace.name, branch }),
branch,
pullRequest: pullRequest ? toSidebarPullRequest(pullRequest) : null,
pullRequests: workspacePullRequests(
null,
pullRequestsById.get(workspace.id),
),
repoUrl: repoFullName ? `https://github.com/${repoFullName}` : null,
branchExistsOnRemote: repoFullName !== null,
previewUrl: null,
Expand Down
Loading
Loading