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
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
import {
CommandDialog,
CommandEmpty,
CommandGroup,
CommandInput,
CommandItem,
CommandList,
CommandShortcut,
} from "@superset/ui/command";
import { electronTrpc } from "renderer/lib/electron-trpc";
import { useHotkeyText } from "renderer/stores/hotkeys";
import type { HotkeyId } from "shared/hotkeys";
import {
actionsCommands,
contextualCommands,
navigationCommands,
type WorkspaceItem,
workspacesCommands,
} from "./generators";
import { useCommandActions } from "./hooks/useCommandActions";
import { useCommandContext } from "./hooks/useCommandContext";
import type { Command, CommandGroup as CommandGroupType } from "./types";

interface CommandMenuProps {
isOpen: boolean;
onOpenChange: (open: boolean) => void;
}

function HotkeyShortcut({ hotkeyId }: { hotkeyId: HotkeyId }) {
const hotkeyText = useHotkeyText(hotkeyId);
if (hotkeyText === "Unassigned") return null;
return <CommandShortcut>{hotkeyText}</CommandShortcut>;
}

function CommandItemContent({ command }: { command: Command }) {
return (
<>
<span>{command.label}</span>
{command.hotkeyId && <HotkeyShortcut hotkeyId={command.hotkeyId} />}
</>
);
}

export function CommandMenu({ isOpen, onOpenChange }: CommandMenuProps) {
const ctx = useCommandContext();
const { executeCommand } = useCommandActions(ctx, () => onOpenChange(false));

// Fetch workspaces for the workspace list
const { data: workspaceGroups } =
electronTrpc.workspaces.getAllGrouped.useQuery();
const allWorkspaces: WorkspaceItem[] =
workspaceGroups?.flatMap((g) =>
g.workspaces.map((ws) => ({
id: ws.id,
name: ws.name,
branch: ws.branch,
})),
) ?? [];

// Generate all command groups
const groups: CommandGroupType[] = [
contextualCommands(ctx),
workspacesCommands(ctx, allWorkspaces),
actionsCommands(ctx),
navigationCommands(ctx),
].filter((g): g is CommandGroupType => g !== null);

const handleSelect = (commandId: string) => {
executeCommand(commandId);
};

return (
<CommandDialog
open={isOpen}
onOpenChange={onOpenChange}
title="Command Menu"
description="Search for commands and workspaces"
showCloseButton={false}
>
<CommandInput placeholder="Type a command or search..." />
<CommandList>
<CommandEmpty>No results found.</CommandEmpty>
{groups.map((group) => (
<CommandGroup key={group.displayName} heading={group.displayName}>
{group.commands.map((command) => (
<CommandItem
key={command.id}
value={command.id}
keywords={command.keywords}
onSelect={handleSelect}
>
<CommandItemContent command={command} />
</CommandItem>
))}
</CommandGroup>
))}
</CommandList>
</CommandDialog>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
import type { HotkeyId } from "shared/hotkeys";
import type {
CommandContext,
CommandGroup,
CommandGroupGenerator,
} from "./types";

export interface WorkspaceItem {
id: string;
name: string;
branch: string;
}

const WORKSPACE_HOTKEY_IDS: HotkeyId[] = [
"JUMP_TO_WORKSPACE_1",
"JUMP_TO_WORKSPACE_2",
"JUMP_TO_WORKSPACE_3",
"JUMP_TO_WORKSPACE_4",
"JUMP_TO_WORKSPACE_5",
"JUMP_TO_WORKSPACE_6",
"JUMP_TO_WORKSPACE_7",
"JUMP_TO_WORKSPACE_8",
"JUMP_TO_WORKSPACE_9",
];

// Only shown when in a workspace
export const contextualCommands: CommandGroupGenerator = (ctx) => {
if (!ctx.isInWorkspace) return null;

return {
displayName: "Workspace Actions",
commands: [
{
id: "close-workspace",
label: `Close ${ctx.workspaceName || "Workspace"}`,
},
{
id: "workspace-settings",
label: `${ctx.workspaceName || "Workspace"} Settings`,
},
{
id: "new-terminal-tab",
label: "New Terminal Tab",
hotkeyId: "NEW_GROUP",
},
{
id: "split-pane-right",
label: "Split Pane Right",
hotkeyId: "SPLIT_RIGHT",
},
{
id: "split-pane-down",
label: "Split Pane Down",
hotkeyId: "SPLIT_DOWN",
},
{
id: "clear-terminal",
label: "Clear Terminal",
hotkeyId: "CLEAR_TERMINAL",
},
],
};
};

// Dynamic workspace list (requires workspace data)
export const workspacesCommands = (
_ctx: CommandContext,
workspaces: WorkspaceItem[],
): CommandGroup | null => {
if (workspaces.length === 0) return null;

return {
displayName: "Workspaces",
commands: workspaces.map((ws, index) => ({
id: `switch-workspace-${ws.id}`,
label: ws.name || ws.branch,
keywords: [ws.branch, ws.name].filter(Boolean),
hotkeyId: index < 9 ? WORKSPACE_HOTKEY_IDS[index] : undefined,
})),
};
};

// Always shown
export const actionsCommands: CommandGroupGenerator = () => ({
displayName: "Actions",
commands: [
{ id: "new-workspace", label: "New Workspace", hotkeyId: "NEW_WORKSPACE" },
{
id: "quick-create-workspace",
label: "Quick Create Workspace",
hotkeyId: "QUICK_CREATE_WORKSPACE",
},
{
id: "open-project",
label: "Open Project",
keywords: ["folder", "repo"],
hotkeyId: "OPEN_PROJECT",
},
{
id: "change-theme",
label: "Change Theme",
keywords: ["dark", "light", "mode", "toggle"],
},
{
id: "toggle-workspace-sidebar",
label: "Toggle Sidebar",
hotkeyId: "TOGGLE_WORKSPACE_SIDEBAR",
},
],
});

// Always shown
export const navigationCommands: CommandGroupGenerator = () => ({
displayName: "Navigation",
commands: [
{
id: "settings-appearance",
label: "Appearance Settings",
keywords: ["theme"],
},
{
id: "settings-keyboard",
label: "Keyboard Shortcuts",
hotkeyId: "SHOW_HOTKEYS",
},
{
id: "settings-terminal",
label: "Terminal Settings",
keywords: ["shell", "presets"],
},
{
id: "settings-integrations",
label: "Integrations",
keywords: ["github"],
},
{
id: "contact-us",
label: "Contact Us",
keywords: ["support", "feedback"],
},
{
id: "join-discord",
label: "Join Discord",
keywords: ["community"],
},
{
id: "check-updates",
label: "Check for Updates",
},
],
});
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { useCommandActions } from "./useCommandActions";
Loading