The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
Layout Editor + Keyboard Shortcuts improvements (#36165)
Jordi Enric7105df3d1f60
diff --git a/apps/studio/components/layouts/AppLayout/AssistantButton.tsx b/apps/studio/components/layouts/AppLayout/AssistantButton.tsxindex 5ca3dd071ff..8f708884181 100644--- a/apps/studio/components/layouts/AppLayout/AssistantButton.tsx+++ b/apps/studio/components/layouts/AppLayout/AssistantButton.tsx@@ -1,13 +1,15 @@+import { ButtonTooltip } from 'components/ui/ButtonTooltip'import { useAiAssistantStateSnapshot } from 'state/ai-assistant-state'import { useAppStateSnapshot } from 'state/app-state'-import { AiIconAnimation, Button } from 'ui'+import { AiIconAnimation } from 'ui'+import { KeyboardShortcut } from 'ui'export const AssistantButton = () => {const snap = useAiAssistantStateSnapshot()const { setEditorPanel } = useAppStateSnapshot()return (- <Button+ <ButtonTooltiptype="text"size="tiny"id="assistant-trigger"@@ -16,8 +18,18 @@ export const AssistantButton = () => {snap.toggleAssistant()setEditorPanel({ open: false })}}+ tooltip={{+ content: {+ text: (+ <div className="flex items-center gap-4">+ <span>AI Assistant</span>+ <KeyboardShortcut keys={['Meta', 'i']} />+ </div>+ ),+ },+ }}><AiIconAnimation allowHoverEffect size={16} />- </Button>+ </ButtonTooltip>)}diff --git a/apps/studio/components/layouts/AppLayout/InlineEditorButton.tsx b/apps/studio/components/layouts/AppLayout/InlineEditorButton.tsxindex 9def8b03667..fa5ca07c5c3 100644--- a/apps/studio/components/layouts/AppLayout/InlineEditorButton.tsx+++ b/apps/studio/components/layouts/AppLayout/InlineEditorButton.tsx@@ -1,24 +1,35 @@import { SqlEditor } from 'icons'import { useAiAssistantStateSnapshot } from 'state/ai-assistant-state'import { useAppStateSnapshot } from 'state/app-state'-import { Button } from 'ui'+import { ButtonTooltip } from 'components/ui/ButtonTooltip'+import { KeyboardShortcut } from 'ui'export const InlineEditorButton = () => {const { closeAssistant } = useAiAssistantStateSnapshot()const { setEditorPanel, editorPanel } = useAppStateSnapshot()return (- <Button+ <ButtonTooltiptype="text"size="tiny"id="editor-trigger"- className="w-[24px] h-[24px] flex items-center justify-center p-0"+ className="w-[24px] h-[24px] flex items-center justify-center p-0 text-foreground-light hover:text-foreground"onClick={() => {closeAssistant()setEditorPanel({ open: !editorPanel.open })}}+ tooltip={{+ content: {+ text: (+ <div className="flex items-center gap-4">+ <span>SQL Editor</span>+ <KeyboardShortcut keys={['Meta', 'e']} />+ </div>+ ),+ },+ }}>- <SqlEditor size={20} strokeWidth={1.5} />- </Button>+ <SqlEditor size={16} strokeWidth={1.5} />+ </ButtonTooltip>)}diff --git a/apps/studio/components/layouts/ProjectLayout/LayoutHeader/NotificationsPopoverV2/NotificationsPopover.tsx b/apps/studio/components/layouts/ProjectLayout/LayoutHeader/NotificationsPopoverV2/NotificationsPopover.tsxindex ba4a83e1955..00220250507 100644--- a/apps/studio/components/layouts/ProjectLayout/LayoutHeader/NotificationsPopoverV2/NotificationsPopover.tsx+++ b/apps/studio/components/layouts/ProjectLayout/LayoutHeader/NotificationsPopoverV2/NotificationsPopover.tsx@@ -26,6 +26,7 @@ import {} from 'ui'import NotificationRow from './NotificationRow'import { NotificationsFilter } from './NotificationsFilter'+import { ButtonTooltip } from 'components/ui/ButtonTooltip'export const NotificationsPopoverV2 = () => {const [open, setOpen] = useState(false)@@ -96,7 +97,12 @@ export const NotificationsPopoverV2 = () => {}}><PopoverTrigger_Shadcn_ asChild>- <Button+ <ButtonTooltip+ tooltip={{+ content: {+ text: 'Notifications',+ },+ }}type={hasNewNotifications ? 'outline' : 'text'}className={cn('h-[26px]',diff --git a/apps/studio/components/layouts/ProjectLayout/ProjectLayout.tsx b/apps/studio/components/layouts/ProjectLayout/ProjectLayout.tsxindex 8cc5e099791..3c887f9ac36 100644--- a/apps/studio/components/layouts/ProjectLayout/ProjectLayout.tsx+++ b/apps/studio/components/layouts/ProjectLayout/ProjectLayout.tsx@@ -91,7 +91,14 @@ const ProjectLayout = forwardRef<HTMLDivElement, PropsWithChildren<ProjectLayoutconst [isClient, setIsClient] = useState(false)const selectedOrganization = useSelectedOrganization()const selectedProject = useSelectedProject()- const { editorPanel, mobileMenuOpen, showSidebar, setMobileMenuOpen } = useAppStateSnapshot()+ const {+ editorPanel,+ mobileMenuOpen,+ showSidebar,+ setMobileMenuOpen,+ toggleEditorPanel,+ setEditorPanel,+ } = useAppStateSnapshot()const aiSnap = useAiAssistantStateSnapshot()const isTableEditorTabsEnabled = useIsTableEditorTabsEnabled()@@ -124,16 +131,25 @@ const ProjectLayout = forwardRef<HTMLDivElement, PropsWithChildren<ProjectLayoutuseEffect(() => {const handler = (e: KeyboardEvent) => {+ // Cmd+I: Open AI Assistant, close Editor Panelif (e.metaKey && e.key === 'i' && !e.altKey && !e.shiftKey) {+ setEditorPanel({ open: false })aiSnap.toggleAssistant()e.preventDefault()e.stopPropagation()}+ // Cmd+E: Toggle Editor Panel, always close AI Assistant+ if (e.metaKey && e.key === 'e' && !e.altKey && !e.shiftKey) {+ aiSnap.closeAssistant()+ toggleEditorPanel()+ e.preventDefault()+ e.stopPropagation()+ }}window.addEventListener('keydown', handler)return () => window.removeEventListener('keydown', handler)// eslint-disable-next-line react-hooks/exhaustive-deps- }, [aiSnap.open])+ }, [setEditorPanel, aiSnap, editorPanel.open])return (<>diff --git a/apps/studio/state/app-state.ts b/apps/studio/state/app-state.tsindex f95a0dcfaf0..dbd21c91198 100644--- a/apps/studio/state/app-state.ts+++ b/apps/studio/state/app-state.ts@@ -185,6 +185,10 @@ export const appState = proxy({}},+ toggleEditorPanel: (value?: boolean) => {+ appState.editorPanel.open = value ?? !appState.editorPanel.open+ },+mobileMenuOpen: false,setMobileMenuOpen: (value: boolean) => {appState.mobileMenuOpen = valuediff --git a/packages/ui/index.tsx b/packages/ui/index.tsxindex 5970d2bf230..51eb2e19576 100644--- a/packages/ui/index.tsx+++ b/packages/ui/index.tsx@@ -281,3 +281,5 @@ export * from './src/components/Icon/icons/IconYoutubeSolid'// Export hooksexport * from './src/lib/Hooks'++export * from './src/components/KeyboardShortcut/KeyboardShortcut'diff --git a/packages/ui/src/components/KeyboardShortcut/KeyboardShortcut.tsx b/packages/ui/src/components/KeyboardShortcut/KeyboardShortcut.tsxnew file mode 100644index 00000000000..6a7f37654f9--- /dev/null+++ b/packages/ui/src/components/KeyboardShortcut/KeyboardShortcut.tsx@@ -0,0 +1,31 @@+const getIsMac = () => {+ if (typeof navigator === 'undefined') return false++ if (navigator.userAgent && navigator.userAgent.includes('Mac')) {+ return true+ }++ if (navigator.platform) {+ return navigator.platform.startsWith('Mac') || navigator.platform === 'iPhone'+ }+ return false+}++export const KeyboardShortcut = ({ keys }: { keys: string[] }) => {+ const isMac = getIsMac()+ const keysWithMeta = keys.map((key) => (key === 'Meta' ? (isMac ? '⌘' : 'Ctrl') : key))+ const keysWithMetaAndShift = keysWithMeta.map((key) => (key === 'Shift' ? '⇧' : key))++ return (+ <div className="text-xs text-foreground-light flex items-center gap-[3px]">+ {keysWithMetaAndShift.map((key) => (+ <span+ className="px-1.5 py-0.5 rounded-sm border-b-2 flex items-center justify-center border border-foreground-lightest cursor-default"+ key={key}+ >+ {key}+ </span>+ ))}+ </div>+ )+}