1
- import React , { useCallback , useMemo } from 'react' ;
1
+ import React , { useCallback , useMemo , useState } from 'react' ;
2
2
import { connect } from 'react-redux' ;
3
3
import {
4
4
useHoverState ,
@@ -23,9 +23,8 @@ import {
23
23
withPreferences ,
24
24
} from 'compass-preferences-model/provider' ;
25
25
import type { ItemAction } from '@mongodb-js/compass-components' ;
26
- import DatabaseCollectionFilter from '../database-collection -filter' ;
26
+ import NavigationItemsFilter from '../navigation-items -filter' ;
27
27
import SidebarDatabasesNavigation from './sidebar-databases-navigation' ;
28
- import { changeFilterRegex } from '../../modules/databases' ;
29
28
import type { RootState } from '../../modules' ;
30
29
import {
31
30
useOpenWorkspace ,
@@ -40,12 +39,12 @@ const navigationItem = css({
40
39
cursor : 'pointer' ,
41
40
color : 'var(--item-color)' ,
42
41
border : 'none' ,
43
- height : spacing [ 5 ] ,
42
+ height : spacing [ 800 ] ,
44
43
position : 'relative' ,
45
44
46
45
'& .item-action-controls' : {
47
46
marginLeft : 'auto' ,
48
- marginRight : spacing [ 1 ] ,
47
+ marginRight : spacing [ 100 ] ,
49
48
} ,
50
49
51
50
'&:hover .item-background' : {
@@ -88,16 +87,16 @@ const itemPlaceholderStyles = css({
88
87
width : '100%' ,
89
88
display : 'flex' ,
90
89
alignItems : 'center' ,
91
- paddingLeft : spacing [ 3 ] ,
92
- height : spacing [ 5 ] ,
90
+ paddingLeft : spacing [ 400 ] ,
91
+ height : spacing [ 800 ] ,
93
92
} ) ;
94
93
95
94
const itemWrapper = css ( {
96
95
position : 'relative' ,
97
96
display : 'flex' ,
98
97
alignItems : 'center' ,
99
- height : spacing [ 5 ] ,
100
- gap : spacing [ 2 ] ,
98
+ height : spacing [ 800 ] ,
99
+ gap : spacing [ 200 ] ,
101
100
zIndex : 1 ,
102
101
} ) ;
103
102
@@ -114,7 +113,7 @@ const itemButtonWrapper = css({
114
113
display : 'flex' ,
115
114
alignItems : 'center' ,
116
115
minWidth : 0 ,
117
- paddingLeft : spacing [ 3 ] ,
116
+ paddingLeft : spacing [ 400 ] ,
118
117
} ) ;
119
118
120
119
const signalContainerStyles = css ( {
@@ -125,7 +124,7 @@ const navigationItemLabel = css({
125
124
overflow : 'hidden' ,
126
125
whiteSpace : 'nowrap' ,
127
126
textOverflow : 'ellipsis' ,
128
- marginLeft : spacing [ 2 ] ,
127
+ marginLeft : spacing [ 200 ] ,
129
128
} ) ;
130
129
131
130
const navigationItemDisabledDarkModeStyles = css ( {
@@ -140,6 +139,10 @@ const navigationItemDisabledLightModeStyles = css({
140
139
'--item-bg-color-hover' : 'var(--item-bg-color)' ,
141
140
} ) ;
142
141
142
+ const databaseCollectionsFilter = css ( {
143
+ margin : `${ spacing [ 100 ] } px ${ spacing [ 400 ] } px` ,
144
+ } ) ;
145
+
143
146
const navigationItemActionIcons = css ( { color : 'inherit' } ) ;
144
147
145
148
export function NavigationItem < Actions extends string > ( {
@@ -199,7 +202,7 @@ export function NavigationItem<Actions extends string>({
199
202
return (
200
203
< Tooltip
201
204
align = "right"
202
- spacing = { spacing [ 3 ] }
205
+ spacing = { spacing [ 400 ] }
203
206
isDisabled = { ! isButtonDisabled || ! buttonDisabledMessage }
204
207
trigger = { ( { children : tooltip , ...triggerProps } ) => {
205
208
const props = mergeProps ( triggerProps , navigationItemProps ) ;
@@ -257,7 +260,6 @@ export function NavigationItems({
257
260
connectionInfo,
258
261
showCreateDatabaseAction,
259
262
isPerformanceTabSupported,
260
- onFilterChange,
261
263
onAction,
262
264
activeWorkspace,
263
265
showTooManyCollectionsInsight = false ,
@@ -266,7 +268,6 @@ export function NavigationItems({
266
268
connectionInfo : ConnectionInfo ;
267
269
showCreateDatabaseAction : boolean ;
268
270
isPerformanceTabSupported : boolean ;
269
- onFilterChange ( regex : RegExp | null ) : void ;
270
271
onAction ( actionName : string , ...rest : any [ ] ) : void ;
271
272
activeWorkspace ?: WorkspaceTab ;
272
273
showTooManyCollectionsInsight ?: boolean ;
@@ -278,6 +279,14 @@ export function NavigationItems({
278
279
} = useOpenWorkspace ( ) ;
279
280
const { hasWorkspacePlugin } = useWorkspacePlugins ( ) ;
280
281
282
+ const [ databasesFilterRegex , setDatabasesFilterRegex ] =
283
+ useState < RegExp | null > ( null ) ;
284
+
285
+ const onDatabasesFilterChange = useCallback (
286
+ ( filterRegex : RegExp | null ) => setDatabasesFilterRegex ( filterRegex ) ,
287
+ [ setDatabasesFilterRegex ]
288
+ ) ;
289
+
281
290
const databasesActions = useMemo ( ( ) => {
282
291
const actions : ItemAction < DatabasesActions > [ ] = [
283
292
{
@@ -356,10 +365,16 @@ export function NavigationItems({
356
365
} }
357
366
> </ ContentWithFallback >
358
367
359
- < DatabaseCollectionFilter onFilterChange = { onFilterChange } />
368
+ < NavigationItemsFilter
369
+ onFilterChange = { onDatabasesFilterChange }
370
+ title = "Databases and collections filter"
371
+ ariaLabel = "Databases and collections filter"
372
+ searchInputClassName = { databaseCollectionsFilter }
373
+ />
360
374
< SidebarDatabasesNavigation
361
375
connectionInfo = { connectionInfo }
362
376
activeWorkspace = { activeWorkspace ?? undefined }
377
+ filterRegex = { databasesFilterRegex }
363
378
/>
364
379
</ >
365
380
) ;
@@ -399,9 +414,7 @@ const mapStateToProps = (
399
414
} ;
400
415
401
416
const MappedNavigationItems = withPreferences (
402
- connect ( mapStateToProps , {
403
- onFilterChange : changeFilterRegex ,
404
- } ) ( NavigationItems ) ,
417
+ connect ( mapStateToProps ) ( NavigationItems ) ,
405
418
[ 'readOnly' ]
406
419
) ;
407
420
0 commit comments