feat(ui): add global command palette (Ctrl+K) for fast navigation and search (#6352)

* feat(ui): add global command palette (Ctrl+K) for fast navigation and search

* fix(ui): address review feedback for shortcut listener, i18n parity, and search deep links

* fix(ui): resolve search routing, translation keys, and palette state reset

* fix(ui): improve command palette styling and sidebar transitions

* fix(ui): address review feedback for typecheck, codegen, debouncing, and state reset

* fix(ui): resolve effect state update warning and debounce reset in command palette

* fix(ui): address review feedback for stale client search results and theme action

* style(ui): apply oxfmt formatting to command palette and tests

* fix(deps): update js-yaml override to resolve audit advisory

* docs(api): sync the docs OpenAPI copy with the new InboundOption fields

Adding Network/Security to InboundOption regenerated
frontend/public/openapi.json, but docs/public/openapi.json is a
hand-kept copy of that file and nothing checks it: make verify never
reaches docs/, and docs-ci.yml fires only on docs/**. The two files were
byte-identical on main and had diverged here, so the published API
reference described a response shape the panel no longer returns.

Regenerating the MDX under docs/content/docs/en/reference/api/ produced
no change — the schema is read from the JSON at render time.

* fix(ui): unnest the command palette row control and label its shortcut

The palette row was a <button> wrapping the copy-subscription <button>.
Nested interactive content is invalid HTML and React 19 logs two errors
for it on every client result. The row is now a role="button" div using
activateOnKey, the pattern the rest of the panel already uses, with
line-height pinned so dropping the UA button style does not grow every
row. Its keydown handler ignores events bubbling from the nested button:
activateOnKey preventDefaults Enter, which would otherwise cancel the
browser's Enter-to-click on the copy button and navigate instead.

The sidebar chip hardcoded the Mac glyph while the handler accepts Ctrl
as well, so Linux and Windows operators were shown a key they do not
have; it now picks the modifier from the platform.

Also restores the comment on ClientsPage's debouncedSearch that the
deep-link change removed — the code it explains is unchanged.
This commit is contained in:
MRVX
2026-09-10 19:23:49 +03:30
committed by GitHub
parent 2dd903ea8e
commit fc08b53395
30 changed files with 2140 additions and 4 deletions
+50 -1
View File
@@ -2,7 +2,7 @@ import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
import type { ComponentType, CSSProperties } from 'react';
import { useLocation, useNavigate } from 'react-router';
import { useTranslation } from 'react-i18next';
import { Drawer, Layout, Menu } from 'antd';
import { Drawer, Layout, Menu, Tooltip } from 'antd';
import type { MenuProps } from 'antd';
import {
ApiOutlined,
@@ -28,6 +28,7 @@ import {
PushpinOutlined,
ReadOutlined,
SafetyOutlined,
SearchOutlined,
SettingOutlined,
SunOutlined,
SwapOutlined,
@@ -40,9 +41,13 @@ import { HttpUtil } from '@/utils';
import { formatPanelVersion } from '@/lib/panel-version';
import { pauseAnimationsUntilLeave, useTheme } from '@/hooks/useTheme';
import { useAllSettings } from '@/api/queries/useAllSettings';
import { useCommandPalette } from '@/components/command-palette/useCommandPalette';
import './AppSidebar.css';
const DONATE_URL = 'https://donate.sanaei.dev/';
// The palette listens for Ctrl as well as Cmd, so the chip must not show a
// Mac glyph to the Linux and Windows operators who are most of this panel's.
const SHORTCUT_MODIFIER = /Mac|iPhone|iPad|iPod/.test(navigator.userAgent) ? '⌘' : 'Ctrl';
const DOCS_URL = 'https://docs.sanaei.dev/';
const REPO_URL = 'https://github.com/MHSanaei/3x-ui';
const LOGOUT_KEY = '__logout__';
@@ -174,6 +179,7 @@ function saveSidebarPinned(pinned: boolean) {
export default function AppSidebar() {
const { t } = useTranslation();
const { isDark, isUltra, toggleTheme, toggleUltra } = useTheme();
const { open: openCommandPalette } = useCommandPalette();
const navigate = useNavigate();
const { pathname, hash } = useLocation();
const { allSetting } = useAllSettings();
@@ -392,6 +398,30 @@ export default function AppSidebar() {
</div>
)}
</div>
<Tooltip
title={
railCollapsed ? t('commandPalette.title') || 'Command Palette (Ctrl + K)' : undefined
}
placement="right"
>
<button
type="button"
className={`sidebar-command-trigger${railCollapsed ? ' collapsed' : ''}`}
onClick={openCommandPalette}
aria-label={t('commandPalette.title') || 'Command Palette (Ctrl + K)'}
>
<span className="sidebar-command-left">
<SearchOutlined className="sidebar-command-icon" />
<span className="sidebar-command-text">
{t('commandPalette.search') || 'Search...'}
</span>
</span>
<span className="sidebar-command-kbd">
<span className="kbd-cmd">{SHORTCUT_MODIFIER}</span>
<span className="kbd-key">K</span>
</span>
</button>
</Tooltip>
<Menu
theme={currentTheme}
mode="inline"
@@ -452,6 +482,25 @@ export default function AppSidebar() {
</button>
</div>
</div>
<button
type="button"
className="sidebar-command-trigger"
onClick={() => {
setDrawerOpen(false);
openCommandPalette();
}}
aria-label={t('commandPalette.title') || 'Command Palette (Ctrl + K)'}
style={{ margin: '8px 12px 4px', width: 'calc(100% - 24px)' }}
>
<span style={{ display: 'flex', alignItems: 'center', gap: 8 }}>
<SearchOutlined className="sidebar-command-icon" />
<span>{t('commandPalette.search') || 'Search...'}</span>
</span>
<span className="sidebar-command-kbd">
<span className="kbd-cmd">{SHORTCUT_MODIFIER}</span>
<span className="kbd-key">K</span>
</span>
</button>
<Menu
theme={currentTheme}
mode="inline"
+7 -1
View File
@@ -2,9 +2,15 @@ import { Outlet } from 'react-router';
import { useWebSocketBridge } from '@/api/websocketBridge';
import { usePageTitle } from '@/hooks/usePageTitle';
import CommandPalette from '@/components/command-palette/CommandPalette';
export default function PanelLayout() {
useWebSocketBridge();
usePageTitle();
return <Outlet />;
return (
<>
<Outlet />
<CommandPalette />
</>
);
}