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 @@ -107,6 +107,7 @@ export function DashboardSidebarWorkspaceItem({
diffStats={diffStats}
/>
}
isLocalWorkspace={hostType === "local-device"}
onCreateSection={handleCreateSection}
onMoveToSection={(targetSectionId) =>
moveWorkspaceToSection(id, projectId, targetSectionId)
Expand Down Expand Up @@ -172,6 +173,7 @@ export function DashboardSidebarWorkspaceItem({
onMoveToSection={(targetSectionId) =>
moveWorkspaceToSection(id, projectId, targetSectionId)
}
isLocalWorkspace={hostType === "local-device"}
onOpenInFinder={handleOpenInFinder}
onCopyPath={handleCopyPath}
onRemoveFromSidebar={() => removeWorkspaceFromSidebar(id)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ interface DashboardSidebarWorkspaceContextMenuProps {
hoverCardContent?: React.ReactNode;
projectId: string;
isInSection?: boolean;
isLocalWorkspace: boolean;
onHoverCardOpen?: () => void;
onCreateSection: () => void;
onMoveToSection: (sectionId: string | null) => void;
Expand All @@ -46,6 +47,7 @@ interface DashboardSidebarWorkspaceContextMenuProps {
export function DashboardSidebarWorkspaceContextMenu({
projectId,
isInSection,
isLocalWorkspace,
onHoverCardOpen,
hoverCardContent,
onCreateSection,
Expand Down Expand Up @@ -81,15 +83,19 @@ export function DashboardSidebarWorkspaceContextMenu({
<LuPencil className="size-4 mr-2" />
Rename
</ContextMenuItem>
<ContextMenuSeparator />
<ContextMenuItem onSelect={onOpenInFinder}>
<LuFolderOpen className="size-4 mr-2" />
Open in Finder
</ContextMenuItem>
<ContextMenuItem onSelect={onCopyPath}>
<LuCopy className="size-4 mr-2" />
Copy Path
</ContextMenuItem>
{isLocalWorkspace && (
<>
<ContextMenuSeparator />
<ContextMenuItem onSelect={onOpenInFinder}>
<LuFolderOpen className="size-4 mr-2" />
Open in Finder
</ContextMenuItem>
<ContextMenuItem onSelect={onCopyPath}>
<LuCopy className="size-4 mr-2" />
Copy Path
</ContextMenuItem>
</>
)}
<ContextMenuSeparator />
<ContextMenuSub>
<ContextMenuSubTrigger>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
import { toast } from "@superset/ui/sonner";
import { useMatchRoute, useNavigate } from "@tanstack/react-router";
import { useState } from "react";
import { useCopyToClipboard } from "renderer/hooks/useCopyToClipboard";
import { apiTrpcClient } from "renderer/lib/api-trpc-client";
import { getHostServiceClientByUrl } from "renderer/lib/host-service-client";
import { electronTrpcClient } from "renderer/lib/trpc-client";
import { getDeleteFocusTargetWorkspaceId } from "renderer/routes/_authenticated/_dashboard/components/DashboardSidebar/utils/getDeleteFocusTargetWorkspaceId";
import { getFlattenedV2WorkspaceIds } from "renderer/routes/_authenticated/_dashboard/components/DashboardSidebar/utils/getFlattenedV2WorkspaceIds";
import { navigateToV2Workspace } from "renderer/routes/_authenticated/_dashboard/utils/workspace-navigation";
import { useDashboardSidebarState } from "renderer/routes/_authenticated/hooks/useDashboardSidebarState";
import { useCollections } from "renderer/routes/_authenticated/providers/CollectionsProvider";
import { useLocalHostService } from "renderer/routes/_authenticated/providers/LocalHostServiceProvider";

interface UseDashboardSidebarWorkspaceItemActionsOptions {
workspaceId: string;
Expand All @@ -22,6 +26,8 @@ export function useDashboardSidebarWorkspaceItemActions({
const navigate = useNavigate();
const matchRoute = useMatchRoute();
const collections = useCollections();
const { activeHostUrl } = useLocalHostService();
Comment thread
cubic-dev-ai[bot] marked this conversation as resolved.
const { copyToClipboard } = useCopyToClipboard();
const { createSection, moveWorkspaceToSection, removeWorkspaceFromSidebar } =
useDashboardSidebarState();

Expand Down Expand Up @@ -106,12 +112,44 @@ export function useDashboardSidebarWorkspaceItemActions({
moveWorkspaceToSection(workspaceId, projectId, newSectionId);
};

const handleOpenInFinder = () => {
toast.info("Open in Finder is coming soon");
const resolveWorktreePath = async (): Promise<string | null> => {
if (!activeHostUrl) {
toast.error("Host service is not available");
return null;
}
const workspace = await getHostServiceClientByUrl(
activeHostUrl,
).workspace.get.query({ id: workspaceId });
if (!workspace?.worktreePath) {
toast.error("Workspace path is not available");
return null;
}
return workspace.worktreePath;
};

const handleOpenInFinder = async () => {
try {
const path = await resolveWorktreePath();
if (!path) return;
await electronTrpcClient.external.openInFinder.mutate(path);
} catch (error) {
toast.error(
`Failed to open in Finder: ${error instanceof Error ? error.message : "Unknown error"}`,
);
}
};

const handleCopyPath = () => {
toast.info("Copy Path is coming soon");
const handleCopyPath = async () => {
try {
const path = await resolveWorktreePath();
if (!path) return;
await copyToClipboard(path);
toast.success("Path copied");
} catch (error) {
toast.error(
`Failed to copy path: ${error instanceof Error ? error.message : "Unknown error"}`,
);
}
};

return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ import {
ContextMenuItem,
ContextMenuSeparator,
} from "@superset/ui/context-menu";
import { toast } from "@superset/ui/sonner";
import { electronTrpcClient } from "renderer/lib/trpc-client";
import { PathActionsMenuItems } from "../PathActionsMenuItems";

interface FileContextMenuProps {
absolutePath: string;
Expand All @@ -23,32 +22,10 @@ export function FileContextMenu({
<ContextMenuContent className="w-56">
<ContextMenuItem>Open to the Side</ContextMenuItem>
<ContextMenuSeparator />
<ContextMenuItem
onSelect={() =>
electronTrpcClient.external.openInFinder.mutate(absolutePath)
}
>
Reveal in Finder
</ContextMenuItem>
<ContextMenuSeparator />
<ContextMenuItem
onSelect={() => {
navigator.clipboard.writeText(absolutePath);
toast.success("Path copied");
}}
>
Copy Path
</ContextMenuItem>
{relativePath && (
<ContextMenuItem
onSelect={() => {
navigator.clipboard.writeText(relativePath);
toast.success("Relative path copied");
}}
>
Copy Relative Path
</ContextMenuItem>
)}
<PathActionsMenuItems
absolutePath={absolutePath}
relativePath={relativePath}
/>
<ContextMenuSeparator />
<ContextMenuItem onSelect={() => setTimeout(onRename, 0)}>
Rename...
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ import {
ContextMenuItem,
ContextMenuSeparator,
} from "@superset/ui/context-menu";
import { toast } from "@superset/ui/sonner";
import { electronTrpcClient } from "renderer/lib/trpc-client";
import { PathActionsMenuItems } from "../PathActionsMenuItems";

interface FolderContextMenuProps {
absolutePath: string;
Expand Down Expand Up @@ -32,32 +31,10 @@ export function FolderContextMenu({
New Folder...
</ContextMenuItem>
<ContextMenuSeparator />
<ContextMenuItem
onSelect={() =>
electronTrpcClient.external.openInFinder.mutate(absolutePath)
}
>
Reveal in Finder
</ContextMenuItem>
<ContextMenuSeparator />
<ContextMenuItem
onSelect={() => {
navigator.clipboard.writeText(absolutePath);
toast.success("Path copied");
}}
>
Copy Path
</ContextMenuItem>
{relativePath && (
<ContextMenuItem
onSelect={() => {
navigator.clipboard.writeText(relativePath);
toast.success("Relative path copied");
}}
>
Copy Relative Path
</ContextMenuItem>
)}
<PathActionsMenuItems
absolutePath={absolutePath}
relativePath={relativePath}
/>
<ContextMenuSeparator />
<ContextMenuItem onSelect={() => setTimeout(onRename, 0)}>
Rename...
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import {
ContextMenuItem,
ContextMenuSeparator,
} from "@superset/ui/context-menu";
import { toast } from "@superset/ui/sonner";
import { useCopyToClipboard } from "renderer/hooks/useCopyToClipboard";
import { electronTrpcClient } from "renderer/lib/trpc-client";

interface PathActionsMenuItemsProps {
absolutePath: string;
relativePath?: string;
}

export function PathActionsMenuItems({
absolutePath,
relativePath,
}: PathActionsMenuItemsProps) {
const { copyToClipboard } = useCopyToClipboard();

const handleCopy = async (path: string, successMessage: string) => {
try {
await copyToClipboard(path);
toast.success(successMessage);
} catch (error) {
toast.error(
`Failed to copy path: ${error instanceof Error ? error.message : "Unknown error"}`,
);
}
};

const handleRevealInFinder = async () => {
try {
await electronTrpcClient.external.openInFinder.mutate(absolutePath);
} catch (error) {
toast.error(
`Failed to reveal in Finder: ${error instanceof Error ? error.message : "Unknown error"}`,
);
}
};

return (
<>
<ContextMenuItem onSelect={handleRevealInFinder}>
Reveal in Finder
</ContextMenuItem>
<ContextMenuSeparator />
<ContextMenuItem onSelect={() => handleCopy(absolutePath, "Path copied")}>
Copy Path
</ContextMenuItem>
{relativePath && (
<ContextMenuItem
onSelect={() => handleCopy(relativePath, "Relative path copied")}
>
Copy Relative Path
</ContextMenuItem>
)}
</>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { PathActionsMenuItems } from "./PathActionsMenuItems";
Loading