Skip to content

feat(compass-indexes): Refactor read/writability of search and regular indexes COMPASS-10310#7778

Open
JimmyChoiMDB wants to merge 15 commits intomainfrom
COMPASS-10310-v2
Open

feat(compass-indexes): Refactor read/writability of search and regular indexes COMPASS-10310#7778
JimmyChoiMDB wants to merge 15 commits intomainfrom
COMPASS-10310-v2

Conversation

@JimmyChoiMDB
Copy link
Collaborator

@JimmyChoiMDB JimmyChoiMDB commented Feb 9, 2026

Description

  • Add indexes-read-write-access.ts file in utils directory that exposes helper functions and hooks to determine whether the user can read or write search or regular indexes
  • Add is-view-search-compatible.ts file that exposes helper functions and hooks to determine whether view version is search compatible and view pipeline is search queryable
  • Moved banner and empty state components to separate files for easy reuse
  • No functional changes

Checklist

  • New tests and/or benchmarks are included
  • Documentation is changed or added
  • If this change updates the UI, screenshots/videos are added and a design review is requested
  • If this change could impact the load on the MongoDB cluster, please describe the expected and worst case impact
  • I have signed the MongoDB Contributor License Agreement (https://www.mongodb.com/legal/contributor-agreement)

Motivation and Context

  • Bugfix
  • New feature
  • Dependency update
  • Misc

Types of changes

  • Backport Needed
  • Patch (non-breaking change which fixes an issue)
  • Minor (non-breaking change which adds functionality)
  • Major (fix or feature that would cause existing functionality to change)

@github-actions github-actions bot added the feat label Feb 9, 2026
@JimmyChoiMDB JimmyChoiMDB added feature flagged PRs labeled with this label will not be included in the release notes of the next release and removed feat labels Feb 9, 2026
@github-actions github-actions bot added the feat label Feb 9, 2026
@JimmyChoiMDB JimmyChoiMDB marked this pull request as ready for review February 10, 2026 00:49
@JimmyChoiMDB JimmyChoiMDB requested a review from a team as a code owner February 10, 2026 00:49
Copilot AI review requested due to automatic review settings February 10, 2026 00:49
Copy link
Contributor

Copilot AI left a 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.

isSearchIndexesReadable: boolean;
isSearchIndexesWritable: boolean;
} {
const { isWritable, isReadonlyView, isSearchIndexesSupported } = useSelector(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

got it, converted the hook into a selector function

getIsRegularIndexesReadable(isReadonlyView);
if (
!isRegularIndexesReadable ||
!isWritable // offline-mode, cannot fetch
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a misleading comment, isWritable can be just connection to a node in a cluster where topology doesn't allow writes

Copy link
Collaborator Author

@JimmyChoiMDB JimmyChoiMDB Feb 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
searchIndexes: searchIndexes.indexes,
hasNoSearchIndexes: searchIndexes.indexes.length === 0,

})(getState());

if (
!isRegularIndexesReadable ||
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 🤔

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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(),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to pass all of them here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

technically isRegularIndexesReadable is just !isReadonlyView, so we dont need them. but the selector function requires all inputs as parameters

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah makes sense. fixed

@JimmyChoiMDB JimmyChoiMDB requested review from gribnoysup and mabaasit and removed request for mabaasit February 12, 2026 18:15
variant="primary"
size="small"
disabled={!isViewPipelineSearchQueryable}
// TODO: COMPASS-10353 disable for other non-writable cases as well
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// TODO: COMPASS-10353 disable for other non-writable cases as well
// TODO(COMPASS-10353): disable for other non-writable cases as well

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is how we are adding todos in the codebase.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah got it, thanks

const { atlasMetadata } = connectionInfoRef.current;
const { isRegularIndexesReadable } = selectReadWriteAccess({
isAtlas: !!atlasMetadata,
...preferences.getPreferences(),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 ||
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feat feature flagged PRs labeled with this label will not be included in the release notes of the next release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants