-
Notifications
You must be signed in to change notification settings - Fork 251
feat(compass-indexes): Refactor read/writability of search and regular indexes COMPASS-10310 #7778
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Refactors how Compass Indexes determines read/write access and view compatibility for regular vs search indexes, and extracts reusable UI pieces for view-incompatible states.
Changes:
- Added shared utilities/hooks for index read/write access and view search compatibility.
- Updated regular/search index fetching + UI rendering to use the new access/compat logic.
- Extracted view-incompatibility banners/empty states into reusable components and updated tests accordingly.
Reviewed changes
Copilot reviewed 14 out of 15 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/compass-indexes/test/setup-store.ts | Updates test preference defaults to include Atlas Search indexes enabled. |
| packages/compass-indexes/src/utils/is-view-search-compatible.ts | Adds hook + helpers for view version/pipeline search compatibility. |
| packages/compass-indexes/src/utils/indexes-read-write-access.ts | Adds hook + helpers for regular/search index read/write gating. |
| packages/compass-indexes/src/modules/search-indexes.ts | Refactors fetch gating for search indexes using new helpers + injected services. |
| packages/compass-indexes/src/modules/regular-indexes.ts | Refactors fetch gating for regular indexes using new helpers. |
| packages/compass-indexes/src/components/view-version-incompatible-banners/view-version-incompatible-banners.tsx | Removes inlined banner component (moved elsewhere). |
| packages/compass-indexes/src/components/view-incompatible-components/view-version-incompatible-banner.tsx | Adds extracted banner component for view version incompatibility. |
| packages/compass-indexes/src/components/view-incompatible-components/view-standard-indexes-incompatible-empty-state.tsx | Adds extracted empty state for standard views/regular index incompatibility messaging. |
| packages/compass-indexes/src/components/view-incompatible-components/view-pipeline-incompatible-banner.tsx | Adds extracted banner for view pipeline incompatibility. |
| packages/compass-indexes/src/components/search-indexes-table/search-indexes-table.tsx | Switches to new access/compat hooks; updates zero state + action gating. |
| packages/compass-indexes/src/components/search-indexes-table/search-indexes-table.spec.tsx | Updates tests to render with Redux Provider + store setup. |
| packages/compass-indexes/src/components/indexes/indexes.tsx | Replaces inline view-incompat components with extracted versions and new hooks. |
| packages/compass-indexes/src/components/indexes/indexes.spec.tsx | Updates a test description/expectation for new messaging behavior. |
| packages/compass-indexes/package.json | Removes @mongodb-js/connection-info dependency. |
| export function getIsViewVersionSearchCompatible( | ||
| serverVersion: string, | ||
| isAtlas: boolean | ||
| ): boolean { | ||
| return isAtlas | ||
| ? VIEW_PIPELINE_UTILS.isVersionSearchCompatibleForViewsDataExplorer( | ||
| serverVersion | ||
| ) | ||
| : VIEW_PIPELINE_UTILS.isVersionSearchCompatibleForViewsCompass( | ||
| serverVersion | ||
| ); | ||
| } |
Copilot
AI
Feb 10, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
getIsViewVersionSearchCompatible only keys off isAtlas, but prior behavior distinguished between managing search indexes in Compass (8.1+) vs deferring to Atlas UI/Data Explorer (8.0+). As written, Atlas connections will treat 8.0 as compatible even when Atlas Search indexes are enabled in Compass, which can incorrectly allow UI/actions/fetching on unsupported versions. Consider including the enableAtlasSearchIndexes (or an explicit 'manageInCompass' flag) in the compatibility calculation and using Compass compatibility when in-Compass management is enabled.
| subTitle="Standard views use the indexes of the underlying collection. As a result, you | ||
| cannot create, drop or re-build indexes on a standard view directly, nor get a list of indexes on the view." |
Copilot
AI
Feb 10, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This JSX prop value appears to be a multi-line string literal wrapped in double quotes; in TS/JS, string literals can't contain raw newlines and this will fail to parse/compile. Use a template literal (backticks), string concatenation, or a single-line string (or JSX text via {...}) to avoid introducing a syntax error.
| subTitle="Standard views use the indexes of the underlying collection. As a result, you | |
| cannot create, drop or re-build indexes on a standard view directly, nor get a list of indexes on the view." | |
| subTitle="Standard views use the indexes of the underlying collection. As a result, you cannot create, drop or re-build indexes on a standard view directly, nor get a list of indexes on the view." |
| const { isWritable, isReadonlyView, isSearchIndexesSupported } = useSelector( | ||
| (state: RootState) => ({ | ||
| serverVersion: state.serverVersion, | ||
| isWritable: state.isWritable, | ||
| isReadonlyView: state.isReadonlyView, | ||
| isSearchIndexesSupported: state.isSearchIndexesSupported, | ||
| collectionStats: state.collectionStats, | ||
| }) | ||
| ); |
Copilot
AI
Feb 10, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This useSelector returns a new object every time the store updates, which will force a rerender even when none of the selected values changed. Prefer selecting fields individually (multiple useSelector calls) or pass shallowEqual as the equality function, and avoid including fields in the selection object that aren't needed for this hook.
| const { isWritable, isReadonlyView, isSearchIndexesSupported } = useSelector( | |
| (state: RootState) => ({ | |
| serverVersion: state.serverVersion, | |
| isWritable: state.isWritable, | |
| isReadonlyView: state.isReadonlyView, | |
| isSearchIndexesSupported: state.isSearchIndexesSupported, | |
| collectionStats: state.collectionStats, | |
| }) | |
| ); | |
| const isWritable = useSelector((state: RootState) => state.isWritable); | |
| const isReadonlyView = useSelector( | |
| (state: RootState) => state.isReadonlyView | |
| ); | |
| const isSearchIndexesSupported = useSelector( | |
| (state: RootState) => state.isSearchIndexesSupported | |
| ); |
| const { serverVersion, collectionStats } = useSelector( | ||
| (state: RootState) => ({ | ||
| serverVersion: state.serverVersion, | ||
| collectionStats: state.collectionStats, | ||
| }) | ||
| ); |
Copilot
AI
Feb 10, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same pattern here: selecting into a freshly created object will trigger rerenders on any store update. Consider selecting serverVersion and collectionStats via separate selectors or using shallowEqual to prevent unnecessary rerenders.
| const { serverVersion, collectionStats } = useSelector( | |
| (state: RootState) => ({ | |
| serverVersion: state.serverVersion, | |
| collectionStats: state.collectionStats, | |
| }) | |
| ); | |
| const serverVersion = useSelector( | |
| (state: RootState) => state.serverVersion | |
| ); | |
| const collectionStats = useSelector( | |
| (state: RootState) => state.collectionStats | |
| ); |
| }); | ||
|
|
||
| if (state) { | ||
| const newState = { ...store.getState(), ...state }; | ||
| Object.assign(store.getState(), newState); | ||
| } | ||
|
|
Copilot
AI
Feb 10, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mutating the object returned by store.getState() is not reliable in Redux tests (it bypasses reducers and may not notify subscribers). Prefer creating the store with a preloaded state (if supported by setupStore/activateIndexesPlugin), or dispatch actions to reach the desired state shape for the scenario under test.
| }); | |
| if (state) { | |
| const newState = { ...store.getState(), ...state }; | |
| Object.assign(store.getState(), newState); | |
| } | |
| ...(state ?? {}), | |
| }); |
| <div className={viewContentStyles}> | ||
| <span> | ||
| Your MongoDB version is {serverVersion}. Creating and managing search | ||
| indexes on views {!isAtlas && 'in Compass'} is supported on MongoDB |
Copilot
AI
Feb 10, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Grammar: 'indexes ... is supported' should be 'indexes ... are supported' (plural subject).
| indexes on views {!isAtlas && 'in Compass'} is supported on MongoDB | |
| indexes on views {!isAtlas && 'in Compass'} are supported on MongoDB |
| export function getIsSearchIndexesReadable( | ||
| enableAtlasSearchIndexes: boolean, | ||
| isReadonlyView: boolean, | ||
| isViewVersionSearchCompatible: boolean, | ||
| isSearchIndexesSupported: boolean | ||
| ): boolean { | ||
| return ( | ||
| enableAtlasSearchIndexes && | ||
| (isReadonlyView ? isViewVersionSearchCompatible : isSearchIndexesSupported) | ||
| ); | ||
| } |
Copilot
AI
Feb 10, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
New access/compat logic is central to the refactor and has multiple branching cases (readonly view vs collection, Atlas vs non-Atlas, version compatibility, pipeline queryability, preferences). Please add focused unit tests covering at least: (1) Atlas + enableAtlasSearchIndexes=true + serverVersion 8.0 (should be treated as incompatible for in-Compass management if that’s the intended rule), (2) Atlas + enableAtlasSearchIndexes=false + serverVersion 8.0, and (3) non-Atlas + serverVersion 8.0/8.1 boundaries, so regressions are caught.
Description
indexes-read-write-access.tsfile in utils directory that exposes helper functions and hooks to determine whether the user can read or write search or regular indexesis-view-search-compatible.tsfile that exposes helper functions and hooks to determine whether view version is search compatible and view pipeline is search queryableChecklist
Motivation and Context
Types of changes