@@ -3,6 +3,7 @@ import { cloneDeep } from 'lodash';
33import { connect } from 'react-redux' ;
44import { getConnectionTitle } from 'mongodb-data-service' ;
55import type { ConnectionInfo } from 'mongodb-data-service' ;
6+ import type { MongoDBInstance } from 'mongodb-instance-model' ;
67import {
78 css ,
89 spacing ,
@@ -24,7 +25,7 @@ import NonGenuineMarker from './non-genuine-marker';
2425
2526import { updateAndSaveConnectionInfo } from '../modules/connection-info' ;
2627import { toggleIsGenuineMongoDBVisible } from '../modules/is-genuine-mongodb-visible' ;
27- import type { MongoDBInstance } from 'mongodb-instance-model ' ;
28+ import { setIsExpanded } from '../modules/is-expanded ' ;
2829
2930const TOAST_TIMEOUT_MS = 5000 ; // 5 seconds.
3031
@@ -35,26 +36,29 @@ const badgesPlaceholderStyles = css({
3536
3637// eslint-disable-next-line no-empty-pattern
3738export function Sidebar ( {
39+ isExpanded,
3840 connectionInfo,
3941 globalAppRegistryEmit,
4042 updateAndSaveConnectionInfo,
4143 isGenuineMongoDBVisible,
4244 toggleIsGenuineMongoDBVisible,
45+ setIsExpanded,
4346 isGenuine,
4447 csfleMode,
4548} : {
49+ isExpanded : boolean ;
4650 connectionInfo : ConnectionInfo ;
4751 globalAppRegistryEmit : any ;
4852 updateAndSaveConnectionInfo : any ;
4953 isGenuineMongoDBVisible : boolean ;
5054 toggleIsGenuineMongoDBVisible : ( isVisible : boolean ) => void ;
55+ setIsExpanded : ( isExpanded : boolean ) => void ;
5156 isGenuine ?: boolean ;
5257 csfleMode ?: 'enabled' | 'disabled' | 'unavailable' ;
5358} ) {
5459 const [ isFavoriteModalVisible , setIsFavoriteModalVisible ] = useState ( false ) ;
5560 const [ isConnectionInfoModalVisible , setIsConnectionInfoModalVisible ] =
5661 useState ( false ) ;
57- const [ isExpanded ] = useState ( true ) ;
5862
5963 const onClickSaveFavorite = useCallback (
6064 ( newFavoriteInfo ) => {
@@ -108,10 +112,16 @@ export function Sidebar({
108112 return ;
109113 }
110114
115+ if ( action === 'expand-sidebar' ) {
116+ setIsExpanded ( true ) ;
117+ return ;
118+ }
119+
111120 globalAppRegistryEmit ( action , ...rest ) ;
112121 } ,
113122 [
114123 connectionInfo . connectionOptions . connectionString ,
124+ setIsExpanded ,
115125 globalAppRegistryEmit ,
116126 openToast ,
117127 ]
@@ -135,7 +145,11 @@ export function Sidebar({
135145 ) ;
136146
137147 return (
138- < ResizableSidebar >
148+ < ResizableSidebar
149+ collapsable = { true }
150+ expanded = { isExpanded }
151+ setExpanded = { setIsExpanded }
152+ >
139153 < >
140154 < SidebarTitle
141155 title = { getConnectionTitle ( connectionInfo ) }
@@ -190,12 +204,14 @@ export function Sidebar({
190204}
191205
192206const mapStateToProps = ( state : {
207+ isExpanded : boolean ;
193208 connectionInfo : {
194209 connectionInfo : ConnectionInfo ;
195210 } ;
196211 isGenuineMongoDBVisible : boolean ;
197212 instance ?: MongoDBInstance ;
198213} ) => ( {
214+ isExpanded : state . isExpanded ,
199215 connectionInfo : state . connectionInfo . connectionInfo ,
200216 isGenuineMongoDBVisible : state . isGenuineMongoDBVisible ,
201217 isGenuine : state . instance ?. genuineMongoDB . isGenuine ,
@@ -206,6 +222,7 @@ const MappedSidebar = connect(mapStateToProps, {
206222 globalAppRegistryEmit,
207223 updateAndSaveConnectionInfo,
208224 toggleIsGenuineMongoDBVisible,
225+ setIsExpanded,
209226} ) ( Sidebar ) ;
210227
211228export default MappedSidebar ;
0 commit comments