Skip to content

Commit 995a998

Browse files
committed
Remove second comand palette provider file
1 parent c53481f commit 995a998

File tree

3 files changed

+25
-68
lines changed

3 files changed

+25
-68
lines changed

src/command-pallette/CommandPaletteProvider.tsx

Lines changed: 0 additions & 64 deletions
This file was deleted.

src/command-pallette/CommandPalletteUI/CommandPaletteSearchBar.tsx

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { useTranslation } from 'react-i18next';
33
import { createPortal } from 'react-dom';
44
import { Icon, Input } from '@ui5/webcomponents-react';
55
import { K8sResource } from 'types';
6+
import { useEventListener } from 'hooks/useEventListener';
67
import { useObjectState } from 'shared/useObjectState';
78
import { CommandPaletteUI } from './CommandPaletteUI';
89
import { useRecoilValue } from 'recoil';
@@ -44,6 +45,29 @@ export function CommandPaletteSearchBar({
4445
}
4546
};
4647

48+
const onKeyPress = (e: Event) => {
49+
const { key, metaKey, ctrlKey } = e as KeyboardEvent;
50+
// for (Edge, Chrome) || (Firefox, Safari)
51+
const isMac = (
52+
(navigator as any).userAgentData?.platform || navigator.platform
53+
)
54+
?.toLowerCase()
55+
?.startsWith('mac');
56+
const modifierKeyPressed = (isMac && metaKey) || (!isMac && ctrlKey);
57+
58+
if (
59+
(key === 'k' || key === 'K') &&
60+
modifierKeyPressed &&
61+
window.location.pathname !== '/clusters'
62+
) {
63+
setShowDialog(!shouldShowDialog);
64+
// [on Firefox] prevent opening the browser search bar via CMD/CTRL+K
65+
e.preventDefault();
66+
}
67+
};
68+
69+
useEventListener('keydown', onKeyPress, [shouldShowDialog]);
70+
4771
useEffect(() => {
4872
setShellbarWidth(
4973
showCompanion.show

src/index.tsx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import { savePreviousPath } from 'state/useAfterInitHook';
99

1010
import App from './components/App/App';
1111
import { Spinner } from 'shared/components/Spinner/Spinner';
12-
import { CommandPaletteProvider } from 'command-pallette/CommandPaletteProvider';
1312
import { NotificationProvider } from 'shared/contexts/NotificationContext';
1413

1514
import { ThemeProvider } from '@ui5/webcomponents-react';
@@ -65,9 +64,7 @@ root.render(
6564
<BrowserRouter>
6665
<Suspense fallback={<Spinner />}>
6766
<NotificationProvider>
68-
<CommandPaletteProvider>
69-
<App />
70-
</CommandPaletteProvider>
67+
<App />
7168
</NotificationProvider>
7269
</Suspense>
7370
</BrowserRouter>

0 commit comments

Comments
 (0)