Skip to content

Commit b1e7351

Browse files
JimmyChoiMDBJimmy ChoiAnemy
authored
fix(compass-indexes): update tooltip when server version should support search indexes but fetch fails COMPASS-9378 (#7122)
* initial commit * wrap in try/catch * default false * update phrasing Co-authored-by: Rhys <[email protected]> --------- Co-authored-by: Jimmy Choi <[email protected]> Co-authored-by: Rhys <[email protected]>
1 parent 01668f8 commit b1e7351

File tree

2 files changed

+38
-10
lines changed

2 files changed

+38
-10
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ describe('IndexesToolbar Component', function () {
4444
onCreateSearchIndexClick={() => {}}
4545
namespace=""
4646
showAtlasSearchLink={false}
47+
serverVersion={'8.0.11'}
4748
{...props}
4849
/>
4950
</PreferencesProvider>

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

Lines changed: 37 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import {
2121
SegmentedControlOption,
2222
} from '@mongodb-js/compass-components';
2323
import { useConnectionInfo } from '@mongodb-js/compass-connections/provider';
24+
import semver from 'semver';
2425

2526
import type { RootState } from '../../modules';
2627
import { createSearchIndexOpened } from '../../modules/search-indexes';
@@ -53,6 +54,19 @@ const createIndexButtonContainerStyles = css({
5354
width: 'fit-content',
5455
});
5556

57+
const MIN_SEARCH_INDEX_MANAGEMENT_SERVER_VERSION = '6.0.7';
58+
59+
const serverSupportsSearchIndexManagement = (serverVersion: string) => {
60+
try {
61+
return semver.gte(
62+
serverVersion,
63+
MIN_SEARCH_INDEX_MANAGEMENT_SERVER_VERSION
64+
);
65+
} catch {
66+
return false;
67+
}
68+
};
69+
5670
type IndexesToolbarProps = {
5771
namespace: string;
5872
indexView: IndexView;
@@ -62,6 +76,7 @@ type IndexesToolbarProps = {
6276
isRefreshing: boolean;
6377
onRefreshIndexes: () => void;
6478
onIndexViewChanged: (newView: IndexView) => void;
79+
serverVersion: string;
6580
// connected:
6681
isReadonlyView: boolean;
6782
isWritable: boolean;
@@ -88,6 +103,7 @@ export const IndexesToolbar: React.FunctionComponent<IndexesToolbarProps> = ({
88103
isSearchIndexesSupported,
89104
onRefreshIndexes,
90105
onIndexViewChanged,
106+
serverVersion,
91107
readOnly, // preferences readOnly.
92108
}) => {
93109
const isSearchManagementActive = usePreference('enableAtlasSearchIndexes');
@@ -188,16 +204,27 @@ export const IndexesToolbar: React.FunctionComponent<IndexesToolbarProps> = ({
188204
</SegmentedControlOption>
189205
}
190206
>
191-
<p>
192-
Atlas Search index management in Compass is only available
193-
for Atlas local deployments and clusters running MongoDB
194-
6.0.7 or newer.
195-
</p>
196-
<p>
197-
For clusters running an earlier version of MongoDB, you
198-
can manage your Atlas Search indexes from the Atlas web
199-
Ul, with the CLI, or with the Administration API.
200-
</p>
207+
{serverSupportsSearchIndexManagement(serverVersion) ? (
208+
<p>
209+
Unable to fetch search indexes. This can occur when your
210+
cluster does not support search indexes or the request
211+
to list search indexes failed.
212+
</p>
213+
) : (
214+
<>
215+
<p>
216+
Atlas Search index management in Compass is only
217+
available for Atlas local deployments and clusters
218+
running MongoDB 6.0.7 or newer.
219+
</p>
220+
<p>
221+
For clusters running an earlier version of MongoDB,
222+
you can manage your Atlas Search indexes from the
223+
Atlas web Ul, with the CLI, or with the Administration
224+
API.
225+
</p>
226+
</>
227+
)}
201228
</Tooltip>
202229
)}
203230
{isSearchIndexesSupported && (

0 commit comments

Comments
 (0)