11import  React ,  {  useCallback  }  from  'react' ; 
22import  {  connect  }  from  'react-redux' ; 
33import  { 
4-   withPreferences , 
54  usePreference , 
5+   withPreferences , 
66}  from  'compass-preferences-model/provider' ; 
77import  { 
88  Button , 
9-   ErrorSummary , 
10-   Tooltip , 
11-   WarningSummary , 
12-   Link , 
139  css , 
14-   spacing , 
10+   DropdownMenuButton , 
11+   ErrorSummary , 
1512  Icon , 
16-   SpinLoader , 
17-   SignalPopover , 
13+   Link , 
1814  PerformanceSignals , 
19-   DropdownMenuButton , 
2015  SegmentedControl , 
2116  SegmentedControlOption , 
17+   SignalPopover , 
18+   spacing , 
19+   SpinLoader , 
20+   Tooltip , 
2221}  from  '@mongodb-js/compass-components' ; 
2322import  {  useConnectionInfo  }  from  '@mongodb-js/compass-connections/provider' ; 
2423import  semver  from  'semver' ; 
2524
2625import  type  {  RootState  }  from  '../../modules' ; 
27- import  {  createSearchIndexOpened  }  from  '../../modules/search-indexes' ; 
26+ import  { 
27+   isVersionSearchCompatibleForViews , 
28+   createSearchIndexOpened , 
29+ }  from  '../../modules/search-indexes' ; 
2830import  {  getAtlasSearchIndexesLink  }  from  '../../utils/atlas-search-indexes-link' ; 
2931import  {  createIndexOpened  }  from  '../../modules/create-index' ; 
3032import  type  {  IndexView  }  from  '../../modules/index-view' ; 
@@ -109,7 +111,10 @@ export const IndexesToolbar: React.FunctionComponent<IndexesToolbarProps> = ({
109111  const  isSearchManagementActive  =  usePreference ( 'enableAtlasSearchIndexes' ) ; 
110112  const  {  atlasMetadata }  =  useConnectionInfo ( ) ; 
111113  const  showInsights  =  usePreference ( 'showInsights' )  &&  ! errorMessage ; 
112-   const  showCreateIndexButton  =  ! isReadonlyView  &&  ! readOnly  &&  ! errorMessage ; 
114+   const  showCreateIndexButton  = 
115+     ( ! isReadonlyView  ||  isVersionSearchCompatibleForViews ( serverVersion ) )  && 
116+     ! readOnly  && 
117+     ! errorMessage ; 
113118  const  refreshButtonIcon  =  isRefreshing  ? ( 
114119    < div  className = { spinnerStyles } > 
115120      < SpinLoader  title = "Refreshing Indexes"  /> 
@@ -123,7 +128,9 @@ export const IndexesToolbar: React.FunctionComponent<IndexesToolbarProps> = ({
123128      className = { indexesToolbarContainerStyles } 
124129      data-testid = "indexes-toolbar-container" 
125130    > 
126-       { ! isReadonlyView  &&  ( 
131+       { ( ! isReadonlyView  || 
132+         ( isVersionSearchCompatibleForViews ( serverVersion )  && 
133+           isSearchManagementActive ) )  &&  ( 
127134        < div  data-testid = "indexes-toolbar" > 
128135          < div  className = { toolbarButtonsContainer } > 
129136            { showCreateIndexButton  &&  ( 
@@ -139,7 +146,9 @@ export const IndexesToolbar: React.FunctionComponent<IndexesToolbarProps> = ({
139146                      isWritable = { isWritable } 
140147                      onCreateRegularIndexClick = { onCreateRegularIndexClick } 
141148                      onCreateSearchIndexClick = { onCreateSearchIndexClick } 
142-                     > </ CreateIndexButton > 
149+                       isReadonlyView = { isReadonlyView } 
150+                       indexView = { indexView } 
151+                     /> 
143152                  </ div > 
144153                } 
145154              > 
@@ -173,6 +182,7 @@ export const IndexesToolbar: React.FunctionComponent<IndexesToolbarProps> = ({
173182                signals = { PerformanceSignals . get ( 'too-many-indexes' ) } 
174183              /> 
175184            ) } 
185+ 
176186            { isSearchManagementActive  &&  ( 
177187              < SegmentedControl 
178188                size = "xsmall" 
@@ -182,13 +192,34 @@ export const IndexesToolbar: React.FunctionComponent<IndexesToolbarProps> = ({
182192                value = { indexView } 
183193                data-testid = "indexes-segment-controls" 
184194              > 
185-                 < SegmentedControlOption 
186-                   data-testid = "regular-indexes-tab" 
187-                   value = "regular-indexes" 
188-                 > 
189-                   Indexes
190-                 </ SegmentedControlOption > 
191-                 { ! isSearchIndexesSupported  &&  ( 
195+                 { isReadonlyView  &&  ( 
196+                   < Tooltip 
197+                     align = "top" 
198+                     justify = "end" 
199+                     enabled = { true } 
200+                     renderMode = "portal" 
201+                     trigger = { 
202+                       < SegmentedControlOption 
203+                         data-testid = "regular-indexes-tab" 
204+                         value = "regular-indexes" 
205+                         disabled = { isReadonlyView } 
206+                       > 
207+                         Indexes
208+                       </ SegmentedControlOption > 
209+                     } 
210+                   > 
211+                     Readonly views may not contain standard indexes.
212+                   </ Tooltip > 
213+                 ) } 
214+                 { ! isReadonlyView  &&  ( 
215+                   < SegmentedControlOption 
216+                     data-testid = "regular-indexes-tab" 
217+                     value = "regular-indexes" 
218+                   > 
219+                     Indexes
220+                   </ SegmentedControlOption > 
221+                 ) } 
222+                 { ! isSearchIndexesSupported  &&  ! isReadonlyView  &&  ( 
192223                  < Tooltip 
193224                    align = "top" 
194225                    justify = "end" 
@@ -227,7 +258,7 @@ export const IndexesToolbar: React.FunctionComponent<IndexesToolbarProps> = ({
227258                    ) } 
228259                  </ Tooltip > 
229260                ) } 
230-                 { isSearchIndexesSupported  &&  ( 
261+                 { ( isSearchIndexesSupported   ||   isReadonlyView )  &&  ( 
231262                  < SegmentedControlOption 
232263                    data-testid = "search-indexes-tab" 
233264                    value = "search-indexes" 
@@ -240,14 +271,8 @@ export const IndexesToolbar: React.FunctionComponent<IndexesToolbarProps> = ({
240271          </ div > 
241272        </ div > 
242273      ) } 
243-       { isReadonlyView  ? ( 
244-         < WarningSummary 
245-           warnings = { [ 'Readonly views may not contain indexes.' ] } 
246-         /> 
247-       )  : ( 
248-         ! ! errorMessage  &&  ( 
249-           < ErrorSummary  data-testid = "indexes-error"  errors = { [ errorMessage ] }  /> 
250-         ) 
274+       { ! ! errorMessage  &&  isSearchManagementActive  &&  ( 
275+         < ErrorSummary  data-testid = "indexes-error"  errors = { [ errorMessage ] }  /> 
251276      ) } 
252277    </ div > 
253278  ) ; 
@@ -259,6 +284,8 @@ type CreateIndexButtonProps = {
259284  isWritable : boolean ; 
260285  onCreateRegularIndexClick : ( )  =>  void ; 
261286  onCreateSearchIndexClick : ( )  =>  void ; 
287+   isReadonlyView : boolean ; 
288+   indexView : IndexView ; 
262289} ; 
263290
264291type  CreateIndexActions  =  'createRegularIndex'  |  'createSearchIndex' ; 
@@ -271,6 +298,8 @@ export const CreateIndexButton: React.FunctionComponent<
271298  isWritable, 
272299  onCreateRegularIndexClick, 
273300  onCreateSearchIndexClick, 
301+   isReadonlyView, 
302+   indexView, 
274303} )  =>  { 
275304  const  onActionDispatch  =  useCallback ( 
276305    ( action : CreateIndexActions )  =>  { 
@@ -284,7 +313,23 @@ export const CreateIndexButton: React.FunctionComponent<
284313    [ onCreateRegularIndexClick ,  onCreateSearchIndexClick ] 
285314  ) ; 
286315
287-   if  ( isSearchIndexesSupported  &&  isSearchManagementActive )  { 
316+   if  ( isReadonlyView  &&  isSearchManagementActive )  { 
317+     if  ( indexView  ===  'search-indexes' )  { 
318+       return  ( 
319+         < Button 
320+           disabled = { ! isWritable } 
321+           onClick = { onCreateSearchIndexClick } 
322+           variant = "primary" 
323+           size = "small" 
324+         > 
325+           Create Search Index
326+         </ Button > 
327+       ) ; 
328+     } 
329+ 
330+     return  null ; 
331+   } 
332+   if  ( ! isReadonlyView  &&  isSearchIndexesSupported  &&  isSearchManagementActive )  { 
288333    return  ( 
289334      < DropdownMenuButton 
290335        data-testid = "multiple-index-types-creation-dropdown" 
0 commit comments