Skip to content

Commit c1ae7a3

Browse files
JonasBaclaudecodex
authored
ref(cmdk): Remove onAction prop in favor of internal action execution (#112648)
Removes the onAction prop from commandPalette which was requiring us to redefine the test and prod logic and diminishing the value of our tests. With this change, the action.onAction or action.to are invoked internally by the command palette. --------- Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com> Co-authored-by: OpenAI Codex <noreply@openai.com>
1 parent cf3618d commit c1ae7a3

File tree

8 files changed

+116
-220
lines changed

8 files changed

+116
-220
lines changed
Lines changed: 5 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,11 @@
1-
import {useCallback} from 'react';
2-
31
import {addSuccessMessage} from 'sentry/actionCreators/indicator';
4-
import {CommandPaletteProvider} from 'sentry/components/commandPalette/ui/cmdk';
5-
import {CMDKAction} from 'sentry/components/commandPalette/ui/cmdk';
6-
import type {CMDKActionData} from 'sentry/components/commandPalette/ui/cmdk';
7-
import type {CollectionTreeNode} from 'sentry/components/commandPalette/ui/collection';
2+
import {
3+
CMDKAction,
4+
CommandPaletteProvider,
5+
} from 'sentry/components/commandPalette/ui/cmdk';
86
import {CommandPalette} from 'sentry/components/commandPalette/ui/commandPalette';
9-
import {normalizeUrl} from 'sentry/utils/url/normalizeUrl';
10-
import {useNavigate} from 'sentry/utils/useNavigate';
117

128
export function CommandPaletteDemo() {
13-
const navigate = useNavigate();
14-
15-
const handleAction = useCallback(
16-
(
17-
action: CollectionTreeNode<CMDKActionData>,
18-
_options?: {modifierKeys?: {shiftKey: boolean}}
19-
) => {
20-
if ('to' in action) {
21-
navigate(normalizeUrl(action.to));
22-
} else if ('onAction' in action) {
23-
action.onAction();
24-
}
25-
},
26-
[navigate]
27-
);
28-
299
return (
3010
<CommandPaletteProvider>
3111
<CMDKAction display={{label: 'Go to Flex story'}} to="/stories/layout/flex/" />
@@ -49,7 +29,7 @@ export function CommandPaletteDemo() {
4929
onAction={() => addSuccessMessage('Deselect all')}
5030
/>
5131
</CMDKAction>
52-
<CommandPalette onAction={handleAction} />
32+
<CommandPalette />
5333
</CommandPaletteProvider>
5434
);
5535
}

static/app/components/commandPalette/ui/cmdk.tsx

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,6 @@ export const CMDKCollection = makeCollection<CMDKActionData>();
5050
/**
5151
* Root provider for the command palette. Wrap the component tree that
5252
* contains CMDKAction registrations and the CommandPalette UI.
53-
*
54-
* Slot outlets are rendered separately in the navigation (see
55-
* CommandPaletteSlotOutlets in navigation/index.tsx) in task → page → global
56-
* DOM order so that presortBySlotRef's compareDocumentPosition sorting works
57-
* correctly. Keeping the outlets in the navigation (rather than here) means
58-
* this provider introduces no DOM nodes — tests that assert an empty container
59-
* are unaffected.
6053
*/
6154
export function CommandPaletteProvider({children}: {children: React.ReactNode}) {
6255
return (

0 commit comments

Comments
 (0)