feat(compass-indexes): Refactor read/writability of search and regular indexes COMPASS-10310#7778
feat(compass-indexes): Refactor read/writability of search and regular indexes COMPASS-10310#7778JimmyChoiMDB wants to merge 15 commits intomainfrom
Conversation
There was a problem hiding this comment.
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. |
packages/compass-indexes/src/utils/is-view-search-compatible.ts
Outdated
Show resolved
Hide resolved
...c/components/view-incompatible-components/view-standard-indexes-incompatible-empty-state.tsx
Show resolved
Hide resolved
packages/compass-indexes/src/utils/indexes-read-write-access.ts
Outdated
Show resolved
Hide resolved
packages/compass-indexes/src/utils/is-view-search-compatible.ts
Outdated
Show resolved
Hide resolved
packages/compass-indexes/src/components/search-indexes-table/search-indexes-table.spec.tsx
Show resolved
Hide resolved
...ass-indexes/src/components/view-incompatible-components/view-version-incompatible-banner.tsx
Show resolved
Hide resolved
packages/compass-indexes/src/utils/indexes-read-write-access.ts
Outdated
Show resolved
Hide resolved
| isSearchIndexesReadable: boolean; | ||
| isSearchIndexesWritable: boolean; | ||
| } { | ||
| const { isWritable, isReadonlyView, isSearchIndexesSupported } = useSelector( |
There was a problem hiding this comment.
Please read the compass development guide section on redux, we are avoiding use of redux hooks for components and use connect instead (the reasoning is explained in the doc). If you want to encapsulate this logic, please make it into a selector function, not a hook
There was a problem hiding this comment.
got it, converted the hook into a selector function
| getIsRegularIndexesReadable(isReadonlyView); | ||
| if ( | ||
| !isRegularIndexesReadable || | ||
| !isWritable // offline-mode, cannot fetch |
There was a problem hiding this comment.
This is a misleading comment, isWritable can be just connection to a node in a cluster where topology doesn't allow writes
There was a problem hiding this comment.
fixed the comment to be less misleading.
also i only added this because there was a test checking for this in search-indexes.spec.ts
isWritable itself seems like a bit of a misnomer, this is describing a non-fetchable or non-refreshable condition
| }; | ||
|
|
||
| const mapState = ({ searchIndexes }: RootState) => ({ | ||
| searchIndexes: searchIndexes.indexes, |
There was a problem hiding this comment.
| searchIndexes: searchIndexes.indexes, | |
| hasNoSearchIndexes: searchIndexes.indexes.length === 0, |
packages/compass-indexes/src/components/search-indexes-table/search-indexes-table.tsx
Show resolved
Hide resolved
| })(getState()); | ||
|
|
||
| if ( | ||
| !isRegularIndexesReadable || |
There was a problem hiding this comment.
With isWritable gaurd, i am wondering now if we should clear this out. If user already had a list of indexes fetched and somehow the topology is not writable anymore, should we clear it? Same for search indexes 🤔
There was a problem hiding this comment.
i do think adding || !isWritable here either incorrect or at least misleading. i think it depends on how you expect offline-mode to behave - do you want to show the indexes we've fetched before and show stale data, or not show anything at all. that might be a question for product.
There was a problem hiding this comment.
Currently we are not hiding any data for this state (!isWritable) at most of the places, but are introducing it here. I think we should align how we are handling things currently and we can create a follow up for this.
There was a problem hiding this comment.
sounds good, created https://jira.mongodb.org/browse/COMPASS-10357 and added a TODO
| const { atlasMetadata } = connectionInfoRef.current; | ||
| const { isRegularIndexesReadable } = selectReadWriteAccess({ | ||
| isAtlas: !!atlasMetadata, | ||
| ...preferences.getPreferences(), |
There was a problem hiding this comment.
Do we need to pass all of them here?
There was a problem hiding this comment.
technically isRegularIndexesReadable is just !isReadonlyView, so we dont need them. but the selector function requires all inputs as parameters
There was a problem hiding this comment.
I meant with ...preferences.getPreferences(), you are literally passing all the preferences to the selectReadWriteAccess method. We can be explicit in passing only values this function needs.
There was a problem hiding this comment.
yeah makes sense. fixed
| variant="primary" | ||
| size="small" | ||
| disabled={!isViewPipelineSearchQueryable} | ||
| // TODO: COMPASS-10353 disable for other non-writable cases as well |
There was a problem hiding this comment.
| // TODO: COMPASS-10353 disable for other non-writable cases as well | |
| // TODO(COMPASS-10353): disable for other non-writable cases as well |
There was a problem hiding this comment.
This is how we are adding todos in the codebase.
There was a problem hiding this comment.
ah got it, thanks
| const { atlasMetadata } = connectionInfoRef.current; | ||
| const { isRegularIndexesReadable } = selectReadWriteAccess({ | ||
| isAtlas: !!atlasMetadata, | ||
| ...preferences.getPreferences(), |
There was a problem hiding this comment.
I meant with ...preferences.getPreferences(), you are literally passing all the preferences to the selectReadWriteAccess method. We can be explicit in passing only values this function needs.
| })(getState()); | ||
|
|
||
| if ( | ||
| !isRegularIndexesReadable || |
There was a problem hiding this comment.
Currently we are not hiding any data for this state (!isWritable) at most of the places, but are introducing it here. I think we should align how we are handling things currently and we can create a follow up for this.
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