1- import React , { useCallback } from 'react' ;
1+ import React , { useCallback , useEffect } from 'react' ;
22import { connect } from 'react-redux' ;
33import {
44 usePreference ,
@@ -25,7 +25,7 @@ import type { RootState } from '../../modules';
2525import { createSearchIndexOpened } from '../../modules/search-indexes' ;
2626import { getAtlasSearchIndexesLink } from '../../utils/atlas-search-indexes-link' ;
2727import { createIndexOpened } from '../../modules/create-index' ;
28- import type { IndexView } from '../../modules/index-view' ;
28+ import { IndexView } from '../../modules/index-view' ;
2929import { indexViewChanged } from '../../modules/index-view' ;
3030
3131const toolbarButtonsContainer = css ( {
@@ -111,10 +111,10 @@ export const IndexesToolbar: React.FunctionComponent<IndexesToolbarProps> = ({
111111 const { atlasMetadata } = useConnectionInfo ( ) ;
112112 const showInsights = usePreference ( 'showInsights' ) && ! errorMessage ;
113113 const showCreateIndexButton =
114- mongoDBMajorVersion > 8.0 && ! readOnly && ! errorMessage ;
114+ ( ! isReadonlyView || mongoDBMajorVersion > 8.0 ) && ! errorMessage ;
115115 const showRefreshButton =
116- ! isReadonlyView ||
117- ( mongoDBMajorVersion > 8.0 && indexView === 'search-indexes' ) ;
116+ ( ! isReadonlyView || mongoDBMajorVersion > 8.0 ) &&
117+ indexView === 'search-indexes' ;
118118 const refreshButtonIcon = isRefreshing ? (
119119 < div className = { spinnerStyles } >
120120 < SpinLoader title = "Refreshing Indexes" />
@@ -123,12 +123,19 @@ export const IndexesToolbar: React.FunctionComponent<IndexesToolbarProps> = ({
123123 < Icon glyph = "Refresh" title = "Refresh Indexes" />
124124 ) ;
125125
126+ useEffect ( ( ) => {
127+ // If the view is readonly, set the default tab to 'search-indexes'
128+ if ( isReadonlyView ) {
129+ onIndexViewChanged ( 'search-indexes' ) ; // Update the Redux state
130+ }
131+ } , [ isReadonlyView , indexView ] ) ;
132+
126133 return (
127134 < div
128135 className = { indexesToolbarContainerStyles }
129136 data-testid = "indexes-toolbar-container"
130137 >
131- { mongoDBMajorVersion > 8.0 && (
138+ { ( ! isReadonlyView || mongoDBMajorVersion > 8.0 ) && (
132139 < div data-testid = "indexes-toolbar" >
133140 < div className = { toolbarButtonsContainer } >
134141 { showCreateIndexButton && (
@@ -188,17 +195,34 @@ export const IndexesToolbar: React.FunctionComponent<IndexesToolbarProps> = ({
188195 onChange = { ( evt ) => onIndexViewChanged ( evt as IndexView ) }
189196 className = { alignSelfEndStyles }
190197 label = "Viewing"
191- value = { indexView }
198+ value = { isReadonlyView ? 'search-indexes' : indexView }
192199 data-testid = "indexes-segment-controls"
193200 >
194- < SegmentedControlOption // NEED TOOLTIP
195- data-testid = "regular-indexes-tab"
196- value = "regular-indexes"
197- disabled = { isReadonlyView }
201+ < Tooltip
202+ align = "top"
203+ justify = "end"
204+ enabled = { true }
205+ renderMode = "portal"
206+ trigger = {
207+ < SegmentedControlOption
208+ data-testid = "regular-indexes-tab"
209+ value = "regular-indexes"
210+ disabled = { isReadonlyView }
211+ >
212+ Indexes
213+ </ SegmentedControlOption >
214+ }
198215 >
199- Indexes
200- </ SegmentedControlOption >
201- { /* {!isSearchIndexesSupported && (
216+ Readonly views may not contain standard indexes.
217+ </ Tooltip >
218+ { serverSupportsSearchIndexManagement ( serverVersion ) ? (
219+ < SegmentedControlOption
220+ data-testid = "search-indexes-tab"
221+ value = "search-indexes"
222+ >
223+ Search Indexes
224+ </ SegmentedControlOption >
225+ ) : (
202226 < Tooltip
203227 align = "top"
204228 justify = "end"
@@ -214,36 +238,20 @@ export const IndexesToolbar: React.FunctionComponent<IndexesToolbarProps> = ({
214238 </ SegmentedControlOption >
215239 }
216240 >
217- {serverSupportsSearchIndexManagement(serverVersion) ? (
241+ < >
218242 < p >
219- Unable to fetch search indexes. This can occur when your
220- cluster does not support search indexes or the request
221- to list search indexes failed .
243+ Atlas Search index management in Compass is only
244+ available for Atlas local deployments and clusters
245+ running MongoDB 6.0.7 or newer .
222246 </ p >
223- ) : (
224- <>
225- <p>
226- Atlas Search index management in Compass is only
227- available for Atlas local deployments and clusters
228- running MongoDB 6.0.7 or newer.
229- </p>
230- <p>
231- For clusters running an earlier version of MongoDB,
232- you can manage your Atlas Search indexes from the
233- Atlas web Ul, with the CLI, or with the Administration
234- API.
235- </p>
236- </>
237- )}
247+ < p >
248+ For clusters running an earlier version of MongoDB, you
249+ can manage your Atlas Search indexes from the Atlas web
250+ Ul, with the CLI, or with the Administration API.
251+ </ p >
252+ </ >
238253 </ Tooltip >
239- )}*/ }
240-
241- < SegmentedControlOption
242- data-testid = "search-indexes-tab"
243- value = "search-indexes"
244- >
245- Search Indexes
246- </ SegmentedControlOption >
254+ ) }
247255 </ SegmentedControl >
248256 ) }
249257 </ div >
0 commit comments