@@ -10,19 +10,12 @@ import { Tooltip, TooltipContent, TooltipTrigger } from "@/components/ui/tooltip
1010import { usePostgresStore } from "@/contexts/postgres-context" ;
1111import { useAppearance } from "@/hooks/use-appearance" ;
1212import { DatabaseConnection } from "@/types/database" ;
13+ import { QueryHistoryItem } from "@/types/postgres" ;
1314import Editor from "@monaco-editor/react" ;
1415import dayjs from "dayjs" ;
1516import relativeTime from "dayjs/plugin/relativeTime" ;
16- import {
17- CodeIcon ,
18- DatabaseIcon ,
19- PanelLeftIcon ,
20- PlayIcon ,
21- RotateCcwIcon ,
22- SearchIcon ,
23- XIcon
24- } from "lucide-react" ;
25- import { useCallback , useEffect , useRef , useState } from "react" ;
17+ import { CodeIcon , DatabaseIcon , PanelLeftIcon , PlayIcon , RotateCcwIcon , SearchIcon , XIcon } from "lucide-react" ;
18+ import { useCallback , useEffect , useState } from "react" ;
2619import { Separator } from "../ui/separator" ;
2720
2821dayjs . extend ( relativeTime ) ;
@@ -36,18 +29,6 @@ interface TableData {
3629 table_name : string ;
3730}
3831
39- interface QueryHistoryItem {
40- id : number ;
41- database_connection_id : number ;
42- query : string ;
43- executor : string ;
44- executor_id : number | null ;
45- type : string ;
46- description : string ;
47- created_at : string ;
48- updated_at : string ;
49- }
50-
5132interface PostgresMasterSidebarProps {
5233 connection : DatabaseConnection ;
5334 loading : boolean ;
@@ -59,19 +40,19 @@ interface PostgresMasterSidebarProps {
5940 onTableSelect : ( tableName : string ) => void ;
6041}
6142
62- const PostgresMasterSidebar = ( {
43+ const PostgresMasterSidebar = ( {
6344 connection,
64- loading,
65- selectedSchema,
66- schemas,
67- tables,
68- selectedTable,
69- onSchemaSelect,
70- onTableSelect
45+ loading,
46+ selectedSchema,
47+ schemas,
48+ tables,
49+ selectedTable,
50+ onSchemaSelect,
51+ onTableSelect,
7152} : PostgresMasterSidebarProps ) => {
7253 const isQueryMode = usePostgresStore ( ( state ) => state . isQueryMode ) ;
7354 const queryString = usePostgresStore ( ( state ) => state . queryString ) ;
74- const queryHistory = usePostgresStore ( ( state ) => state . queryHistory ) as QueryHistoryItem [ ] ;
55+ const queryHistory = usePostgresStore ( ( state ) => state . queryHistory ) ;
7556 const executingQuery = usePostgresStore ( ( state ) => state . executingQuery ) ;
7657 const loadingHistory = usePostgresStore ( ( state ) => state . loadingHistory ) ;
7758 const setQueryString = usePostgresStore ( ( state ) => state . setQueryString ) ;
@@ -81,7 +62,7 @@ const PostgresMasterSidebar = ({
8162 const [ open , setOpen ] = useState ( false ) ;
8263 const [ search , setSearch ] = useState ( "" ) ;
8364 const [ activeTab , setActiveTab ] = useState ( "explorer" ) ;
84-
65+
8566 const { appearance } = useAppearance ( ) ;
8667
8768 // Auto-switch to query tab when query mode is enabled
@@ -92,15 +73,19 @@ const PostgresMasterSidebar = ({
9273 } , [ isQueryMode ] ) ;
9374
9475 // Handle tab changes and auto-enable query mode
95- const handleTabChange = useCallback ( ( tab : string ) => {
96- setActiveTab ( tab ) ;
97- if ( tab === "query" && ! isQueryMode ) {
98- setQueryMode ( true ) ;
99- }
100- } , [ isQueryMode , setQueryMode ] ) ;
101-
76+ const handleTabChange = useCallback (
77+ ( tab : string ) => {
78+ setActiveTab ( tab ) ;
79+ if ( tab === "query" && ! isQueryMode ) {
80+ setQueryMode ( true ) ;
81+ }
82+ } ,
83+ [ isQueryMode , setQueryMode ] ,
84+ ) ;
85+
10286 const filteredTables = tables . filter ( ( table ) => {
103- const regex = new RegExp ( search , "i" ) ;
87+ const escapedSearch = search . replace ( / [ . * + ? ^ $ { } ( ) | [ \] \\ ] / g, "\\$&" ) ;
88+ const regex = new RegExp ( escapedSearch , "i" ) ;
10489 return regex . test ( table . table_name ) ;
10590 } ) ;
10691
@@ -169,7 +154,7 @@ const PostgresMasterSidebar = ({
169154 < div
170155 className = "rounded-md border bg-background p-2 font-mono text-sm flex-1 min-h-0"
171156 onKeyDown = { ( e ) => {
172- if ( e . ctrlKey && e . code === "Enter" && queryString ?. trim ( ) ) {
157+ if ( ( e . ctrlKey || e . metaKey ) && e . code === "Enter" && queryString ?. trim ( ) ) {
173158 executeQuery ( connection ) ;
174159 }
175160 } }
@@ -298,21 +283,17 @@ const PostgresMasterSidebar = ({
298283 < TooltipContent > Open sidebar</ TooltipContent >
299284 </ Tooltip >
300285 < SheetContent side = "left" className = "w-80 p-4" >
301- < div className = "flex flex-col gap-4 overflow-y-auto pt-10 h-full" >
302- { sidebarContent }
303- </ div >
286+ < div className = "flex flex-col gap-4 overflow-y-auto pt-10 h-full" > { sidebarContent } </ div >
304287 </ SheetContent >
305288 </ Sheet >
306289 </ div >
307290
308291 { /* Desktop view */ }
309292 < div className = "hidden h-full md:block" >
310- < div className = "flex h-full w-76 flex-col gap-4 overflow-y-auto border-r p-4" >
311- { sidebarContent }
312- </ div >
293+ < div className = "flex h-full w-76 flex-col gap-4 overflow-y-auto border-r p-4" > { sidebarContent } </ div >
313294 </ div >
314295 </ >
315296 ) ;
316297} ;
317298
318- export default PostgresMasterSidebar ;
299+ export default PostgresMasterSidebar ;
0 commit comments