Skip to content
Merged
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
Expand Up @@ -13,6 +13,7 @@ import {
import { toast } from "@superset/ui/sonner";
import { Tooltip, TooltipContent, TooltipTrigger } from "@superset/ui/tooltip";
import { cn } from "@superset/ui/utils";
import { memo, useCallback, useMemo } from "react";
import { HiChevronDown } from "react-icons/hi2";
import { LuCopy } from "react-icons/lu";
import jetbrainsIcon from "renderer/assets/app-icons/jetbrains.svg";
Expand All @@ -28,12 +29,18 @@ import { useHotkeyText } from "renderer/stores/hotkeys";

interface OpenInMenuButtonProps {
worktreePath: string;
branch?: string;
}

export function OpenInMenuButton({ worktreePath }: OpenInMenuButtonProps) {
export const OpenInMenuButton = memo(function OpenInMenuButton({
worktreePath,
branch,
}: OpenInMenuButtonProps) {
const utils = trpc.useUtils();
const { data: lastUsedApp = "cursor" } =
trpc.settings.getLastUsedApp.useQuery();
trpc.settings.getLastUsedApp.useQuery(undefined, {
staleTime: 30000,
});
const openInApp = trpc.external.openInApp.useMutation({
onSuccess: () => utils.settings.getLastUsedApp.invalidate(),
onError: (error) => toast.error(`Failed to open: ${error.message}`),
Expand All @@ -43,29 +50,30 @@ export function OpenInMenuButton({ worktreePath }: OpenInMenuButtonProps) {
onError: (error) => toast.error(`Failed to copy path: ${error.message}`),
});

const currentApp = getAppOption(lastUsedApp);
const currentApp = useMemo(() => getAppOption(lastUsedApp), [lastUsedApp]);
const openInShortcut = useHotkeyText("OPEN_IN_APP");
const copyPathShortcut = useHotkeyText("COPY_PATH");
const showOpenInShortcut = openInShortcut !== "Unassigned";
const showCopyPathShortcut = copyPathShortcut !== "Unassigned";
const isLoading = openInApp.isPending || copyPath.isPending;

const handleOpenInEditor = () => {
if (isLoading) return;
const handleOpenInEditor = useCallback(() => {
if (openInApp.isPending || copyPath.isPending) return;
openInApp.mutate({ path: worktreePath, app: lastUsedApp });
};
}, [worktreePath, lastUsedApp, openInApp, copyPath.isPending]);

const handleOpenInOtherApp = (appId: ExternalApp) => {
if (isLoading) return;
openInApp.mutate({ path: worktreePath, app: appId });
};
const handleOpenInOtherApp = useCallback(
(appId: ExternalApp) => {
if (openInApp.isPending || copyPath.isPending) return;
openInApp.mutate({ path: worktreePath, app: appId });
},
[worktreePath, openInApp, copyPath.isPending],
);

const handleCopyPath = () => {
if (isLoading) return;
const handleCopyPath = useCallback(() => {
if (openInApp.isPending || copyPath.isPending) return;
copyPath.mutate(worktreePath);
};

const BUTTON_HEIGHT = 24;
}, [worktreePath, copyPath, openInApp.isPending]);

return (
<div className="flex items-center no-drag">
Expand All @@ -76,34 +84,43 @@ export function OpenInMenuButton({ worktreePath }: OpenInMenuButtonProps) {
type="button"
onClick={handleOpenInEditor}
disabled={isLoading}
style={{ height: `${BUTTON_HEIGHT}px` }}
className={cn(
"flex items-center gap-1.5 pl-2 pr-1.5 rounded-l border border-r-0 border-foreground/20 bg-foreground/5 text-xs font-medium transition-colors",
"hover:bg-foreground/10 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-1",
isLoading && "opacity-50 cursor-not-allowed",
"group flex items-center gap-1.5 h-6 pl-1.5 pr-2 rounded-l border border-r-0 border-border/60 bg-secondary/50 text-xs font-medium",
"transition-all duration-150 ease-out",
"hover:bg-secondary hover:border-border",
"focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring",
"active:scale-[0.98]",
isLoading && "opacity-50 pointer-events-none",
)}
>
<img
src={currentApp.icon}
alt={currentApp.label}
alt=""
className="size-3.5 object-contain shrink-0"
/>
<span className="text-foreground">Open</span>
{branch && (
<span className="text-muted-foreground truncate max-w-[140px] tabular-nums">
/{branch}
</span>
)}
<span className="text-foreground font-medium">Open</span>
</button>
</TooltipTrigger>
<TooltipContent side="bottom" sideOffset={8} className="max-w-[300px]">
<TooltipContent side="bottom" sideOffset={6}>
<div className="flex flex-col gap-1">
<span className="flex items-center gap-1.5">
Open in {currentApp.displayLabel ?? currentApp.label}
{showOpenInShortcut && (
<kbd className="px-1.5 py-0.5 text-[10px] font-sans bg-foreground/10 rounded">
<kbd className="px-1 py-0.5 text-[10px] font-mono bg-foreground/10 text-foreground/70 rounded">
{openInShortcut}
</kbd>
)}
</span>
<span className="text-[10px] text-muted-foreground font-mono truncate">
{worktreePath}
</span>
{branch && (
<span className="text-xs text-muted-foreground font-mono">
/{branch}
</span>
)}
</div>
</TooltipContent>
</Tooltip>
Expand All @@ -114,26 +131,28 @@ export function OpenInMenuButton({ worktreePath }: OpenInMenuButtonProps) {
<button
type="button"
disabled={isLoading}
style={{ height: `${BUTTON_HEIGHT}px` }}
className={cn(
"flex items-center px-1.5 rounded-r border border-foreground/20 bg-foreground/5 text-foreground/60 transition-colors",
"hover:bg-foreground/10 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-1",
isLoading && "opacity-50 cursor-not-allowed",
"flex items-center justify-center h-6 w-6 rounded-r border border-border/60 bg-secondary/50 text-muted-foreground",
"transition-all duration-150 ease-out",
"hover:bg-secondary hover:border-border hover:text-foreground",
"focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring",
"active:scale-[0.98]",
isLoading && "opacity-50 pointer-events-none",
)}
>
<HiChevronDown className="size-3" />
<HiChevronDown className="size-3.5" />
</button>
</DropdownMenuTrigger>

<DropdownMenuContent align="end" className="w-52">
<DropdownMenuContent align="end" className="w-48">
{APP_OPTIONS.map((app) => (
<DropdownMenuItem
key={app.id}
onClick={() => handleOpenInOtherApp(app.id)}
>
<img
src={app.icon}
alt={app.label}
alt=""
className="size-4 object-contain mr-2"
/>
{app.label}
Expand All @@ -146,25 +165,27 @@ export function OpenInMenuButton({ worktreePath }: OpenInMenuButtonProps) {
<DropdownMenuSubTrigger>
<img
src={vscodeIcon}
alt="VS Code"
alt=""
className="size-4 object-contain mr-2"
/>
VS Code
</DropdownMenuSubTrigger>
<DropdownMenuSubContent className="w-44">
<DropdownMenuSubContent className="w-40">
{VSCODE_OPTIONS.map((app) => (
<DropdownMenuItem
key={app.id}
onClick={() => handleOpenInOtherApp(app.id)}
>
<img
src={app.icon}
alt={app.label}
alt=""
className="size-4 object-contain mr-2"
/>
{app.label}
{app.id === lastUsedApp && (
<DropdownMenuShortcut>⌘O</DropdownMenuShortcut>
{app.id === lastUsedApp && showOpenInShortcut && (
<DropdownMenuShortcut>
{openInShortcut}
</DropdownMenuShortcut>
)}
</DropdownMenuItem>
))}
Expand All @@ -174,20 +195,20 @@ export function OpenInMenuButton({ worktreePath }: OpenInMenuButtonProps) {
<DropdownMenuSubTrigger>
<img
src={jetbrainsIcon}
alt="JetBrains"
alt=""
className="size-4 object-contain mr-2"
/>
JetBrains
</DropdownMenuSubTrigger>
<DropdownMenuSubContent className="w-44">
<DropdownMenuSubContent className="w-40">
{JETBRAINS_OPTIONS.map((app) => (
<DropdownMenuItem
key={app.id}
onClick={() => handleOpenInOtherApp(app.id)}
>
<img
src={app.icon}
alt={app.label}
alt=""
className="size-4 object-contain mr-2"
/>
{app.label}
Expand All @@ -207,4 +228,4 @@ export function OpenInMenuButton({ worktreePath }: OpenInMenuButtonProps) {
</DropdownMenu>
</div>
);
}
});
Original file line number Diff line number Diff line change
@@ -1,21 +1,14 @@
import { OpenInMenuButton } from "./OpenInMenuButton";
import { ViewModeToggleCompact } from "./ViewModeToggleCompact";

interface WorkspaceControlsProps {
workspaceId: string | undefined;
worktreePath: string | undefined;
}

export function WorkspaceControls({
workspaceId,
worktreePath,
}: WorkspaceControlsProps) {
// Don't render if no active workspace with a worktree path
if (!workspaceId || !worktreePath) return null;
export function WorkspaceControls({ workspaceId }: WorkspaceControlsProps) {
if (!workspaceId) return null;

return (
<div className="flex items-center gap-2 no-drag">
<OpenInMenuButton worktreePath={worktreePath} />
<ViewModeToggleCompact workspaceId={workspaceId} />
</div>
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { trpc } from "renderer/lib/trpc";
import { AvatarDropdown } from "../AvatarDropdown";
import { WindowControls } from "./WindowControls";
import { OpenInMenuButton } from "./WorkspaceControls/OpenInMenuButton";
import { WorkspaceSidebarControl } from "./WorkspaceSidebarControl";

export function TopBar() {
Expand Down Expand Up @@ -31,6 +32,12 @@ export function TopBar() {
</div>

<div className="flex items-center gap-3 h-full pr-4 shrink-0">
{activeWorkspace?.worktreePath && (
<OpenInMenuButton
worktreePath={activeWorkspace.worktreePath}
branch={activeWorkspace.worktree?.branch}
/>
)}
<AvatarDropdown />
{!isMac && <WindowControls />}
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Button } from "@superset/ui/button";
import { toast } from "@superset/ui/sonner";
import { LuFolderPlus } from "react-icons/lu";
import { LuFolderOpen } from "react-icons/lu";
import { useOpenNew } from "renderer/react-query/projects";
import { useCreateBranchWorkspace } from "renderer/react-query/workspaces";

Expand Down Expand Up @@ -54,8 +54,8 @@ export function WorkspaceSidebarFooter() {
onClick={handleOpenNewProject}
disabled={openNew.isPending || createBranchWorkspace.isPending}
>
<LuFolderPlus className="w-4 h-4" />
<span>Add project</span>
<LuFolderOpen className="w-4 h-4" />
<span>Add repository</span>
</Button>
</div>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,7 @@ export function ContentView() {
const showGroupStrip = viewMode === "workbench";

const workspaceControls = (
<WorkspaceControls
workspaceId={activeWorkspace?.id}
worktreePath={activeWorkspace?.worktreePath}
/>
<WorkspaceControls workspaceId={activeWorkspace?.id} />
);

if (viewMode === "review") {
Expand Down
Loading