1
1
import { type ConnectionInfo } from '@mongodb-js/connection-info' ;
2
2
import { useConnectionColor } from '@mongodb-js/connection-form' ;
3
- import { useConnectionRepository } from './use-connection-repository' ;
4
3
import { useDarkMode , type TabTheme } from '@mongodb-js/compass-components' ;
5
4
import { palette } from '@mongodb-js/compass-components' ;
6
5
import { useCallback } from 'react' ;
7
6
import { usePreference } from 'compass-preferences-model/provider' ;
7
+ import { useConnectionsColorList } from '../stores/store-context' ;
8
8
9
9
type ThemeProvider = {
10
10
getThemeOf (
@@ -16,20 +16,17 @@ type ThemeProvider = {
16
16
export function useTabConnectionTheme ( ) : ThemeProvider {
17
17
const { connectionColorToHex, connectionColorToHexActive } =
18
18
useConnectionColor ( ) ;
19
- const { getConnectionInfoById } = useConnectionRepository ( ) ;
19
+ const connectionColorsList = useConnectionsColorList ( ) ;
20
20
const darkTheme = useDarkMode ( ) ;
21
21
const isMultipleConnectionsEnabled = usePreference (
22
22
'enableMultipleConnectionSystem'
23
23
) ;
24
24
25
- // TODO: this method is not reactive and works only by accident, refactor the
26
- // hook to explicitly track changes to color in connections, otherwise the
27
- // value of the theme might be stale when we remove `useConnectionRepository`
28
- // hook completely
29
25
const getThemeOf = useCallback (
30
26
( connectionId : ConnectionInfo [ 'id' ] ) => {
31
- const connectionInfo = getConnectionInfoById ( connectionId ) ;
32
- const color = connectionInfo ?. favorite ?. color ;
27
+ const color = connectionColorsList . find ( ( connection ) => {
28
+ return connection . id === connectionId ;
29
+ } ) ?. color ;
33
30
const bgColor = connectionColorToHex ( color ) ;
34
31
const activeBgColor = connectionColorToHexActive ( color ) ;
35
32
@@ -70,7 +67,7 @@ export function useTabConnectionTheme(): ThemeProvider {
70
67
} ,
71
68
[
72
69
palette ,
73
- getConnectionInfoById ,
70
+ connectionColorsList ,
74
71
connectionColorToHex ,
75
72
connectionColorToHexActive ,
76
73
darkTheme ,
0 commit comments