Skip to content

Commit 0c96520

Browse files
update banner to include data explorer versions
1 parent 0b4ab54 commit 0c96520

File tree

3 files changed

+180
-110
lines changed

3 files changed

+180
-110
lines changed

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

Lines changed: 0 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,9 @@ import {
55
withPreferences,
66
} from 'compass-preferences-model/provider';
77
import {
8-
Banner,
9-
BannerVariant,
108
Button,
119
css,
1210
DropdownMenuButton,
13-
ErrorSummary,
1411
Icon,
1512
Link,
1613
PerformanceSignals,
@@ -30,7 +27,6 @@ import { getAtlasSearchIndexesLink } from '../../utils/atlas-search-indexes-link
3027
import { createIndexOpened } from '../../modules/create-index';
3128
import type { IndexView } from '../../modules/index-view';
3229
import { indexViewChanged } from '../../modules/index-view';
33-
import { getAtlasUpgradeClusterLink } from '../../utils/atlas-upgrade-cluster-link';
3430

3531
const toolbarButtonsContainer = css({
3632
display: 'flex',
@@ -56,15 +52,6 @@ const createIndexButtonContainerStyles = css({
5652
width: 'fit-content',
5753
});
5854

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-
6855
const MIN_SEARCH_INDEX_MANAGEMENT_SERVER_VERSION = '6.0.7';
6956

7057
const serverSupportsSearchIndexManagement = (serverVersion: string) => {
@@ -121,7 +108,6 @@ export const IndexesToolbar: React.FunctionComponent<IndexesToolbarProps> = ({
121108
const { atlasMetadata } = useConnectionInfo();
122109
const showInsights = usePreference('showInsights') && !errorMessage;
123110
const showCreateIndexButton = !isReadonlyView && !readOnly && !errorMessage;
124-
const mongoDBMajorVersion = serverVersion.split('.').slice(0, 2).join('.');
125111
const refreshButtonIcon = isRefreshing ? (
126112
<div className={spinnerStyles}>
127113
<SpinLoader title="Refreshing Indexes" />
@@ -130,89 +116,6 @@ export const IndexesToolbar: React.FunctionComponent<IndexesToolbarProps> = ({
130116
<Icon glyph="Refresh" title="Refresh Indexes" />
131117
);
132118

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-
216119
return (
217120
<div
218121
className={indexesToolbarContainerStyles}
@@ -335,11 +238,6 @@ export const IndexesToolbar: React.FunctionComponent<IndexesToolbarProps> = ({
335238
</div>
336239
</div>
337240
)}
338-
{isReadonlyView
339-
? renderViewBanner(serverVersion, mongoDBMajorVersion)
340-
: !!errorMessage && (
341-
<ErrorSummary data-testid="indexes-error" errors={[errorMessage]} />
342-
)}
343241
</div>
344242
);
345243
};

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

Lines changed: 73 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ import React from 'react';
22
import { connect } from 'react-redux';
33
import {
44
Banner,
5-
Body,
65
Link,
76
WorkspaceContainer,
87
css,
98
spacing,
109
usePersistedState,
10+
EmptyContent,
1111
} from '@mongodb-js/compass-components';
1212

1313
import IndexesToolbar from '../indexes-toolbar/indexes-toolbar';
@@ -29,6 +29,9 @@ import { usePreference } from 'compass-preferences-model/provider';
2929
import { useConnectionInfo } from '@mongodb-js/compass-connections/provider';
3030
import { getAtlasSearchIndexesLink } from '../../utils/atlas-search-indexes-link';
3131
import CreateIndexModal from '../create-index-modal/create-index-modal';
32+
import { ZeroGraphic } from '../search-indexes-table/zero-graphic';
33+
import { ViewVersionIncompatibleBanner } from '../view-version-incompatible-banners/view-version-incompatible-banners';
34+
import type { AtlasClusterMetadata } from '@mongodb-js/connection-info';
3235

3336
// This constant is used as a trigger to show an insight whenever number of
3437
// indexes in a collection is more than what is specified here.
@@ -48,25 +51,54 @@ const linkTitle = 'Search and Vector Search.';
4851
const DISMISSED_SEARCH_INDEXES_BANNER_LOCAL_STORAGE_KEY =
4952
'mongodb_compass_dismissedSearchIndexesBanner' as const;
5053

54+
const DataExplorerViewEmptyState = () => {
55+
return (
56+
<EmptyContent
57+
icon={ZeroGraphic}
58+
title="No standard indexes"
59+
subTitle="Standard views use the indexes of the underlying collection. As a result, you
60+
cannot create, drop or re-build indexes on a standard view directly, nor get a list of indexes on the view."
61+
callToActionLink={
62+
<Link
63+
href="https://www.mongodb.com/docs/atlas/atlas-search/" // PLACEHOLDER LINK
64+
target="_blank"
65+
>
66+
Learn more about views
67+
</Link>
68+
}
69+
/>
70+
);
71+
};
72+
5173
const AtlasIndexesBanner = ({
5274
namespace,
5375
dismissed,
5476
onDismissClick,
77+
atlasMetadata,
78+
isReadonlyView,
5579
}: {
5680
namespace: string;
5781
dismissed: boolean;
5882
onDismissClick: () => void;
83+
atlasMetadata: AtlasClusterMetadata | undefined;
84+
isReadonlyView?: boolean;
5985
}) => {
60-
const { atlasMetadata } = useConnectionInfo();
61-
6286
if (!atlasMetadata || dismissed) {
6387
return null;
6488
}
6589

90+
const viewIsSearchCompatible = false; // view only contains $addFields, $set or $match stages with the $expr operator.
91+
const bannerVariant =
92+
isReadonlyView && !viewIsSearchCompatible ? 'warning' : 'info';
93+
const bannerText =
94+
isReadonlyView && !viewIsSearchCompatible
95+
? 'This view is incompatible with search indexes. To use search indexes, edit the view to only contain $addFields, $set or $match stages with the $expr operator. You can view all search indexes under '
96+
: 'These indexes can be created and viewed under ';
6697
return (
67-
<Banner variant="info" dismissible onClose={onDismissClick}>
68-
<Body weight="medium">Looking for search indexes?</Body>
69-
These indexes can be created and viewed under{' '}
98+
<Banner variant={bannerVariant} dismissible onClose={onDismissClick}>
99+
<b>Looking for search indexes?</b>
100+
<br />
101+
{bannerText}
70102
{atlasMetadata ? (
71103
<Link
72104
href={getAtlasSearchIndexesLink({
@@ -84,6 +116,18 @@ const AtlasIndexesBanner = ({
84116
);
85117
};
86118

119+
/* if (version > 8.0 || version===8.0 && !isSearchManagementActive) { // compass >8.0 and data explorer >=8.0
120+
return ( // ALSO CHECK IF VIEW IS SEARCH QUERYABLE
121+
<Banner variant={BannerVariant.Warning}>
122+
<b>Looking for search indexes?</b>
123+
<br />
124+
This view is incompatible with search indexes. To use search indexes,
125+
edit the view to only contain $addFields, $set, or $match stages with
126+
the $expr operator. You can view all search indexes under INSERT LINK.
127+
</Banner>
128+
);
129+
}*/
130+
87131
type IndexesProps = {
88132
namespace: string;
89133
isReadonlyView?: boolean;
@@ -92,6 +136,7 @@ type IndexesProps = {
92136
currentIndexesView: IndexView;
93137
refreshRegularIndexes: () => void;
94138
refreshSearchIndexes: () => void;
139+
serverVersion: string;
95140
};
96141

97142
function isRefreshingStatus(status: FetchStatus) {
@@ -117,6 +162,7 @@ export function Indexes({
117162
currentIndexesView,
118163
refreshRegularIndexes,
119164
refreshSearchIndexes,
165+
serverVersion,
120166
}: IndexesProps) {
121167
const [atlasBannerDismissed, setDismissed] = usePersistedState(
122168
DISMISSED_SEARCH_INDEXES_BANNER_LOCAL_STORAGE_KEY,
@@ -143,7 +189,8 @@ export function Indexes({
143189
: refreshSearchIndexes;
144190

145191
const enableAtlasSearchIndexes = usePreference('enableAtlasSearchIndexes');
146-
192+
const mongoDBMajorVersion = serverVersion.split('.').slice(0, 2).join('.');
193+
const { atlasMetadata } = useConnectionInfo();
147194
return (
148195
<div className={containerStyles}>
149196
<WorkspaceContainer
@@ -162,13 +209,24 @@ export function Indexes({
162209
}
163210
>
164211
<div className={indexesContainersStyles}>
165-
{!isReadonlyView && !enableAtlasSearchIndexes && (
212+
{isReadonlyView && (
213+
<ViewVersionIncompatibleBanner
214+
namespace={namespace}
215+
serverVersion={serverVersion}
216+
mongoDBMajorVersion={mongoDBMajorVersion}
217+
enableAtlasSearchIndexes={enableAtlasSearchIndexes}
218+
atlasMetadata={atlasMetadata}
219+
/>
220+
)}
221+
{!enableAtlasSearchIndexes && (
166222
<AtlasIndexesBanner
167223
namespace={namespace}
168224
dismissed={atlasBannerDismissed}
169225
onDismissClick={() => {
170226
setDismissed(true);
171227
}}
228+
atlasMetadata={atlasMetadata}
229+
isReadonlyView={isReadonlyView}
172230
/>
173231
)}
174232
{!isReadonlyView && currentIndexesView === 'regular-indexes' && (
@@ -177,6 +235,11 @@ export function Indexes({
177235
{!isReadonlyView && currentIndexesView === 'search-indexes' && (
178236
<SearchIndexesTable />
179237
)}
238+
{isReadonlyView &&
239+
!enableAtlasSearchIndexes &&
240+
searchIndexes.indexes.length === 0 && (
241+
<DataExplorerViewEmptyState />
242+
)}
180243
</div>
181244
</WorkspaceContainer>
182245
<CreateSearchIndexModal />
@@ -192,12 +255,14 @@ const mapState = ({
192255
regularIndexes,
193256
searchIndexes,
194257
indexView,
258+
serverVersion,
195259
}: RootState) => ({
196260
namespace,
197261
isReadonlyView,
198262
regularIndexes,
199263
searchIndexes,
200264
currentIndexesView: indexView,
265+
serverVersion,
201266
});
202267

203268
const mapDispatch = {

0 commit comments

Comments
 (0)