Skip to content
Closed
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
47 changes: 47 additions & 0 deletions apps/desktop/src/lib/trpc/routers/workspaces/procedures/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -333,5 +333,52 @@ export const createCreateProcedures = () => {
projectId: project.id,
};
}),

createCloudWorkspace: publicProcedure
.input(
z.object({
projectId: z.string(),
name: z.string().optional(),
}),
)
.mutation(async ({ input }) => {
const project = localDb
.select()
.from(projects)
.where(eq(projects.id, input.projectId))
.get();
if (!project) {
throw new Error(`Project ${input.projectId} not found`);
}

const maxTabOrder = getMaxWorkspaceTabOrder(input.projectId);
const workspaceName = input.name?.trim() || "Cloud Workspace";

const workspace = localDb
.insert(workspaces)
.values({
projectId: input.projectId,
type: "cloud",
branch: "cloud",
name: workspaceName,
tabOrder: maxTabOrder + 1,
})
.returning()
.get();

setLastActiveWorkspace(workspace.id);
activateProject(project);

track("workspace_created", {
workspace_id: workspace.id,
project_id: project.id,
type: "cloud",
});

return {
workspace,
projectId: project.id,
};
}),
});
};
11 changes: 7 additions & 4 deletions apps/desktop/src/lib/trpc/routers/workspaces/procedures/query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ export const createQueryProcedures = () => {

return {
...workspace,
type: workspace.type as "worktree" | "branch",
type: workspace.type as "worktree" | "branch" | "cloud",
worktreePath: getWorkspacePath(workspace) ?? "",
project: project
? {
Expand Down Expand Up @@ -165,7 +165,7 @@ export const createQueryProcedures = () => {
projectId: string;
worktreeId: string | null;
worktreePath: string;
type: "worktree" | "branch";
type: "worktree" | "branch" | "cloud";
branch: string;
name: string;
tabOrder: number;
Expand Down Expand Up @@ -206,13 +206,16 @@ export const createQueryProcedures = () => {
let worktreePath = "";
if (workspace.type === "worktree" && workspace.worktreeId) {
worktreePath = worktreePathMap.get(workspace.worktreeId) ?? "";
} else if (workspace.type === "branch") {
} else if (
workspace.type === "branch" ||
workspace.type === "cloud"
) {
worktreePath = group.project.mainRepoPath;
}

group.workspaces.push({
...workspace,
type: workspace.type as "worktree" | "branch",
type: workspace.type as "worktree" | "branch" | "cloud",
worktreePath,
isUnread: workspace.isUnread ?? false,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ export function getWorktreePath(worktreeId: string): string | undefined {
/**
* Gets the working directory path for a workspace.
* For worktree workspaces: returns the worktree path
* For branch workspaces: returns the main repo path
* For branch/cloud workspaces: returns the main repo path
*/
export function getWorkspacePath(workspace: SelectWorkspace): string | null {
if (workspace.type === "branch") {
if (workspace.type === "branch" || workspace.type === "cloud") {
const project = localDb
.select()
.from(projects)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import {
} from "@superset/ui/select";
import { toast } from "@superset/ui/sonner";
import { useEffect, useMemo, useRef, useState } from "react";
import { GoGitBranch } from "react-icons/go";
import { GoCloud, GoGitBranch } from "react-icons/go";
import { HiCheck, HiChevronDown, HiChevronUpDown } from "react-icons/hi2";
import { electronTrpc } from "renderer/lib/electron-trpc";
import { formatRelativeTime } from "renderer/lib/formatRelativeTime";
Expand Down Expand Up @@ -83,6 +83,9 @@ export function NewWorkspaceModal() {
{ enabled: !!selectedProjectId },
);
const createWorkspace = useCreateWorkspace();
const createCloudWorkspace =
electronTrpc.workspaces.createCloudWorkspace.useMutation();
const utils = electronTrpc.useUtils();

// Filter branches based on search
const filteredBranches = useMemo(() => {
Expand Down Expand Up @@ -140,12 +143,17 @@ export function NewWorkspaceModal() {
}, [isOpen, selectedProjectId, mode]);

const handleKeyDown = (e: React.KeyboardEvent) => {
const isPending =
mode === "cloud"
? createCloudWorkspace.isPending
: createWorkspace.isPending;

if (
e.key === "Enter" &&
!e.shiftKey &&
mode === "new" &&
(mode === "new" || mode === "cloud") &&
selectedProjectId &&
!createWorkspace.isPending
!isPending
) {
e.preventDefault();
handleCreateWorkspace();
Expand All @@ -169,6 +177,20 @@ export function NewWorkspaceModal() {
const customBranchName = branchName.trim() || undefined;

try {
if (mode === "cloud") {
await createCloudWorkspace.mutateAsync({
projectId: selectedProjectId,
name: workspaceName,
});

// Invalidate workspace queries to refresh sidebar
await utils.workspaces.getAllGrouped.invalidate();

handleClose();
toast.success("Cloud workspace created");
return;
}

const result = await createWorkspace.mutateAsync({
projectId: selectedProjectId,
name: workspaceName,
Expand Down Expand Up @@ -431,11 +453,31 @@ export function NewWorkspaceModal() {
/>
)}
{mode === "cloud" && (
<div className="flex flex-col items-center justify-center py-8 text-center">
<div className="text-sm font-medium text-foreground mb-1">
Cloud Workspaces
<div className="space-y-3">
<Input
id="cloud-title"
className="h-9 text-sm"
placeholder="Workspace name (press Enter to create)"
value={title}
onChange={(e) => setTitle(e.target.value)}
/>

<div className="rounded-md border border-border bg-muted/30 px-3 py-2">
<div className="flex items-center gap-2 text-xs text-muted-foreground">
<span className="inline-flex items-center justify-center size-5 rounded-full bg-primary/10 text-primary">
<GoCloud className="size-3" />
</span>
<span>Cloud workspace powered by remote development</span>
</div>
</div>
<p className="text-xs text-muted-foreground">Coming soon</p>

<Button
className="w-full h-8 text-sm"
onClick={handleCreateWorkspace}
disabled={createCloudWorkspace.isPending}
>
Create Cloud Workspace
</Button>
</div>
)}
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { Tooltip, TooltipContent, TooltipTrigger } from "@superset/ui/tooltip";
import { useParams } from "@tanstack/react-router";
import { LuCloud } from "react-icons/lu";
import { electronTrpc } from "renderer/lib/electron-trpc";
import { OpenInMenuButton } from "./OpenInMenuButton";
import { OrganizationDropdown } from "./OrganizationDropdown";
Expand All @@ -13,6 +15,7 @@ export function TopBar() {
);
// Default to Mac layout while loading to avoid overlap with traffic lights
const isMac = platform === undefined || platform === "darwin";
const isCloudWorkspace = workspace?.type === "cloud";

return (
<div className="drag gap-2 h-12 w-full flex items-center justify-between bg-background border-b border-border">
Expand All @@ -21,7 +24,21 @@ export function TopBar() {
style={{
paddingLeft: isMac ? "88px" : "16px",
}}
/>
>
{isCloudWorkspace && (
<Tooltip delayDuration={300}>
<TooltipTrigger asChild>
<div className="no-drag flex items-center gap-1.5 px-2 py-1 rounded-md bg-primary/10 text-primary text-xs font-medium">
<LuCloud className="size-3.5" />
<span>Cloud</span>
</div>
</TooltipTrigger>
<TooltipContent side="bottom">
<p className="text-xs">Cloud workspace - hosted remotely</p>
</TooltipContent>
</Tooltip>
)}
</div>

<div className="flex-1" />

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ interface Workspace {
id: string;
projectId: string;
worktreePath: string;
type: "worktree" | "branch";
type: "worktree" | "branch" | "cloud";
branch: string;
name: string;
tabOrder: number;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ interface WorkspaceListItemProps {
worktreePath: string;
name: string;
branch: string;
type: "worktree" | "branch";
type: "worktree" | "branch" | "cloud";
isUnread?: boolean;
index: number;
shortcutIndex?: number;
Expand All @@ -84,6 +84,7 @@ export function WorkspaceListItem({
isCollapsed = false,
}: WorkspaceListItemProps) {
const isBranchWorkspace = type === "branch";
const isCloudWorkspace = type === "cloud";
const navigate = useNavigate();
const matchRoute = useMatchRoute();
const reorderWorkspaces = useReorderWorkspaces();
Expand Down Expand Up @@ -308,6 +309,21 @@ export function WorkspaceListItem({
);
}

// Cloud workspaces get a simple tooltip
if (isCloudWorkspace) {
return (
<Tooltip delayDuration={300}>
<TooltipTrigger asChild>{collapsedButton}</TooltipTrigger>
<TooltipContent side="right" className="flex flex-col gap-0.5">
<span className="font-medium">{name || branch}</span>
<span className="text-xs text-muted-foreground">
Cloud workspace
</span>
</TooltipContent>
</Tooltip>
);
}

// Worktree workspaces get the full hover card with context menu
return (
<>
Expand Down Expand Up @@ -414,7 +430,14 @@ export function WorkspaceListItem({
</div>
</TooltipTrigger>
<TooltipContent side="right" sideOffset={8}>
{isBranchWorkspace ? (
{isCloudWorkspace ? (
<>
<p className="text-xs font-medium">Cloud workspace</p>
<p className="text-xs text-muted-foreground">
Hosted in the cloud for remote development
</p>
</>
) : isBranchWorkspace ? (
<>
<p className="text-xs font-medium">Local workspace</p>
<p className="text-xs text-muted-foreground">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
interface DeleteWorkspaceDialogProps {
workspaceId: string;
workspaceName: string;
workspaceType?: "worktree" | "branch";
workspaceType?: "worktree" | "branch" | "cloud";
open: boolean;
onOpenChange: (open: boolean) => void;
}
Expand All @@ -31,6 +31,7 @@ export function DeleteWorkspaceDialog({
onOpenChange,
}: DeleteWorkspaceDialogProps) {
const isBranch = workspaceType === "branch";
const isCloud = workspaceType === "cloud";
const deleteWorkspace = useDeleteWorkspace();
const closeWorkspace = useCloseWorkspace();

Expand Down Expand Up @@ -108,8 +109,8 @@ export function DeleteWorkspaceDialog({
const hasUnpushedCommits = canDeleteData?.hasUnpushedCommits ?? false;
const hasWarnings = hasChanges || hasUnpushedCommits;

// For branch workspaces, use simplified dialog (only close option)
if (isBranch) {
// For branch/cloud workspaces, use simplified dialog (only close option)
if (isBranch || isCloud) {
return (
<AlertDialog open={open} onOpenChange={onOpenChange}>
<AlertDialogContent className="max-w-[340px] gap-0 p-0">
Expand All @@ -120,8 +121,9 @@ export function DeleteWorkspaceDialog({
<AlertDialogDescription asChild>
<div className="text-muted-foreground space-y-1.5">
<span className="block">
This will close the workspace and kill any active terminals.
Your branch and commits will remain in the repository.
{isCloud
? "This will disconnect from the cloud workspace and kill any active terminals."
: "This will close the workspace and kill any active terminals. Your branch and commits will remain in the repository."}
</span>
</div>
</AlertDialogDescription>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export function WorkspaceRow({
isOpening,
}: WorkspaceRowProps) {
const isBranch = workspace.type === "branch";
const isCloud = workspace.type === "cloud";
const [hasHovered, setHasHovered] = useState(false);
const { showDeleteDialog, setShowDeleteDialog, handleDeleteClick } =
useWorkspaceDeleteHandler();
Expand Down Expand Up @@ -104,7 +105,14 @@ export function WorkspaceRow({
</div>
</TooltipTrigger>
<TooltipContent side="top" sideOffset={4}>
{isBranch ? (
{isCloud ? (
<>
<p className="text-xs font-medium">Cloud workspace</p>
<p className="text-xs text-muted-foreground">
Hosted in the cloud for remote development
</p>
</>
) : isBranch ? (
<>
<p className="text-xs font-medium">Local workspace</p>
<p className="text-xs text-muted-foreground">
Expand Down Expand Up @@ -181,11 +189,12 @@ export function WorkspaceRow({
// Determine the delete/close action label based on workspace type and state
const isOpenWorkspace = workspace.workspaceId !== null;
const isClosedWorktree = !isOpenWorkspace && workspace.worktreeId !== null;
const actionLabel = isBranch
? "Close workspace"
: isClosedWorktree
? "Delete worktree"
: "Delete workspace";
const actionLabel =
isBranch || isCloud
? "Close workspace"
: isClosedWorktree
? "Delete worktree"
: "Delete workspace";

// Can delete open workspaces or closed worktrees
const canDelete = isOpenWorkspace || isClosedWorktree;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export interface WorkspaceItem {
projectId: string;
projectName: string;
worktreePath: string;
type: "worktree" | "branch";
type: "worktree" | "branch" | "cloud";
branch: string;
name: string;
lastOpenedAt: number;
Expand Down
Loading