Skip to content

Commit 9650ec9

Browse files
authored
chore(search-indexes): set up search indexes detection COMPASS-7196 (#4815)
1 parent c2bd019 commit 9650ec9

File tree

21 files changed

+476
-267
lines changed

21 files changed

+476
-267
lines changed

packages/collection-model/index.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ interface Collection {
4646
isTimeSeries: boolean;
4747
isClustered: boolean;
4848
isFLE: boolean;
49+
isSearchIndexesSupported: boolean;
4950
sourceName?: string;
5051
sourceReadonly?: boolean;
5152
sourceViewon?: string;

packages/collection-model/lib/model.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,7 @@ const CollectionModel = AmpersandModel.extend(debounceActions(['fetch']), {
257257
/**
258258
* Fetches collection info and returns a special format of collection metadata
259259
* that events like open-in-new-tab, select-namespace, edit-view require
260+
* @param {{ dataService: import('mongodb-data-service').DataService }} dataService
260261
*/
261262
async fetchMetadata({ dataService }) {
262263
try {
@@ -268,12 +269,26 @@ const CollectionModel = AmpersandModel.extend(debounceActions(['fetch']), {
268269
// We don't care if it fails to get stats from server for any reason
269270
}
270271

272+
/**
273+
* The support for search indexes is a feature of a server not a collection.
274+
* As this check can only be performed currently by running $listSearchIndexes
275+
* aggregation stage against a collection, so we run it from the collection model.
276+
* With this setup, when a user opens the first collection, we set this property
277+
* on the instance model and then from there its value is read avoiding call to server.
278+
*/
279+
const isSearchIndexesSupported = await getParentByType(this, 'Instance')
280+
.getIsSearchSupported({
281+
dataService,
282+
ns: this.ns,
283+
});
284+
271285
const collectionMetadata = {
272286
namespace: this.ns,
273287
isReadonly: this.readonly,
274288
isTimeSeries: this.isTimeSeries,
275289
isClustered: this.clustered,
276290
isFLE: this.fle2,
291+
isSearchIndexesSupported,
277292
};
278293
if (this.sourceId) {
279294
try {

packages/compass-collection/src/modules/tabs.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ export interface WorkspaceTabObject {
8989
sourceReadonly?: boolean;
9090
sourceViewOn?: string;
9191
localAppRegistry: AppRegistry;
92+
isSearchIndexesSupported: boolean;
9293
}
9394

9495
/**
@@ -148,6 +149,7 @@ const doSelectNamespace = (state: State, action: AnyAction) => {
148149
sourceReadonly: action.sourceReadonly,
149150
sourceViewOn: action.sourceViewOn,
150151
localAppRegistry: action.context.localAppRegistry,
152+
isSearchIndexesSupported: action.isSearchIndexesSupported,
151153
});
152154
} else {
153155
newState.push({ ...tab });
@@ -197,6 +199,7 @@ const doCreateTab = (state: State, action: AnyAction) => {
197199
sourceReadonly: action.sourceReadonly,
198200
sourceViewOn: action.sourceViewOn,
199201
localAppRegistry: action.context.localAppRegistry,
202+
isSearchIndexesSupported: action.isSearchIndexesSupported,
200203
});
201204
return newState;
202205
};
@@ -413,6 +416,7 @@ export const createTab = ({
413416
sourceViewOn,
414417
query,
415418
aggregation,
419+
isSearchIndexesSupported,
416420
}: Pick<
417421
WorkspaceTabObject,
418422
| 'id'
@@ -425,6 +429,7 @@ export const createTab = ({
425429
| 'editViewName'
426430
| 'sourceReadonly'
427431
| 'sourceViewOn'
432+
| 'isSearchIndexesSupported'
428433
> & {
429434
context: ContextProps;
430435
query?: any; // TODO(COMPASS-6162): type query.
@@ -444,6 +449,7 @@ export const createTab = ({
444449
sourceViewOn,
445450
query,
446451
aggregation,
452+
isSearchIndexesSupported,
447453
});
448454

449455
/**
@@ -475,6 +481,7 @@ export const selectNamespace = ({
475481
context,
476482
sourceReadonly,
477483
sourceViewOn,
484+
isSearchIndexesSupported,
478485
}: Pick<
479486
WorkspaceTabObject,
480487
| 'id'
@@ -487,6 +494,7 @@ export const selectNamespace = ({
487494
| 'editViewName'
488495
| 'sourceReadonly'
489496
| 'sourceViewOn'
497+
| 'isSearchIndexesSupported'
490498
> & {
491499
context: ContextProps;
492500
}): AnyAction => ({
@@ -502,6 +510,7 @@ export const selectNamespace = ({
502510
context,
503511
sourceReadonly,
504512
sourceViewOn,
513+
isSearchIndexesSupported,
505514
});
506515

507516
/**
@@ -662,6 +671,7 @@ export const selectOrCreateTab = ({
662671
sourceReadonly,
663672
sourceViewOn,
664673
sourcePipeline,
674+
isSearchIndexesSupported,
665675
}: Pick<
666676
WorkspaceTabObject,
667677
| 'namespace'
@@ -673,6 +683,7 @@ export const selectOrCreateTab = ({
673683
| 'editViewName'
674684
| 'sourceReadonly'
675685
| 'sourceViewOn'
686+
| 'isSearchIndexesSupported'
676687
> & {
677688
sourcePipeline: Document[];
678689
}): ThunkAction<void, RootState, void, AnyAction> => {
@@ -694,6 +705,7 @@ export const selectOrCreateTab = ({
694705
sourceReadonly,
695706
sourceViewOn,
696707
sourcePipeline,
708+
isSearchIndexesSupported,
697709
})
698710
);
699711
} else {
@@ -716,6 +728,7 @@ export const selectOrCreateTab = ({
716728
sourceReadonly,
717729
sourceViewOn,
718730
sourcePipeline,
731+
isSearchIndexesSupported,
719732
})
720733
);
721734
// Clear the stats of the closed tab's namespace if it's the last one in use.
@@ -751,6 +764,7 @@ export const createNewTab = ({
751764
sourcePipeline,
752765
query,
753766
aggregation,
767+
isSearchIndexesSupported,
754768
}: Pick<
755769
WorkspaceTabObject,
756770
| 'namespace'
@@ -762,6 +776,7 @@ export const createNewTab = ({
762776
| 'editViewName'
763777
| 'sourceReadonly'
764778
| 'sourceViewOn'
779+
| 'isSearchIndexesSupported'
765780
> & {
766781
sourcePipeline?: Document[];
767782
query?: any; // TODO(COMPASS-6162): type query.
@@ -782,6 +797,7 @@ export const createNewTab = ({
782797
sourcePipeline,
783798
query,
784799
aggregation,
800+
isSearchIndexesSupported,
785801
});
786802
dispatch(
787803
createTab({
@@ -798,6 +814,7 @@ export const createNewTab = ({
798814
sourceViewOn,
799815
query,
800816
aggregation,
817+
isSearchIndexesSupported,
801818
})
802819
);
803820
showCollectionSubmenu({ isReadOnly: isReadonly });
@@ -821,6 +838,7 @@ export const replaceTabContent = ({
821838
sourceReadonly,
822839
sourceViewOn,
823840
sourcePipeline,
841+
isSearchIndexesSupported,
824842
}: Pick<
825843
WorkspaceTabObject,
826844
| 'namespace'
@@ -832,6 +850,7 @@ export const replaceTabContent = ({
832850
| 'editViewName'
833851
| 'sourceReadonly'
834852
| 'sourceViewOn'
853+
| 'isSearchIndexesSupported'
835854
> & {
836855
sourcePipeline?: Document[];
837856
}): ThunkAction<void, RootState, void, AnyAction> => {
@@ -848,6 +867,7 @@ export const replaceTabContent = ({
848867
sourceName,
849868
editViewName,
850869
sourcePipeline,
870+
isSearchIndexesSupported,
851871
});
852872
dispatch(
853873
selectNamespace({
@@ -862,6 +882,7 @@ export const replaceTabContent = ({
862882
context,
863883
sourceReadonly: !!sourceReadonly,
864884
sourceViewOn,
885+
isSearchIndexesSupported,
865886
})
866887
);
867888
showCollectionSubmenu({ isReadOnly: isReadonly });

packages/compass-collection/src/stores/context.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ export type ContextProps = {
8080
isDataLake?: boolean;
8181
scopedModals?: any[];
8282
connectionString?: string;
83+
isSearchIndexesSupported?: boolean;
8384
};
8485

8586
type ContextWithAppRegistry = ContextProps & {
@@ -123,6 +124,7 @@ const setupStore = ({
123124
query,
124125
aggregation,
125126
connectionString,
127+
isSearchIndexesSupported,
126128
}: ContextWithAppRegistry & { role: Role }) => {
127129
if (!role.storeName || !role.configureStore) {
128130
return;
@@ -149,6 +151,7 @@ const setupStore = ({
149151
query,
150152
aggregation,
151153
connectionString,
154+
isSearchIndexesSupported,
152155
});
153156
localAppRegistry.registerStore(role.storeName, store);
154157

@@ -359,6 +362,7 @@ const createContext = ({
359362
sourcePipeline,
360363
query,
361364
aggregation,
365+
isSearchIndexesSupported,
362366
}: ContextProps): ContextProps => {
363367
const serverVersion = state.serverVersion;
364368
const localAppRegistry = new AppRegistry();
@@ -405,6 +409,7 @@ const createContext = ({
405409
sourcePipeline,
406410
query,
407411
aggregation,
412+
isSearchIndexesSupported,
408413
});
409414

410415
// Add the tab.

packages/compass-collection/src/stores/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,7 @@ store.onActivated = (appRegistry: AppRegistry) => {
224224
sourcePipeline: metadata.sourcePipeline,
225225
query: metadata.query,
226226
aggregation: metadata.aggregation,
227+
isSearchIndexesSupported: metadata.isSearchIndexesSupported,
227228
})
228229
);
229230
});
@@ -268,6 +269,7 @@ store.onActivated = (appRegistry: AppRegistry) => {
268269
sourceReadonly: metadata.sourceReadonly,
269270
sourceViewOn: metadata.sourceViewOn,
270271
sourcePipeline: metadata.sourcePipeline,
272+
isSearchIndexesSupported: metadata.isSearchIndexesSupported,
271273
})
272274
);
273275
});

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ const renderIndexes = (
2525
dropFailedIndex={() => {}}
2626
onHideIndex={() => {}}
2727
onUnhideIndex={() => {}}
28+
isAtlasSearchSupported={false}
2829
{...props}
2930
/>
3031
);

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import type { IndexView } from '../indexes-toolbar/indexes-toolbar';
2121
import { IndexesToolbar } from '../indexes-toolbar/indexes-toolbar';
2222
import { IndexesTable } from '../indexes-table/indexes-table';
2323
import type { RootState } from '../../modules';
24+
import { SearchIndexesStatuses } from '../../modules/search-indexes';
2425

2526
const containerStyles = css({
2627
margin: spacing[3],
@@ -45,6 +46,7 @@ type IndexesProps = {
4546
onHideIndex: (name: string) => void;
4647
onUnhideIndex: (name: string) => void;
4748
readOnly?: boolean;
49+
isAtlasSearchSupported: boolean;
4850
};
4951

5052
// This constant is used as a trigger to show an insight whenever number of
@@ -66,6 +68,7 @@ export const Indexes: React.FunctionComponent<IndexesProps> = ({
6668
onHideIndex,
6769
onUnhideIndex,
6870
readOnly, // preferences readOnly.
71+
isAtlasSearchSupported,
6972
}) => {
7073
const [currentIndexesView, setCurrentIndexesView] =
7174
useState<IndexView>('regular-indexes');
@@ -89,7 +92,7 @@ export const Indexes: React.FunctionComponent<IndexesProps> = ({
8992
isRefreshing={isRefreshing}
9093
writeStateDescription={description}
9194
hasTooManyIndexes={indexes.length > IDEAL_NUMBER_OF_MAX_INDEXES}
92-
isAtlasSearchSupported={true}
95+
isAtlasSearchSupported={isAtlasSearchSupported}
9396
onRefreshIndexes={refreshIndexes}
9497
onChangeIndexView={setCurrentIndexesView}
9598
/>
@@ -121,6 +124,7 @@ const mapState = ({
121124
serverVersion,
122125
appRegistry,
123126
regularIndexes: { indexes, isRefreshing, error },
127+
searchIndexes: { status },
124128
}: RootState) => ({
125129
indexes,
126130
isWritable,
@@ -130,6 +134,7 @@ const mapState = ({
130134
localAppRegistry: (appRegistry as any).localAppRegistry,
131135
isRefreshing,
132136
serverVersion,
137+
isAtlasSearchSupported: status !== SearchIndexesStatuses.NOT_AVAILABLE,
133138
});
134139

135140
const mapDispatch = {

packages/compass-indexes/src/modules/data-service.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
import type { DataService } from 'mongodb-data-service';
1+
import type { IndexesDataService } from '../stores/store';
22

33
export enum ActionTypes {
44
DataServiceConnected = 'indexes/data-service/DATA_SERVICE_CONNECTED',
55
}
66

77
type DataServiceConnectedAction = {
88
type: ActionTypes.DataServiceConnected;
9-
dataService: DataService;
9+
dataService: IndexesDataService;
1010
};
1111

12-
type State = DataService | null;
12+
type State = IndexesDataService | null;
1313

1414
const INITIAL_STATE: State = null;
1515

@@ -23,7 +23,7 @@ export default function reducer(
2323
return state;
2424
}
2525

26-
export const dataServiceConnected = (dataService: DataService) => ({
26+
export const dataServiceConnected = (dataService: IndexesDataService) => ({
2727
type: ActionTypes.DataServiceConnected,
2828
dataService,
2929
});

packages/compass-indexes/src/modules/description.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export default reducer;
3232
* Action creator for getDescription events.
3333
*
3434
* @param {String} description - The description.
35-
* @returns {Object} The getDescription action.
35+
* @returns {import('redux').AnyAction} The getDescription action.
3636
*/
3737
export const getDescription = (description) => ({
3838
type: GET_DESCRIPTION,

0 commit comments

Comments
 (0)