@@ -109,6 +109,13 @@ export function DatabaseSidebar({
109109 return set ;
110110 } , [ starredItemsRaw ] ) ;
111111
112+ // Compute non-starred counts for section headers
113+ const nonStarredCounts = useMemo ( ( ) => ( {
114+ tables : tables . filter ( ( t ) => ! starredSet . has ( `table:${ t . schema } .${ t . name } ` ) ) . length ,
115+ views : views . filter ( ( v ) => ! starredSet . has ( `view:${ v . schema } .${ v . name } ` ) ) . length ,
116+ functions : functions . filter ( ( f ) => ! starredSet . has ( `function:${ f . schema } .${ f . name } ` ) ) . length ,
117+ } ) , [ tables , views , functions , starredSet ] ) ;
118+
112119 // Pre-compute pending changes set for O(1) lookups
113120 const pendingChangesSet = useMemo ( ( ) => {
114121 const set = new Set < string > ( ) ;
@@ -205,21 +212,21 @@ export function DatabaseSidebar({
205212
206213 // Add tables if expanded
207214 if ( expandedNodes . has ( "tables" ) ) {
208- filterItems ( tables ) . forEach ( ( table ) => {
215+ filterItems ( tables , "table" ) . forEach ( ( table ) => {
209216 allItems . push ( getItemKey ( "table" , table . name , table . schema ) ) ;
210217 } ) ;
211218 }
212219
213220 // Add views if expanded
214221 if ( expandedNodes . has ( "views" ) ) {
215- filterItems ( views ) . forEach ( ( view ) => {
222+ filterItems ( views , "view" ) . forEach ( ( view ) => {
216223 allItems . push ( getItemKey ( "view" , view . name , view . schema ) ) ;
217224 } ) ;
218225 }
219226
220227 // Add functions if expanded
221228 if ( expandedNodes . has ( "functions" ) ) {
222- filterItems ( functions ) . forEach ( ( func ) => {
229+ filterItems ( functions , "function" ) . forEach ( ( func ) => {
223230 allItems . push ( getItemKey ( "function" , func . name , func . schema ) ) ;
224231 } ) ;
225232 }
@@ -516,12 +523,22 @@ export function DatabaseSidebar({
516523 // Use pre-computed starred items
517524 const starredItems = starredItemsRaw ;
518525
519- // IconFilter items based on search
520- const filterItems = < T extends { name : string } > ( items : T [ ] ) : T [ ] => {
521- if ( ! searchQuery ) return items ;
522- return items . filter ( ( item ) =>
523- item . name . toLowerCase ( ) . includes ( searchQuery . toLowerCase ( ) ) ,
524- ) ;
526+ // Filter items based on search and exclude starred items from original groups
527+ const filterItems = < T extends { name : string ; schema : string } > (
528+ items : T [ ] ,
529+ type : "table" | "view" | "function" ,
530+ ) : T [ ] => {
531+ return items . filter ( ( item ) => {
532+ // Exclude starred items from their original group
533+ if ( starredSet . has ( `${ type } :${ item . schema } .${ item . name } ` ) ) {
534+ return false ;
535+ }
536+ // Apply search filter
537+ if ( searchQuery && ! item . name . toLowerCase ( ) . includes ( searchQuery . toLowerCase ( ) ) ) {
538+ return false ;
539+ }
540+ return true ;
541+ } ) ;
525542 } ;
526543
527544 // IconCheck if a table/view is currently active in the active panel
@@ -810,10 +827,10 @@ export function DatabaseSidebar({
810827 ) }
811828
812829 { /* Tables Section */ }
813- { ( tables . length > 0 || isLoadingData ) && (
830+ { ( nonStarredCounts . tables > 0 || isLoadingData ) && (
814831 < SidebarSection
815832 title = "Tables"
816- count = { tables . length }
833+ count = { nonStarredCounts . tables }
817834 isExpanded = { expandedNodes . has ( "tables" ) }
818835 onToggle = { ( ) => {
819836 toggleNode ( "tables" ) ;
@@ -822,7 +839,7 @@ export function DatabaseSidebar({
822839 onAdd = { handleCreateTable }
823840 addTooltip = "Create new table"
824841 >
825- { filterItems ( tables ) . map ( ( table ) => {
842+ { filterItems ( tables , "table" ) . map ( ( table ) => {
826843 const itemKey = getItemKey ( "table" , table . name , table . schema ) ;
827844 return (
828845 < SidebarItem
@@ -882,18 +899,18 @@ export function DatabaseSidebar({
882899 ) }
883900
884901 { /* Views Section */ }
885- { views . length > 0 && (
902+ { nonStarredCounts . views > 0 && (
886903 < SidebarSection
887904 title = "Views"
888- count = { views . length }
905+ count = { nonStarredCounts . views }
889906 isExpanded = { expandedNodes . has ( "views" ) }
890907 onToggle = { ( ) => {
891908 toggleNode ( "views" ) ;
892909 } }
893910 onAdd = { handleCreateView }
894911 addTooltip = "Create new view"
895912 >
896- { filterItems ( views ) . map ( ( view ) => {
913+ { filterItems ( views , "view" ) . map ( ( view ) => {
897914 const itemKey = getItemKey ( "view" , view . name , view . schema ) ;
898915 return (
899916 < SidebarItem
@@ -960,10 +977,10 @@ export function DatabaseSidebar({
960977 ) }
961978
962979 { /* Functions Section */ }
963- { functions . length > 0 && (
980+ { nonStarredCounts . functions > 0 && (
964981 < SidebarSection
965982 title = "Functions"
966- count = { functions . length }
983+ count = { nonStarredCounts . functions }
967984 isExpanded = { expandedNodes . has ( "functions" ) }
968985 onToggle = { ( ) => {
969986 toggleNode ( "functions" ) ;
@@ -972,7 +989,7 @@ export function DatabaseSidebar({
972989 onAdd = { handleCreateFunction }
973990 addTooltip = "Create new function"
974991 >
975- { filterItems ( functions ) . map ( ( func ) => {
992+ { filterItems ( functions , "function" ) . map ( ( func ) => {
976993 const itemKey = getItemKey ( "function" , func . name , func . schema ) ;
977994 return (
978995 < SidebarItem
0 commit comments