Skip to content

feat(cmdk): New CmdK action pattern and support Async actions#112015

Draft
rbro112 wants to merge 2 commits intomasterfrom
rbro112/cmdk-action-provider
Draft

feat(cmdk): New CmdK action pattern and support Async actions#112015
rbro112 wants to merge 2 commits intomasterfrom
rbro112/cmdk-action-provider

Conversation

@rbro112
Copy link
Copy Markdown
Member

@rbro112 rbro112 commented Apr 1, 2026

Adds a new action pattern for registering CmdK actions:

 // Static or simple async actions
<CmdKAction actions=[{...}] />
// Actions that require a managed async action
<CmdKAction
  queryOptions={() => {
    const baseOptions = apiOptions.as<ResponseType[]>()(path, {
      path: {...},
      query: {...},
      staleTime: 30_000,
    });
    return {
      ...baseOptions,
      select: raw => baseOptions.select(raw).map((target): CommandPaletteAction => ({
        to: target.to,
        display: {
          label: target.label,
          details: target.description,
          icon: <IconIssues />,
        },
      })
    };
  })}
  />

These are tracked centrally using a set of promises and a loading state replaces the search icon when any promise is still in flight. As promises resolve, they're removed from the set.

Additionally, I provide a grouping mechanism with CmdKActionProvider (not sold on this):

<CmdKActionProvider groupingKey="snapshots">
  <CmdKAction actions=[{ ...download snapshot images action }] />
  ...

  <SnapshotsUI ... />
</CmdKActionProvider>

This allows for dynamically generating scoped actions as part of specific contextual locations. This example above would generate a "snapshots" group of actions within the palette.

Adds two simple global actions leveraging this async pattern to globalActions.tsx - the existing DSN lookup action using our new pattern and a docs search action to search Sentry dev docs.

Copy link
Copy Markdown
Member Author

rbro112 commented Apr 1, 2026

This stack of pull requests is managed by Graphite. Learn more about stacking.

@github-actions github-actions bot added the Scope: Frontend Automatically applied to PRs that change frontend components label Apr 1, 2026
@rbro112 rbro112 changed the title New CmdK action pattern and support Async actions feat(cmdk): New CmdK action pattern and support Async actions Apr 1, 2026
* },
* ]}
*/
actions?: () => CommandPaletteAction[] | Promise<CommandPaletteAction[]>;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this need to be a function or can we simplify to CommandPaletteAction[] | Promise<CommandPaletteAction[]?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Had it as a function in case users wanted to make it more dynamic, but the promise itself could handle that. Will update

export type CommandPaletteDispatch = React.Dispatch<CommandPaletteAction>;
export type CommandPaletteDispatch = React.Dispatch<CommandPaletteStateAction>;

export type CommandPaletteAction =
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was getting confused between these actions and other command palette actions, so I think this rename is a small but important change

* <IssuesPage />
* </CmdKActionProvider>
*/
export function CmdKActionProvider({children, groupingKey}: CmdKActionProviderProps) {
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sold on this pattern in the current impl. CommonCommandPaletteAction is limited to a set of possible groupingKey strings ('search-result' | 'navigate' | 'add' | 'help').

My intention here is to be able to group actions by a "sub group" - basically any dynamic string. As a dev on size analysis and snapshots, the idea is to group our contextual actions into "Size Analysis" and "Snapshots" groups which would show in our palette as subheadings.

But this would require a bit of a refactor here to add a group?: string prop on CommonCommandPaletteAction and then render those titles/groups.

To start this seems fine with small scope and usage of this, but could explode if we have tons of teams adding groups. Also could get strange if we have nested groups or actions get grouped when actions are registered in potentially unexpected locations. Generally I almost lean to removing this entirely and potentially implementing in a future iteration once we have a better idea of usage

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Scope: Frontend Automatically applied to PRs that change frontend components

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants