Skip to content

Commit 6bc7021

Browse files
fetching search indexes for view
1 parent 0c96520 commit 6bc7021

File tree

4 files changed

+108
-66
lines changed

4 files changed

+108
-66
lines changed

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

Lines changed: 57 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,16 @@ export const IndexesToolbar: React.FunctionComponent<IndexesToolbarProps> = ({
105105
readOnly, // preferences readOnly.
106106
}) => {
107107
const isSearchManagementActive = usePreference('enableAtlasSearchIndexes');
108+
const mongoDBMajorVersion = parseFloat(
109+
serverVersion.split('.').slice(0, 2).join('.')
110+
);
108111
const { atlasMetadata } = useConnectionInfo();
109112
const showInsights = usePreference('showInsights') && !errorMessage;
110-
const showCreateIndexButton = !isReadonlyView && !readOnly && !errorMessage;
113+
const showCreateIndexButton =
114+
mongoDBMajorVersion > 8.0 && !readOnly && !errorMessage;
115+
const showRefreshButton =
116+
!isReadonlyView ||
117+
(mongoDBMajorVersion > 8.0 && indexView === 'search-indexes');
111118
const refreshButtonIcon = isRefreshing ? (
112119
<div className={spinnerStyles}>
113120
<SpinLoader title="Refreshing Indexes" />
@@ -121,7 +128,7 @@ export const IndexesToolbar: React.FunctionComponent<IndexesToolbarProps> = ({
121128
className={indexesToolbarContainerStyles}
122129
data-testid="indexes-toolbar-container"
123130
>
124-
{!isReadonlyView && (
131+
{mongoDBMajorVersion > 8.0 && (
125132
<div data-testid="indexes-toolbar">
126133
<div className={toolbarButtonsContainer}>
127134
{showCreateIndexButton && (
@@ -137,23 +144,27 @@ export const IndexesToolbar: React.FunctionComponent<IndexesToolbarProps> = ({
137144
isWritable={isWritable}
138145
onCreateRegularIndexClick={onCreateRegularIndexClick}
139146
onCreateSearchIndexClick={onCreateSearchIndexClick}
140-
></CreateIndexButton>
147+
isReadonlyView={isReadonlyView}
148+
indexView={indexView}
149+
/>
141150
</div>
142151
}
143152
>
144153
{writeStateDescription}
145154
</Tooltip>
146155
)}
147-
<Button
148-
data-testid="refresh-indexes-button"
149-
disabled={isRefreshing}
150-
onClick={() => onRefreshIndexes()}
151-
variant="default"
152-
size="small"
153-
leftGlyph={refreshButtonIcon}
154-
>
155-
Refresh
156-
</Button>
156+
{showRefreshButton && (
157+
<Button
158+
data-testid="refresh-indexes-button"
159+
disabled={isRefreshing}
160+
onClick={() => onRefreshIndexes()}
161+
variant="default"
162+
size="small"
163+
leftGlyph={refreshButtonIcon}
164+
>
165+
Refresh
166+
</Button>
167+
)}
157168
{showAtlasSearchLink && atlasMetadata && (
158169
<Link
159170
href={getAtlasSearchIndexesLink({
@@ -180,13 +191,14 @@ export const IndexesToolbar: React.FunctionComponent<IndexesToolbarProps> = ({
180191
value={indexView}
181192
data-testid="indexes-segment-controls"
182193
>
183-
<SegmentedControlOption
194+
<SegmentedControlOption // NEED TOOLTIP
184195
data-testid="regular-indexes-tab"
185196
value="regular-indexes"
197+
disabled={isReadonlyView}
186198
>
187199
Indexes
188200
</SegmentedControlOption>
189-
{!isSearchIndexesSupported && (
201+
{/* {!isSearchIndexesSupported && (
190202
<Tooltip
191203
align="top"
192204
justify="end"
@@ -224,15 +236,14 @@ export const IndexesToolbar: React.FunctionComponent<IndexesToolbarProps> = ({
224236
</>
225237
)}
226238
</Tooltip>
227-
)}
228-
{isSearchIndexesSupported && (
229-
<SegmentedControlOption
230-
data-testid="search-indexes-tab"
231-
value="search-indexes"
232-
>
233-
Search Indexes
234-
</SegmentedControlOption>
235-
)}
239+
)}*/}
240+
241+
<SegmentedControlOption
242+
data-testid="search-indexes-tab"
243+
value="search-indexes"
244+
>
245+
Search Indexes
246+
</SegmentedControlOption>
236247
</SegmentedControl>
237248
)}
238249
</div>
@@ -248,6 +259,8 @@ type CreateIndexButtonProps = {
248259
isWritable: boolean;
249260
onCreateRegularIndexClick: () => void;
250261
onCreateSearchIndexClick: () => void;
262+
isReadonlyView: boolean;
263+
indexView: IndexView;
251264
};
252265

253266
type CreateIndexActions = 'createRegularIndex' | 'createSearchIndex';
@@ -260,6 +273,8 @@ export const CreateIndexButton: React.FunctionComponent<
260273
isWritable,
261274
onCreateRegularIndexClick,
262275
onCreateSearchIndexClick,
276+
isReadonlyView,
277+
indexView,
263278
}) => {
264279
const onActionDispatch = useCallback(
265280
(action: CreateIndexActions) => {
@@ -273,7 +288,24 @@ export const CreateIndexButton: React.FunctionComponent<
273288
[onCreateRegularIndexClick, onCreateSearchIndexClick]
274289
);
275290

276-
if (isSearchIndexesSupported && isSearchManagementActive) {
291+
if (isReadonlyView && isSearchManagementActive) {
292+
if (indexView === 'search-indexes') {
293+
return (
294+
<Button
295+
data-testid="open-create-index-modal-button"
296+
disabled={!isWritable}
297+
onClick={onCreateRegularIndexClick}
298+
variant="primary"
299+
size="small"
300+
>
301+
Create Search Index
302+
</Button>
303+
);
304+
}
305+
306+
return null;
307+
}
308+
if (!isReadonlyView && isSearchIndexesSupported && isSearchManagementActive) {
277309
return (
278310
<DropdownMenuButton
279311
data-testid="multiple-index-types-creation-dropdown"

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

Lines changed: 42 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,22 @@ const linkTitle = 'Search and Vector Search.';
5151
const DISMISSED_SEARCH_INDEXES_BANNER_LOCAL_STORAGE_KEY =
5252
'mongodb_compass_dismissedSearchIndexesBanner' as const;
5353

54-
const DataExplorerViewEmptyState = () => {
54+
const ViewVersionIncompatibleEmptyState = ({
55+
mongoDBMajorVersion,
56+
enableAtlasSearchIndexes,
57+
}: {
58+
mongoDBMajorVersion: number;
59+
enableAtlasSearchIndexes: boolean;
60+
}) => {
61+
const viewIsSearchCompatible = true; // view only contains $addFields, $set or $match stages with the $expr operator.
62+
63+
if (
64+
mongoDBMajorVersion >= 8.1 &&
65+
enableAtlasSearchIndexes &&
66+
viewIsSearchCompatible
67+
) {
68+
return null;
69+
}
5570
return (
5671
<EmptyContent
5772
icon={ZeroGraphic}
@@ -76,18 +91,19 @@ const AtlasIndexesBanner = ({
7691
onDismissClick,
7792
atlasMetadata,
7893
isReadonlyView,
94+
mongoDBMajorVersion,
7995
}: {
8096
namespace: string;
8197
dismissed: boolean;
8298
onDismissClick: () => void;
8399
atlasMetadata: AtlasClusterMetadata | undefined;
84100
isReadonlyView?: boolean;
101+
mongoDBMajorVersion: number;
85102
}) => {
86-
if (!atlasMetadata || dismissed) {
103+
const viewIsSearchCompatible = true; // view only contains $addFields, $set or $match stages with the $expr operator.
104+
if (dismissed || (mongoDBMajorVersion > 8.0 && viewIsSearchCompatible)) {
87105
return null;
88106
}
89-
90-
const viewIsSearchCompatible = false; // view only contains $addFields, $set or $match stages with the $expr operator.
91107
const bannerVariant =
92108
isReadonlyView && !viewIsSearchCompatible ? 'warning' : 'info';
93109
const bannerText =
@@ -116,18 +132,6 @@ const AtlasIndexesBanner = ({
116132
);
117133
};
118134

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-
131135
type IndexesProps = {
132136
namespace: string;
133137
isReadonlyView?: boolean;
@@ -189,7 +193,9 @@ export function Indexes({
189193
: refreshSearchIndexes;
190194

191195
const enableAtlasSearchIndexes = usePreference('enableAtlasSearchIndexes');
192-
const mongoDBMajorVersion = serverVersion.split('.').slice(0, 2).join('.');
196+
const mongoDBMajorVersion = parseFloat(
197+
serverVersion.split('.').slice(0, 2).join('.')
198+
);
193199
const { atlasMetadata } = useConnectionInfo();
194200
return (
195201
<div className={containerStyles}>
@@ -218,28 +224,29 @@ export function Indexes({
218224
atlasMetadata={atlasMetadata}
219225
/>
220226
)}
221-
{!enableAtlasSearchIndexes && (
222-
<AtlasIndexesBanner
223-
namespace={namespace}
224-
dismissed={atlasBannerDismissed}
225-
onDismissClick={() => {
226-
setDismissed(true);
227-
}}
228-
atlasMetadata={atlasMetadata}
229-
isReadonlyView={isReadonlyView}
230-
/>
231-
)}
227+
{!enableAtlasSearchIndexes ||
228+
(mongoDBMajorVersion > 8.0 && (
229+
<AtlasIndexesBanner
230+
namespace={namespace}
231+
dismissed={atlasBannerDismissed}
232+
onDismissClick={() => {
233+
setDismissed(true);
234+
}}
235+
atlasMetadata={atlasMetadata}
236+
isReadonlyView={isReadonlyView}
237+
mongoDBMajorVersion={mongoDBMajorVersion}
238+
/>
239+
))}
232240
{!isReadonlyView && currentIndexesView === 'regular-indexes' && (
233241
<RegularIndexesTable />
234242
)}
235-
{!isReadonlyView && currentIndexesView === 'search-indexes' && (
236-
<SearchIndexesTable />
243+
{currentIndexesView === 'search-indexes' && <SearchIndexesTable />}
244+
{isReadonlyView && searchIndexes.indexes.length === 0 && (
245+
<ViewVersionIncompatibleEmptyState
246+
mongoDBMajorVersion={mongoDBMajorVersion}
247+
enableAtlasSearchIndexes={enableAtlasSearchIndexes}
248+
/>
237249
)}
238-
{isReadonlyView &&
239-
!enableAtlasSearchIndexes &&
240-
searchIndexes.indexes.length === 0 && (
241-
<DataExplorerViewEmptyState />
242-
)}
243250
</div>
244251
</WorkspaceContainer>
245252
<CreateSearchIndexModal />

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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,21 @@ export const ViewVersionIncompatibleBanner = ({
2525
}: {
2626
namespace: string;
2727
serverVersion: string;
28-
mongoDBMajorVersion: string;
28+
mongoDBMajorVersion: number;
2929
enableAtlasSearchIndexes: boolean;
3030
atlasMetadata: AtlasClusterMetadata | undefined;
3131
}) => {
32-
const version = parseFloat(mongoDBMajorVersion);
3332
const searchIndexOnViewsVersion = enableAtlasSearchIndexes ? '8.1' : '8.0';
3433

35-
if (version > 8.0 || (version === 8.0 && !enableAtlasSearchIndexes)) {
34+
if (
35+
mongoDBMajorVersion > 8.0 ||
36+
(mongoDBMajorVersion === 8.0 && !enableAtlasSearchIndexes)
37+
) {
3638
// return if 8.1+ or 8.0+ for data explorer
3739
return null;
3840
}
3941

40-
if (version < 8.0) {
42+
if (mongoDBMajorVersion < 8.0) {
4143
// data explorer <8.0 and compass <8.0
4244
return (
4345
<Banner variant={BannerVariant.Warning}>
@@ -70,7 +72,7 @@ export const ViewVersionIncompatibleBanner = ({
7072
);
7173
}
7274

73-
if (version === 8.0 && enableAtlasSearchIndexes) {
75+
if (mongoDBMajorVersion === 8.0 && enableAtlasSearchIndexes) {
7476
// compass 8.0
7577
return (
7678
<Banner variant={BannerVariant.Warning}>

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -605,7 +605,8 @@ const fetchIndexes = (
605605
searchIndexes: { status },
606606
} = getState();
607607

608-
if (isReadonlyView || !isWritable) {
608+
if (!isWritable) {
609+
// remove is ReadOnlyBlocker,
609610
return;
610611
}
611612

0 commit comments

Comments
 (0)