Skip to content

Commit 6961789

Browse files
move function
1 parent 73b536b commit 6961789

File tree

4 files changed

+39
-33
lines changed

4 files changed

+39
-33
lines changed

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,14 @@ import { useConnectionInfo } from '@mongodb-js/compass-connections/provider';
2323
import semver from 'semver';
2424

2525
import type { RootState } from '../../modules';
26-
import { createSearchIndexOpened } from '../../modules/search-indexes';
26+
import {
27+
compareVersionForViewSearchCompatibility,
28+
createSearchIndexOpened,
29+
} from '../../modules/search-indexes';
2730
import { getAtlasSearchIndexesLink } from '../../utils/atlas-search-indexes-link';
2831
import { createIndexOpened } from '../../modules/create-index';
2932
import type { IndexView } from '../../modules/index-view';
3033
import { indexViewChanged } from '../../modules/index-view';
31-
import { compareVersionForViewCompatibility } from '../indexes/indexes';
3234

3335
const toolbarButtonsContainer = css({
3436
display: 'flex',
@@ -110,7 +112,8 @@ export const IndexesToolbar: React.FunctionComponent<IndexesToolbarProps> = ({
110112
const { atlasMetadata } = useConnectionInfo();
111113
const showInsights = usePreference('showInsights') && !errorMessage;
112114
const showCreateIndexButton =
113-
(!isReadonlyView || compareVersionForViewCompatibility(serverVersion)) &&
115+
(!isReadonlyView ||
116+
compareVersionForViewSearchCompatibility(serverVersion)) &&
114117
!readOnly &&
115118
!errorMessage;
116119
const refreshButtonIcon = isRefreshing ? (
@@ -127,7 +130,7 @@ export const IndexesToolbar: React.FunctionComponent<IndexesToolbarProps> = ({
127130
data-testid="indexes-toolbar-container"
128131
>
129132
{(!isReadonlyView ||
130-
compareVersionForViewCompatibility(serverVersion)) && (
133+
compareVersionForViewSearchCompatibility(serverVersion)) && (
131134
<div data-testid="indexes-toolbar">
132135
<div className={toolbarButtonsContainer}>
133136
{showCreateIndexButton && (

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

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@ import IndexesToolbar from '../indexes-toolbar/indexes-toolbar';
1515
import RegularIndexesTable from '../regular-indexes-table/regular-indexes-table';
1616
import SearchIndexesTable from '../search-indexes-table/search-indexes-table';
1717
import { refreshRegularIndexes } from '../../modules/regular-indexes';
18-
import { refreshSearchIndexes } from '../../modules/search-indexes';
18+
import {
19+
compareVersionForViewSearchCompatibility,
20+
refreshSearchIndexes,
21+
} from '../../modules/search-indexes';
1922
import type { State as RegularIndexesState } from '../../modules/regular-indexes';
2023
import type { State as SearchIndexesState } from '../../modules/search-indexes';
2124
import { FetchStatuses } from '../../utils/fetch-status';
@@ -32,7 +35,6 @@ import { getAtlasSearchIndexesLink } from '../../utils/atlas-search-indexes-link
3235
import CreateIndexModal from '../create-index-modal/create-index-modal';
3336
import { ZeroGraphic } from '../search-indexes-table/zero-graphic';
3437
import { ViewVersionIncompatibleBanner } from '../view-version-incompatible-banners/view-version-incompatible-banners';
35-
import semver from 'semver';
3638

3739
// This constant is used as a trigger to show an insight whenever number of
3840
// indexes in a collection is more than what is specified here.
@@ -52,20 +54,6 @@ const linkTitle = 'Search and Vector Search.';
5254
const DISMISSED_SEARCH_INDEXES_BANNER_LOCAL_STORAGE_KEY =
5355
'mongodb_compass_dismissedSearchIndexesBanner' as const;
5456

55-
const MIN_VERSION_FOR_VIEW_SEARCH_COMPATIBILITY_COMPASS = '8.1.0';
56-
export const compareVersionForViewCompatibility = (
57-
//default to 8.1+
58-
serverVersion: string,
59-
comparator: 'gt' | 'gte' | 'lt' | 'lte' = 'gte',
60-
compareVersion: string = MIN_VERSION_FOR_VIEW_SEARCH_COMPATIBILITY_COMPASS
61-
) => {
62-
try {
63-
return semver[comparator](serverVersion, compareVersion);
64-
} catch {
65-
return false;
66-
}
67-
};
68-
6957
const ViewVersionIncompatibleEmptyState = ({
7058
serverVersion,
7159
enableAtlasSearchIndexes,
@@ -74,7 +62,7 @@ const ViewVersionIncompatibleEmptyState = ({
7462
enableAtlasSearchIndexes: boolean;
7563
}) => {
7664
if (
77-
compareVersionForViewCompatibility(serverVersion) &&
65+
compareVersionForViewSearchCompatibility(serverVersion) &&
7866
enableAtlasSearchIndexes
7967
) {
8068
return null;
@@ -222,7 +210,7 @@ export function Indexes({
222210
/>
223211
)}
224212
{(!isReadonlyView ||
225-
compareVersionForViewCompatibility(serverVersion, 'gte')) &&
213+
compareVersionForViewSearchCompatibility(serverVersion, 'gte')) &&
226214
!enableAtlasSearchIndexes && (
227215
<AtlasIndexesBanner
228216
namespace={namespace}
@@ -236,7 +224,7 @@ export function Indexes({
236224
<RegularIndexesTable />
237225
)}
238226
{(!isReadonlyView ||
239-
compareVersionForViewCompatibility(serverVersion)) &&
227+
compareVersionForViewSearchCompatibility(serverVersion)) &&
240228
currentIndexesView === 'search-indexes' && <SearchIndexesTable />}
241229
{isReadonlyView && searchIndexes.indexes.length === 0 && (
242230
<ViewVersionIncompatibleEmptyState

packages/compass-indexes/src/components/view-version-incompatible-banners/view-version-incompatible-banners.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
import { getAtlasUpgradeClusterLink } from '../../utils/atlas-upgrade-cluster-link';
88
import React from 'react';
99
import type { AtlasClusterMetadata } from '@mongodb-js/connection-info';
10-
import { compareVersionForViewCompatibility } from '../indexes/indexes';
10+
import { compareVersionForViewSearchCompatibility } from '../../modules/search-indexes';
1111

1212
const viewContentStyles = css({
1313
display: 'flex',
@@ -28,15 +28,15 @@ export const ViewVersionIncompatibleBanner = ({
2828
const searchIndexOnViewsVersion = enableAtlasSearchIndexes ? '8.1' : '8.0';
2929

3030
if (
31-
compareVersionForViewCompatibility(serverVersion) ||
32-
(compareVersionForViewCompatibility(serverVersion, 'gte', '8.0.0') &&
31+
compareVersionForViewSearchCompatibility(serverVersion) ||
32+
(compareVersionForViewSearchCompatibility(serverVersion, 'gte', '8.0.0') &&
3333
!enableAtlasSearchIndexes)
3434
) {
3535
// return if 8.1+ on compass or 8.0+ for data explorer
3636
return null;
3737
}
3838

39-
if (compareVersionForViewCompatibility(serverVersion, 'lt', '8.0.0')) {
39+
if (compareVersionForViewSearchCompatibility(serverVersion, 'lt', '8.0.0')) {
4040
// data explorer <8.0 and compass <8.0
4141
return (
4242
<Banner
@@ -73,8 +73,8 @@ export const ViewVersionIncompatibleBanner = ({
7373
}
7474

7575
if (
76-
compareVersionForViewCompatibility(serverVersion, 'gte', '8.0.0') &&
77-
compareVersionForViewCompatibility(serverVersion, 'lt', '8.1.0') &&
76+
compareVersionForViewSearchCompatibility(serverVersion, 'gte', '8.0.0') &&
77+
compareVersionForViewSearchCompatibility(serverVersion, 'lt', '8.1.0') &&
7878
enableAtlasSearchIndexes
7979
) {
8080
// compass 8.0

packages/compass-indexes/src/modules/search-indexes.ts

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,31 @@ const ATLAS_SEARCH_SERVER_ERRORS: Record<string, string> = {
2525
'This index name is already in use. Please choose another one.',
2626
};
2727

28-
const MIN_VERSION_FOR_VIEW_SEARCH_COMPATIBILITY_COMPASS = '8.1.0';
28+
/*const MIN_VERSION_FOR_VIEW_SEARCH_COMPATIBILITY_COMPASS = '8.1.0';
2929
3030
const isVersionSearchCompatibleForViews = (serverVersion: string) => {
3131
try {
3232
return semver.gte(
33-
serverVersion,
34-
MIN_VERSION_FOR_VIEW_SEARCH_COMPATIBILITY_COMPASS
33+
serverVersion,
34+
MIN_VERSION_FOR_VIEW_SEARCH_COMPATIBILITY_COMPASS
3535
);
3636
} catch {
3737
return false;
3838
}
39+
};*/
40+
41+
const MIN_VERSION_FOR_VIEW_SEARCH_COMPATIBILITY_COMPASS = '8.1.0';
42+
export const compareVersionForViewSearchCompatibility = (
43+
//default to 8.1+
44+
serverVersion: string,
45+
comparator: 'gt' | 'gte' | 'lt' | 'lte' = 'gte',
46+
compareVersion: string = MIN_VERSION_FOR_VIEW_SEARCH_COMPATIBILITY_COMPASS
47+
) => {
48+
try {
49+
return semver[comparator](serverVersion, compareVersion);
50+
} catch {
51+
return false;
52+
}
3953
};
4054

4155
export enum ActionTypes {
@@ -621,7 +635,8 @@ const fetchIndexes = (
621635
} = getState();
622636

623637
if (
624-
(isReadonlyView && !isVersionSearchCompatibleForViews(serverVersion)) ||
638+
(isReadonlyView &&
639+
!compareVersionForViewSearchCompatibility(serverVersion)) ||
625640
!isWritable
626641
) {
627642
return; // return if view is not search compatible

0 commit comments

Comments
 (0)