Skip to content

Commit 8cc8504

Browse files
fix indexes-toolbar
1 parent 6bc7021 commit 8cc8504

File tree

1 file changed

+49
-41
lines changed

1 file changed

+49
-41
lines changed

packages/compass-indexes/src/components/indexes-toolbar/indexes-toolbar.tsx

Lines changed: 49 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useCallback } from 'react';
1+
import React, { useCallback, useEffect } from 'react';
22
import { connect } from 'react-redux';
33
import {
44
usePreference,
@@ -25,7 +25,7 @@ import type { RootState } from '../../modules';
2525
import { createSearchIndexOpened } from '../../modules/search-indexes';
2626
import { getAtlasSearchIndexesLink } from '../../utils/atlas-search-indexes-link';
2727
import { createIndexOpened } from '../../modules/create-index';
28-
import type { IndexView } from '../../modules/index-view';
28+
import { IndexView } from '../../modules/index-view';
2929
import { indexViewChanged } from '../../modules/index-view';
3030

3131
const 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

Comments
 (0)