Skip to content

Commit 7283459

Browse files
dnywhclaude
andauthored
chore(studio): use ShortcutBadge in Connect command (supabase#46245)
## What kind of change does this PR introduce? Refactor ## What is the current behavior? FE-3452: `Connect.Commands.tsx` has a local `ConnectShortcutBadge` component that hand-rolls the same Fragment + `KeyboardShortcut` + "then" separator loop that `ShortcutBadge` already provides. FE-3453: The `'header_button' | 'connect_section' | 'keyboard_shortcut'` union is written out twice: once in `app-state.ts` and once in the `ConnectSheetOpenedEvent` telemetry type in `telemetry-constants.ts`. ## What is the new behavior? FE-3452: `ConnectShortcutBadge` is removed; the badge uses `<ShortcutBadge shortcutId={SHORTCUT_IDS.CONNECT_OPEN_SHEET} />` inline. FE-3453: A `ConnectSheetSource` type is exported from `telemetry-constants.ts` and imported into `app-state.ts`. ## Additional context - Resolves FE-3452 - Resolves FE-3453. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Refactor** * Consolidated shortcut badge rendering to use a shared component across the application, improving code maintainability and reducing duplication. * Introduced a centralized type definition for connect sheet source tracking, enhancing type consistency throughout the codebase. <!-- review_stack_entry_start --> [![Review Change Stack](https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui.svg)](https://app.coderabbit.ai/change-stack/supabase/supabase/pull/46245?utm_source=github_walkthrough&utm_medium=github&utm_campaign=change_stack) <!-- review_stack_entry_end --> <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 3d48b83 commit 7283459

3 files changed

Lines changed: 9 additions & 19 deletions

File tree

apps/studio/components/interfaces/ConnectButton/Connect.Commands.tsx

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,14 @@
11
import { Plug } from 'lucide-react'
22
import { parseAsBoolean, parseAsString, useQueryState } from 'nuqs'
3-
import { Fragment } from 'react'
4-
import { KeyboardShortcut } from 'ui'
53
import type { ICommand } from 'ui-patterns/CommandMenu'
64
import { useRegisterCommands, useSetCommandMenuOpen } from 'ui-patterns/CommandMenu'
75

86
import { COMMAND_MENU_SECTIONS } from '@/components/interfaces/App/CommandMenu/CommandMenu.utils'
97
import { orderCommandSectionsByPriority } from '@/components/interfaces/App/CommandMenu/ordering'
8+
import { ShortcutBadge } from '@/components/ui/ShortcutBadge'
109
import { useSelectedProjectQuery } from '@/hooks/misc/useSelectedProject'
1110
import { PROJECT_STATUS } from '@/lib/constants'
12-
import { hotkeyToKeys } from '@/state/shortcuts/formatShortcut'
13-
import { SHORTCUT_DEFINITIONS, SHORTCUT_IDS } from '@/state/shortcuts/registry'
14-
15-
const ConnectShortcutBadge = () => (
16-
<div className="flex items-center gap-1">
17-
{SHORTCUT_DEFINITIONS[SHORTCUT_IDS.CONNECT_OPEN_SHEET].sequence.map((step, index) => (
18-
<Fragment key={`${step}-${index}`}>
19-
{index > 0 && <span className="text-foreground-lighter text-[11px]">then</span>}
20-
<KeyboardShortcut keys={hotkeyToKeys(step)} />
21-
</Fragment>
22-
))}
23-
</div>
24-
)
11+
import { SHORTCUT_IDS } from '@/state/shortcuts/registry'
2512

2613
export function useConnectCommands() {
2714
const setIsOpen = useSetCommandMenuOpen()
@@ -43,7 +30,7 @@ export function useConnectCommands() {
4330
setIsOpen(false)
4431
},
4532
icon: () => <Plug className="rotate-90" />,
46-
badge: ConnectShortcutBadge,
33+
badge: () => <ShortcutBadge shortcutId={SHORTCUT_IDS.CONNECT_OPEN_SHEET} />,
4734
},
4835
{
4936
id: 'connect-mcp',

apps/studio/state/app-state.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { LOCAL_STORAGE_KEYS as COMMON_LOCAL_STORAGE_KEYS } from 'common'
2+
import { type ConnectSheetSource } from 'common/telemetry-constants'
23
import { proxy, snapshot, useSnapshot } from 'valtio'
34

45
const getInitialState = () => {
@@ -70,8 +71,8 @@ export const appState = proxy({
7071
appState.mobileMenuOpen = value
7172
},
7273

73-
connectSheetSource: 'header_button' as 'header_button' | 'connect_section' | 'keyboard_shortcut',
74-
setConnectSheetSource: (value: 'header_button' | 'connect_section' | 'keyboard_shortcut') => {
74+
connectSheetSource: 'header_button' as ConnectSheetSource,
75+
setConnectSheetSource: (value: ConnectSheetSource) => {
7576
appState.connectSheetSource = value
7677
},
7778

packages/common/telemetry-constants.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1916,6 +1916,8 @@ export interface HomeConnectActionClickedEvent {
19161916
groups: TelemetryGroups
19171917
}
19181918

1919+
export type ConnectSheetSource = 'header_button' | 'connect_section' | 'keyboard_shortcut'
1920+
19191921
/**
19201922
* User opened the ConnectSheet panel.
19211923
*
@@ -1929,7 +1931,7 @@ export interface ConnectSheetOpenedEvent {
19291931
/**
19301932
* Where the sheet was opened from
19311933
*/
1932-
source: 'header_button' | 'connect_section' | 'keyboard_shortcut'
1934+
source: ConnectSheetSource
19331935
}
19341936
groups: TelemetryGroups
19351937
}

0 commit comments

Comments
 (0)