Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Fix command palette shortcuts #1245

Merged
merged 6 commits into from
Aug 5, 2024
Merged
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
17 changes: 11 additions & 6 deletions assets/src/components/commandpalette/CommandHotkeys.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
import { useHotkeys } from '@saas-ui/use-hotkeys'

import { CommandWithHotkeys } from './commands'
import { UseHotkeysOptions, useHotkeys } from '@saas-ui/use-hotkeys'
import merge from 'lodash/merge'

export default function CommandHotkeys({
command,
hotkeys,
callback,
options,
deps,
}: {
command: CommandWithHotkeys
hotkeys: string[] | string
callback: () => void
options?: UseHotkeysOptions
deps?: any[]
}) {
useHotkeys(command.hotkeys, command.callback, command.options, command.deps)
useHotkeys(hotkeys, callback, merge({ targetElement: window }, options), deps)

return undefined
}
5 changes: 3 additions & 2 deletions assets/src/components/commandpalette/CommandPalette.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,11 @@ export default function CommandPalette({
</span>
</Command.Empty>
{commands.map((group, i) => (
<>
<div key={i}>
<Command.Group title={group.title}>
{group.commands.map((command) => (
<Command.Item
key={`${command.prefix}${command.label}`}
disabled={command.disabled}
onSelect={() => {
command.callback()
Expand All @@ -69,7 +70,7 @@ export default function CommandPalette({
))}
</Command.Group>
{i < commands.length - 1 && <Command.Separator />}
</>
</div>
))}
</Command.List>
</>
Expand Down
11 changes: 8 additions & 3 deletions assets/src/components/commandpalette/CommandPaletteLauncher.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { Chip, SearchIcon } from '@pluralsh/design-system'
import { useCallback, useState } from 'react'
import { usePlatform } from 'components/hooks/usePlatform'
import styled, { useTheme } from 'styled-components'

import { useHotkeys } from '@saas-ui/use-hotkeys'

import CommandPaletteDialog from './CommandPaletteDialog'
Expand Down Expand Up @@ -74,8 +73,14 @@ export default function CommandPaletteLauncher() {
open={open}
setOpen={setOpen}
/>
{commands.map((command) => (
<CommandHotkeys command={command} />
{commands.map(({ hotkeys, callback, options, deps }, i) => (
<CommandHotkeys
key={i}
hotkeys={hotkeys}
callback={callback}
options={options}
deps={deps}
/>
))}
</>
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export default function CommandPaletteShortcuts({
>
{chunks.map((chunk, i) => (
<WrapWithIf
key={i}
condition={!['or', 'then'].includes(chunk.toLowerCase())}
wrapper={
<div
Expand Down
4 changes: 2 additions & 2 deletions assets/src/components/commandpalette/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,6 @@ export function useCommands(): CommandGroup[] {
prefix: 'CD > Clusters >',
label: 'Pods',
icon: PodContainerIcon,
// FIXME: Fix issue with callback.
callback: () => {
if (cluster?.id)
navigate(
Expand Down Expand Up @@ -259,7 +258,8 @@ export function useCommands(): CommandGroup[] {
label: 'Open docs',
icon: DocumentIcon,
rightIcon: ArrowTopRightIcon,
callback: () => window.open('https://docs.plural.sh', '_blank'),
callback: () =>
window.open('https://docs.plural.sh', '_blank', 'noopener'),
hotkeys: ['shift D'],
},
{
Expand Down
Loading