@@ -2,12 +2,12 @@ import React from 'react';
22import { connect } from 'react-redux' ;
33import {
44 Banner ,
5- Body ,
65 Link ,
76 WorkspaceContainer ,
87 css ,
98 spacing ,
109 usePersistedState ,
10+ EmptyContent ,
1111} from '@mongodb-js/compass-components' ;
1212
1313import IndexesToolbar from '../indexes-toolbar/indexes-toolbar' ;
@@ -29,6 +29,9 @@ import { usePreference } from 'compass-preferences-model/provider';
2929import { useConnectionInfo } from '@mongodb-js/compass-connections/provider' ;
3030import { getAtlasSearchIndexesLink } from '../../utils/atlas-search-indexes-link' ;
3131import 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.';
4851const 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+
5173const 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+
87131type 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
97142function 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
203268const mapDispatch = {
0 commit comments