11import { type ConnectionInfo } from '@mongodb-js/connection-info' ;
22import { useConnectionColor } from '@mongodb-js/connection-form' ;
3- import { useConnectionRepository } from './use-connection-repository' ;
43import { useDarkMode , type TabTheme } from '@mongodb-js/compass-components' ;
54import { palette } from '@mongodb-js/compass-components' ;
65import { useCallback } from 'react' ;
76import { usePreference } from 'compass-preferences-model/provider' ;
7+ import { useConnectionsColorList } from '../stores/store-context' ;
88
99type ThemeProvider = {
1010 getThemeOf (
@@ -16,20 +16,17 @@ type ThemeProvider = {
1616export function useTabConnectionTheme ( ) : ThemeProvider {
1717 const { connectionColorToHex, connectionColorToHexActive } =
1818 useConnectionColor ( ) ;
19- const { getConnectionInfoById } = useConnectionRepository ( ) ;
19+ const connectionColorsList = useConnectionsColorList ( ) ;
2020 const darkTheme = useDarkMode ( ) ;
2121 const isMultipleConnectionsEnabled = usePreference (
2222 'enableMultipleConnectionSystem'
2323 ) ;
2424
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
2925 const getThemeOf = useCallback (
3026 ( 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 ;
3330 const bgColor = connectionColorToHex ( color ) ;
3431 const activeBgColor = connectionColorToHexActive ( color ) ;
3532
@@ -70,7 +67,7 @@ export function useTabConnectionTheme(): ThemeProvider {
7067 } ,
7168 [
7269 palette ,
73- getConnectionInfoById ,
70+ connectionColorsList ,
7471 connectionColorToHex ,
7572 connectionColorToHexActive ,
7673 darkTheme ,
0 commit comments