Database diagrams editor that allows you to visualize and design your DB with a single query.
TypeScript databasedbdb-migrationeditorerdmariadbmssqlmysqlpostgresqlreactreact-flowschema-migrationssqlsqlitetypescriptvisualizationxyflow
feat(side panel): collapsible side panel on desktop view + keyboard shortcut (#439)
Huy Bui70f545f78bab
diff --git a/src/context/keyboard-shortcuts-context/keyboard-shortcuts-provider.tsx b/src/context/keyboard-shortcuts-context/keyboard-shortcuts-provider.tsxindex 4a09e4f2..f6849113 100644--- a/src/context/keyboard-shortcuts-context/keyboard-shortcuts-provider.tsx+++ b/src/context/keyboard-shortcuts-context/keyboard-shortcuts-provider.tsx@@ -8,6 +8,7 @@ import {import { useHistory } from '@/hooks/use-history';import { useDialog } from '@/hooks/use-dialog';import { useChartDB } from '@/hooks/use-chartdb';+import { useLayout } from '@/hooks/use-layout';export const KeyboardShortcutsProvider: React.FC<React.PropsWithChildren> = ({children,@@ -15,6 +16,8 @@ export const KeyboardShortcutsProvider: React.FC<React.PropsWithChildren> = ({const { redo, undo } = useHistory();const { openOpenDiagramDialog } = useDialog();const { updateDiagramUpdatedAt } = useChartDB();+ const { toggleSidePanel } = useLayout();+useHotkeys(keyboardShortcutsForOS[KeyboardShortcutAction.REDO].keyCombination,redo,@@ -49,6 +52,15 @@ export const KeyboardShortcutsProvider: React.FC<React.PropsWithChildren> = ({},[updateDiagramUpdatedAt]);+ useHotkeys(+ keyboardShortcutsForOS[KeyboardShortcutAction.TOGGLE_SIDE_PANEL]+ .keyCombination,+ toggleSidePanel,+ {+ preventDefault: true,+ },+ [toggleSidePanel]+ );return (<keyboardShortcutsContext.Provider value={{}}>diff --git a/src/context/keyboard-shortcuts-context/keyboard-shortcuts.ts b/src/context/keyboard-shortcuts-context/keyboard-shortcuts.tsindex 2516284e..6a30aa29 100644--- a/src/context/keyboard-shortcuts-context/keyboard-shortcuts.ts+++ b/src/context/keyboard-shortcuts-context/keyboard-shortcuts.ts@@ -5,6 +5,7 @@ export enum KeyboardShortcutAction {UNDO = 'undo',OPEN_DIAGRAM = 'open_diagram',SAVE_DIAGRAM = 'save_diagram',+ TOGGLE_SIDE_PANEL = 'toggle_side_panel',}export interface KeyboardShortcut {@@ -47,6 +48,13 @@ export const keyboardShortcuts: Record<keyCombinationMac: 'meta+s',keyCombinationWin: 'ctrl+s',},+ [KeyboardShortcutAction.TOGGLE_SIDE_PANEL]: {+ action: KeyboardShortcutAction.TOGGLE_SIDE_PANEL,+ keyCombinationLabelMac: '⌘B',+ keyCombinationLabelWin: 'Ctrl+B',+ keyCombinationMac: 'meta+b',+ keyCombinationWin: 'ctrl+b',+ },};export interface KeyboardShortcutForOS {diff --git a/src/context/layout-context/layout-context.tsx b/src/context/layout-context/layout-context.tsxindex d1d7cc9f..5b597d15 100644--- a/src/context/layout-context/layout-context.tsx+++ b/src/context/layout-context/layout-context.tsx@@ -22,6 +22,7 @@ export interface LayoutContext {isSidePanelShowed: boolean;hideSidePanel: () => void;showSidePanel: () => void;+ toggleSidePanel: () => void;isSelectSchemaOpen: boolean;openSelectSchema: () => void;@@ -47,6 +48,7 @@ export const layoutContext = createContext<LayoutContext>({isSidePanelShowed: false,hideSidePanel: emptyFn,showSidePanel: emptyFn,+ toggleSidePanel: emptyFn,isSelectSchemaOpen: false,openSelectSchema: emptyFn,diff --git a/src/context/layout-context/layout-provider.tsx b/src/context/layout-context/layout-provider.tsxindex 81b3962c..32bed103 100644--- a/src/context/layout-context/layout-provider.tsx+++ b/src/context/layout-context/layout-provider.tsx@@ -36,6 +36,10 @@ export const LayoutProvider: React.FC<React.PropsWithChildren> = ({const showSidePanel: LayoutContext['showSidePanel'] = () =>setIsSidePanelShowed(true);+ const toggleSidePanel: LayoutContext['toggleSidePanel'] = () => {+ setIsSidePanelShowed((prevIsSidePanelShowed) => !prevIsSidePanelShowed);+ };+const openTableFromSidebar: LayoutContext['openTableFromSidebar'] = (tableId) => {@@ -77,6 +81,7 @@ export const LayoutProvider: React.FC<React.PropsWithChildren> = ({isSidePanelShowed,hideSidePanel,showSidePanel,+ toggleSidePanel,isSelectSchemaOpen,openSelectSchema,closeSelectSchema,diff --git a/src/pages/editor-page/editor-desktop-layout.tsx b/src/pages/editor-page/editor-desktop-layout.tsxindex b1a94159..ec95e542 100644--- a/src/pages/editor-page/editor-desktop-layout.tsx+++ b/src/pages/editor-page/editor-desktop-layout.tsx@@ -8,6 +8,7 @@ import { SidePanel } from './side-panel/side-panel';import { Canvas } from './canvas/canvas';import { useLayout } from '@/hooks/use-layout';import type { Diagram } from '@/lib/domain/diagram';+import { cn } from '@/lib/utils';export interface EditorDesktopLayoutProps {initialDiagram?: Diagram;@@ -23,12 +24,13 @@ export const EditorDesktopLayout: React.FC<EditorDesktopLayoutProps> = ({defaultSize={25}minSize={25}maxSize={isSidePanelShowed ? 99 : 0}- // eslint-disable-next-line- className="transition-[flex-grow] duration-200 min-w-[350px]"+ className={cn('transition-[flex-grow] duration-200', {+ 'min-w-[350px]': isSidePanelShowed,+ })}><SidePanel /></ResizablePanel>- <ResizableHandle />+ <ResizableHandle disabled={!isSidePanelShowed} /><ResizablePanel defaultSize={75}><Canvas initialTables={initialDiagram?.tables ?? []} /></ResizablePanel>diff --git a/src/pages/editor-page/top-navbar/top-navbar.tsx b/src/pages/editor-page/top-navbar/top-navbar.tsxindex 27ae6cc7..783d5f2a 100644--- a/src/pages/editor-page/top-navbar/top-navbar.tsx+++ b/src/pages/editor-page/top-navbar/top-navbar.tsx@@ -467,6 +467,14 @@ export const TopNavbar: React.FC<TopNavbarProps> = () => {{isSidePanelShowed? t('menu.view.hide_sidebar'): t('menu.view.show_sidebar')}+ <MenubarShortcut>+ {+ keyboardShortcutsForOS[+ KeyboardShortcutAction+ .TOGGLE_SIDE_PANEL+ ].keyCombinationLabel+ }+ </MenubarShortcut></MenubarItem><MenubarSeparator /><MenubarItem onClick={showOrHideCardinality}>