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
@@ -1,22 +1,14 @@
import { Input } from "@superset/ui/input";
import { Kbd, KbdGroup } from "@superset/ui/kbd";
import { useMemo, useState } from "react";
import { useState } from "react";
import { HiMagnifyingGlass } from "react-icons/hi2";
import {
formatKeysForDisplay,
getHotkeysByCategory,
HOTKEYS,
type HotkeyCategory,
type HotkeyDefinition,
type HotkeyWithDisplay,
} from "shared/hotkeys";

function useIsMac(): boolean {
return useMemo(() => {
const platform = navigator.platform?.toUpperCase() ?? "";
const userAgent = navigator.userAgent?.toUpperCase() ?? "";
return platform.includes("MAC") || userAgent.includes("MAC");
}, []);
}

const CATEGORY_ORDER: HotkeyCategory[] = [
"Workspace",
"Terminal",
Expand All @@ -29,11 +21,9 @@ function HotkeyRow({
hotkey,
isEven,
}: {
hotkey: HotkeyDefinition;
hotkey: HotkeyWithDisplay;
isEven: boolean;
}) {
const keys = formatKeysForDisplay(hotkey.keys);

return (
<div
className={`flex items-center justify-between py-3 px-4 ${
Expand All @@ -42,7 +32,7 @@ function HotkeyRow({
>
<span className="text-sm text-foreground">{hotkey.label}</span>
<KbdGroup>
{keys.map((key) => (
{hotkey.display.map((key) => (
<Kbd key={key}>{key}</Kbd>
))}
</KbdGroup>
Expand All @@ -54,8 +44,8 @@ function HotkeyRow({
* Consolidate individual workspace jump shortcuts (1-9) into a single entry
*/
function consolidateWorkspaceJumps(
hotkeys: HotkeyDefinition[],
): HotkeyDefinition[] {
hotkeys: HotkeyWithDisplay[],
): HotkeyWithDisplay[] {
const workspaceJumpPattern = /^Switch to Workspace \d$/;
const hasWorkspaceJumps = hotkeys.some((h) =>
workspaceJumpPattern.test(h.label),
Expand All @@ -64,10 +54,13 @@ function consolidateWorkspaceJumps(
if (!hasWorkspaceJumps) return hotkeys;

const filtered = hotkeys.filter((h) => !workspaceJumpPattern.test(h.label));
// Reuse the meta key symbol from an existing hotkey's display
const [metaKey] = HOTKEYS.JUMP_TO_WORKSPACE_1.display;
filtered.unshift({
keys: "meta+1-9",
label: "Switch to Workspace 1-9",
category: "Workspace",
display: [metaKey, "1-9"],
});

return filtered;
Expand All @@ -76,8 +69,8 @@ function consolidateWorkspaceJumps(
export function KeyboardShortcutsSettings() {
const [searchQuery, setSearchQuery] = useState("");
const hotkeysByCategory = getHotkeysByCategory();
const isMac = useIsMac();
const modifierKey = isMac ? "⌘" : "Ctrl";
// Reuse the meta key symbol from SHOW_HOTKEYS display
const [modifierKey] = HOTKEYS.SHOW_HOTKEYS.display;

// Flatten and consolidate all hotkeys
const allHotkeys = CATEGORY_ORDER.flatMap((category) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,10 @@ import {
} from "react-icons/hi2";
import { useOpenSettings } from "renderer/stores";
import { HELP_MENU } from "shared/constants";
import { formatKeysForDisplay, HOTKEYS } from "shared/hotkeys";
import { HOTKEYS } from "shared/hotkeys";

export function HelpMenu() {
const openSettings = useOpenSettings();
const hotkeyKeys = formatKeysForDisplay(HOTKEYS.SHOW_HOTKEYS.keys);

const handleContactUs = () => {
window.open(HELP_MENU.CONTACT_URL, "_blank");
Expand Down Expand Up @@ -74,7 +73,7 @@ export function HelpMenu() {
<HiOutlineCommandLine className="h-4 w-4" />
<span className="flex-1">Keyboard Shortcuts</span>
<KbdGroup>
{hotkeyKeys.map((key) => (
{HOTKEYS.SHOW_HOTKEYS.display.map((key) => (
<Kbd key={key}>{key}</Kbd>
))}
</KbdGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@ import { Kbd, KbdGroup } from "@superset/ui/kbd";
import { Tooltip, TooltipContent, TooltipTrigger } from "@superset/ui/tooltip";
import { HiOutlineCog6Tooth } from "react-icons/hi2";
import { useOpenSettings } from "renderer/stores";
import { formatKeysForDisplay, HOTKEYS } from "shared/hotkeys";
import { HOTKEYS } from "shared/hotkeys";

export function SettingsButton() {
const openSettings = useOpenSettings();
const keys = formatKeysForDisplay(HOTKEYS.SHOW_HOTKEYS.keys);

return (
<Tooltip>
Expand All @@ -24,7 +23,7 @@ export function SettingsButton() {
<span className="flex items-center gap-2">
Settings
<KbdGroup>
{keys.map((key) => (
{HOTKEYS.SHOW_HOTKEYS.display.map((key) => (
<Kbd key={key}>{key}</Kbd>
))}
</KbdGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@ import { Kbd, KbdGroup } from "@superset/ui/kbd";
import { Tooltip, TooltipContent, TooltipTrigger } from "@superset/ui/tooltip";
import { HiMiniBars3, HiMiniBars3BottomLeft } from "react-icons/hi2";
import { useSidebarStore } from "renderer/stores";
import { formatKeysForDisplay, HOTKEYS } from "shared/hotkeys";
import { HOTKEYS } from "shared/hotkeys";

export function SidebarControl() {
const { isSidebarOpen, toggleSidebar } = useSidebarStore();
const keys = formatKeysForDisplay(HOTKEYS.TOGGLE_SIDEBAR.keys);

return (
<Tooltip>
Expand All @@ -30,7 +29,7 @@ export function SidebarControl() {
<span className="flex items-center gap-2">
Toggle sidebar
<KbdGroup>
{keys.map((key) => (
{HOTKEYS.TOGGLE_SIDEBAR.display.map((key) => (
<Kbd key={key}>{key}</Kbd>
))}
</KbdGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Kbd, KbdGroup } from "@superset/ui/kbd";
import { HiMiniCommandLine } from "react-icons/hi2";
import { formatKeysForDisplay, HOTKEYS } from "shared/hotkeys";
import { HOTKEYS } from "shared/hotkeys";

const shortcuts = [HOTKEYS.NEW_TERMINAL, HOTKEYS.OPEN_IN_APP];

Expand All @@ -17,7 +17,7 @@ export function EmptyTabView() {
{shortcuts.map((shortcut) => (
<div key={shortcut.label} className="flex items-center gap-2">
<KbdGroup>
{formatKeysForDisplay(shortcut.keys).map((key) => (
{shortcut.display.map((key) => (
<Kbd key={key}>{key}</Kbd>
))}
</KbdGroup>
Expand Down
Loading