Skip to content

Commit 0b4ab54

Browse files
add banners to indexes tab
1 parent e7e965d commit 0b4ab54

File tree

2 files changed

+116
-18
lines changed

2 files changed

+116
-18
lines changed

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

Lines changed: 109 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,25 @@
11
import React, { useCallback } from 'react';
22
import { connect } from 'react-redux';
33
import {
4-
withPreferences,
54
usePreference,
5+
withPreferences,
66
} from 'compass-preferences-model/provider';
77
import {
8+
Banner,
9+
BannerVariant,
810
Button,
9-
ErrorSummary,
10-
Tooltip,
11-
WarningSummary,
12-
Link,
1311
css,
14-
spacing,
12+
DropdownMenuButton,
13+
ErrorSummary,
1514
Icon,
16-
SpinLoader,
17-
SignalPopover,
15+
Link,
1816
PerformanceSignals,
19-
DropdownMenuButton,
2017
SegmentedControl,
2118
SegmentedControlOption,
19+
SignalPopover,
20+
spacing,
21+
SpinLoader,
22+
Tooltip,
2223
} from '@mongodb-js/compass-components';
2324
import { useConnectionInfo } from '@mongodb-js/compass-connections/provider';
2425
import semver from 'semver';
@@ -29,6 +30,7 @@ import { getAtlasSearchIndexesLink } from '../../utils/atlas-search-indexes-link
2930
import { createIndexOpened } from '../../modules/create-index';
3031
import type { IndexView } from '../../modules/index-view';
3132
import { indexViewChanged } from '../../modules/index-view';
33+
import { getAtlasUpgradeClusterLink } from '../../utils/atlas-upgrade-cluster-link';
3234

3335
const toolbarButtonsContainer = css({
3436
display: 'flex',
@@ -54,6 +56,15 @@ const createIndexButtonContainerStyles = css({
5456
width: 'fit-content',
5557
});
5658

59+
const viewContentStyles = css({
60+
display: 'flex',
61+
justifyContent: 'space-between',
62+
alignItems: 'center',
63+
width: '100%',
64+
//alignItems: 'flex-end',
65+
//gap: spacing[200],
66+
});
67+
5768
const MIN_SEARCH_INDEX_MANAGEMENT_SERVER_VERSION = '6.0.7';
5869

5970
const serverSupportsSearchIndexManagement = (serverVersion: string) => {
@@ -110,6 +121,7 @@ export const IndexesToolbar: React.FunctionComponent<IndexesToolbarProps> = ({
110121
const { atlasMetadata } = useConnectionInfo();
111122
const showInsights = usePreference('showInsights') && !errorMessage;
112123
const showCreateIndexButton = !isReadonlyView && !readOnly && !errorMessage;
124+
const mongoDBMajorVersion = serverVersion.split('.').slice(0, 2).join('.');
113125
const refreshButtonIcon = isRefreshing ? (
114126
<div className={spinnerStyles}>
115127
<SpinLoader title="Refreshing Indexes" />
@@ -118,6 +130,89 @@ export const IndexesToolbar: React.FunctionComponent<IndexesToolbarProps> = ({
118130
<Icon glyph="Refresh" title="Refresh Indexes" />
119131
);
120132

133+
const renderViewBanner = (
134+
serverVersion: string,
135+
mongoDBMajorVersion: string
136+
) => {
137+
const version = parseFloat(mongoDBMajorVersion);
138+
if (version < 8.0) {
139+
return (
140+
<Banner variant={BannerVariant.Warning}>
141+
<b>Looking for search indexes?</b>
142+
<br />
143+
<div className={viewContentStyles}>
144+
<span>
145+
Your MongoDB version is {serverVersion}. Creating and managing
146+
search indexes on views in Compass is supported on MongoDB version
147+
8.1 or higher. Upgrade your cluster to create search indexes on
148+
views.
149+
</span>
150+
{atlasMetadata && (
151+
<Button
152+
size="xsmall"
153+
onClick={() => {
154+
window.open(
155+
getAtlasUpgradeClusterLink({
156+
clusterName: atlasMetadata.clusterName,
157+
}),
158+
'_blank'
159+
);
160+
}}
161+
>
162+
Upgrade Cluster
163+
</Button>
164+
)}
165+
</div>
166+
</Banner>
167+
);
168+
}
169+
170+
if (version === 8.0) {
171+
return (
172+
<Banner variant={BannerVariant.Warning}>
173+
<b>Looking for search indexes?</b>
174+
<br />
175+
<div className={viewContentStyles}>
176+
<span>
177+
Your MongoDB version is {serverVersion}. Creating and managing
178+
search indexes on views in Compass is supported on MongoDB version
179+
8.1 or higher. Upgrade your cluster or manage search indexes on
180+
views in the Atlas UI.
181+
</span>
182+
{atlasMetadata && (
183+
<Button
184+
size="xsmall"
185+
onClick={() => {
186+
window.open(
187+
getAtlasSearchIndexesLink({
188+
clusterName: atlasMetadata.clusterName,
189+
namespace,
190+
}),
191+
'_blank'
192+
);
193+
}}
194+
>
195+
Go to Atlas
196+
</Button>
197+
)}
198+
</div>
199+
</Banner>
200+
);
201+
}
202+
if (version > 8.0) {
203+
return (
204+
<Banner variant={BannerVariant.Warning}>
205+
<b>Looking for search indexes?</b>
206+
<br />
207+
This view is incompatible with search indexes. To use search indexes,
208+
edit the view to only contain $addFields, $set, or $match stages with
209+
the $expr operator. You can view all search indexes under INSERT LINK.
210+
</Banner>
211+
);
212+
}
213+
return null;
214+
};
215+
121216
return (
122217
<div
123218
className={indexesToolbarContainerStyles}
@@ -240,15 +335,11 @@ export const IndexesToolbar: React.FunctionComponent<IndexesToolbarProps> = ({
240335
</div>
241336
</div>
242337
)}
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-
)
251-
)}
338+
{isReadonlyView
339+
? renderViewBanner(serverVersion, mongoDBMajorVersion)
340+
: !!errorMessage && (
341+
<ErrorSummary data-testid="indexes-error" errors={[errorMessage]} />
342+
)}
252343
</div>
253344
);
254345
};
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export function getAtlasUpgradeClusterLink({
2+
clusterName,
3+
}: {
4+
clusterName: string;
5+
}) {
6+
return `#/clusters/edit/${encodeURIComponent(clusterName)}`;
7+
}

0 commit comments

Comments
 (0)