diff --git a/packages/compass-indexes/src/components/indexes-toolbar/indexes-toolbar.spec.tsx b/packages/compass-indexes/src/components/indexes-toolbar/indexes-toolbar.spec.tsx index ce7e488b03d..b13e8821cbc 100644 --- a/packages/compass-indexes/src/components/indexes-toolbar/indexes-toolbar.spec.tsx +++ b/packages/compass-indexes/src/components/indexes-toolbar/indexes-toolbar.spec.tsx @@ -37,7 +37,7 @@ describe('IndexesToolbar Component', function () { isWritable={true} writeStateDescription={undefined} onRefreshIndexes={() => {}} - isAtlasSearchSupported={false} + isSearchIndexesSupported={false} isRefreshing={false} onIndexViewChanged={() => {}} onCreateRegularIndexClick={() => {}} @@ -75,7 +75,7 @@ describe('IndexesToolbar Component', function () { showInsights: true, }); - renderIndexesToolbar({ isAtlasSearchSupported: true }); + renderIndexesToolbar({ isSearchIndexesSupported: true }); }); it('should render the create index dropdown button enabled', async function () { @@ -100,7 +100,7 @@ describe('IndexesToolbar Component', function () { showInsights: true, }); - renderIndexesToolbar({ isAtlasSearchSupported: false }); + renderIndexesToolbar({ isSearchIndexesSupported: false }); }); it('should render the create index button only', function () { @@ -198,7 +198,7 @@ describe('IndexesToolbar Component', function () { it('calls onCreateRegularIndexClick when index button is clicked', function () { const onCreateRegularIndexClickSpy = sinon.spy(); renderIndexesToolbar({ - isAtlasSearchSupported: true, + isSearchIndexesSupported: true, onCreateRegularIndexClick: onCreateRegularIndexClickSpy, }); @@ -221,7 +221,7 @@ describe('IndexesToolbar Component', function () { it('calls onCreateSearchIndexClick when index button is clicked', function () { const onCreateSearchIndexClickSpy = sinon.spy(); renderIndexesToolbar({ - isAtlasSearchSupported: true, + isSearchIndexesSupported: true, onCreateSearchIndexClick: onCreateSearchIndexClickSpy, }); @@ -308,7 +308,7 @@ describe('IndexesToolbar Component', function () { it('when it supports search management, it changes tab view', function () { renderIndexesToolbar({ - isAtlasSearchSupported: true, + isSearchIndexesSupported: true, onIndexViewChanged: onChangeViewCallback, }); const segmentControl = screen.getByText('Search Indexes'); @@ -320,7 +320,7 @@ describe('IndexesToolbar Component', function () { it('when it does not support search management, it renders tab as disabled', function () { renderIndexesToolbar({ - isAtlasSearchSupported: false, + isSearchIndexesSupported: false, onIndexViewChanged: onChangeViewCallback, }); const segmentControl = screen.getByText('Search Indexes'); diff --git a/packages/compass-indexes/src/components/indexes-toolbar/indexes-toolbar.tsx b/packages/compass-indexes/src/components/indexes-toolbar/indexes-toolbar.tsx index b1a06cb90e8..c9e33b2e11b 100644 --- a/packages/compass-indexes/src/components/indexes-toolbar/indexes-toolbar.tsx +++ b/packages/compass-indexes/src/components/indexes-toolbar/indexes-toolbar.tsx @@ -21,7 +21,6 @@ import { } from '@mongodb-js/compass-components'; import type { RootState } from '../../modules'; -import { FetchStatuses } from '../../utils/fetch-status'; import { createSearchIndexOpened } from '../../modules/search-indexes'; import { createIndexOpened } from '../../modules/create-index'; import type { IndexView } from '../../modules/index-view'; @@ -59,7 +58,7 @@ type IndexesToolbarProps = { onCreateRegularIndexClick: () => void; onCreateSearchIndexClick: () => void; writeStateDescription?: string; - isAtlasSearchSupported: boolean; + isSearchIndexesSupported: boolean; // via withPreferences: readOnly?: boolean; }; @@ -74,7 +73,7 @@ export const IndexesToolbar: React.FunctionComponent = ({ isRefreshing, writeStateDescription, hasTooManyIndexes, - isAtlasSearchSupported, + isSearchIndexesSupported, onRefreshIndexes, onIndexViewChanged, readOnly, // preferences readOnly. @@ -104,7 +103,7 @@ export const IndexesToolbar: React.FunctionComponent = ({
= ({ > Indexes - {!isAtlasSearchSupported && ( + {!isSearchIndexesSupported && ( = ({

)} - {isAtlasSearchSupported && ( + {isSearchIndexesSupported && ( = ({ type CreateIndexButtonProps = { isSearchManagementActive: boolean; - isAtlasSearchSupported: boolean; + isSearchIndexesSupported: boolean; isWritable: boolean; onCreateRegularIndexClick: () => void; onCreateSearchIndexClick: () => void; @@ -211,7 +210,7 @@ export const CreateIndexButton: React.FunctionComponent< CreateIndexButtonProps > = ({ isSearchManagementActive, - isAtlasSearchSupported, + isSearchIndexesSupported, isWritable, onCreateRegularIndexClick, onCreateSearchIndexClick, @@ -228,7 +227,7 @@ export const CreateIndexButton: React.FunctionComponent< [onCreateRegularIndexClick, onCreateSearchIndexClick] ); - if (isAtlasSearchSupported && isSearchManagementActive) { + if (isSearchIndexesSupported && isSearchManagementActive) { return ( ({ isWritable, isReadonlyView, + isSearchIndexesSupported, writeStateDescription: description, indexView, serverVersion, - isAtlasSearchSupported: searchIndexes.status !== FetchStatuses.NOT_AVAILABLE, + searchIndexes, }); const mapDispatch = { diff --git a/packages/compass-indexes/src/modules/index.ts b/packages/compass-indexes/src/modules/index.ts index c2647d9e34e..f1c7079afc5 100644 --- a/packages/compass-indexes/src/modules/index.ts +++ b/packages/compass-indexes/src/modules/index.ts @@ -4,6 +4,7 @@ import type AppRegistry from 'hadron-app-registry'; import isWritable from './is-writable'; import indexView from './index-view'; import isReadonlyView from './is-readonly-view'; +import isSearchIndexesSupported from './is-search-indexes-supported'; import description from './description'; import regularIndexes from './regular-indexes'; import searchIndexes from './search-indexes'; @@ -26,6 +27,9 @@ const reducer = combineReducers({ // CollectionProps) Used to know if many things should even be visible. isReadonlyView, + // Does this collection support search indexes + isSearchIndexesSupported, + // 'regular-indexes' or 'search-indexes' indexView, diff --git a/packages/compass-indexes/src/modules/is-search-indexes-supported.ts b/packages/compass-indexes/src/modules/is-search-indexes-supported.ts new file mode 100644 index 00000000000..a21e22029e3 --- /dev/null +++ b/packages/compass-indexes/src/modules/is-search-indexes-supported.ts @@ -0,0 +1,40 @@ +import type { AnyAction } from 'redux'; + +export const IS_SEARCH_INDEXES_SUPPORTED_CHANGED = + 'indexes/is-search-indexes-supported/is-search-indexes-supported-changed'; + +/** + * The initial state of the is readonly view attribute. + */ +export const INITIAL_STATE = false; + +/** + * Reducer function for is readonly view state. + * + * @param {Boolean} state - The state. + * + * @returns {Boolean} The state. + */ +export default function reducer( + state = INITIAL_STATE, + action: AnyAction +): boolean { + if (action.type === IS_SEARCH_INDEXES_SUPPORTED_CHANGED) { + return action.isSearchIndexesSupported; + } + return state; +} + +/** + * Action creator for readonly view changed events. + * + * @param {Boolean} isReadonlyView - Is the view readonly. + * + * @returns {import('redux').AnyAction} The readonly view changed action. + */ +export const isSearchIndexesSupportedChanged = ( + isSearchIndexesSupported: boolean +) => ({ + type: IS_SEARCH_INDEXES_SUPPORTED_CHANGED, + isSearchIndexesSupported, +}); diff --git a/packages/compass-indexes/src/modules/search-indexes.spec.ts b/packages/compass-indexes/src/modules/search-indexes.spec.ts index 76d11dc431d..a0084c7f065 100644 --- a/packages/compass-indexes/src/modules/search-indexes.spec.ts +++ b/packages/compass-indexes/src/modules/search-indexes.spec.ts @@ -56,7 +56,7 @@ describe('search-indexes module', function () { it('has not available search indexes state by default', async function () { store = await setupStoreAndWait({ isSearchIndexesSupported: false }); expect(store.getState().searchIndexes.status).to.equal( - FetchStatuses.NOT_AVAILABLE + FetchStatuses.NOT_READY ); }); diff --git a/packages/compass-indexes/src/modules/search-indexes.ts b/packages/compass-indexes/src/modules/search-indexes.ts index c3e03e2ed6f..f1acc1a3fa4 100644 --- a/packages/compass-indexes/src/modules/search-indexes.ts +++ b/packages/compass-indexes/src/modules/search-indexes.ts @@ -125,7 +125,7 @@ export type State = { }; export const INITIAL_STATE: State = { - status: FetchStatuses.NOT_AVAILABLE, + status: FetchStatuses.NOT_READY, createIndex: { isModalOpen: false, isBusy: false, diff --git a/packages/compass-indexes/src/stores/store.ts b/packages/compass-indexes/src/stores/store.ts index 1a342287b37..fffdb0e1fee 100644 --- a/packages/compass-indexes/src/stores/store.ts +++ b/packages/compass-indexes/src/stores/store.ts @@ -8,9 +8,7 @@ import { getDescription } from '../modules/description'; import { INITIAL_STATE as INDEX_LIST_INITIAL_STATE } from '../modules/index-view'; import { createIndexOpened } from '../modules/create-index'; import { refreshRegularIndexes } from '../modules/regular-indexes'; -import { FetchStatuses } from '../utils/fetch-status'; import { - INITIAL_STATE as SEARCH_INDEXES_INITIAL_STATE, refreshSearchIndexes, createSearchIndexOpened, } from '../modules/search-indexes'; @@ -76,13 +74,8 @@ export function activateIndexesPlugin( namespace: options.namespace, serverVersion: options.serverVersion, isReadonlyView: options.isReadonly, + isSearchIndexesSupported: options.isSearchIndexesSupported, indexView: INDEX_LIST_INITIAL_STATE, - searchIndexes: { - ...SEARCH_INDEXES_INITIAL_STATE, - status: options.isSearchIndexesSupported - ? FetchStatuses.NOT_READY - : FetchStatuses.NOT_AVAILABLE, - }, }, applyMiddleware( thunk.withExtraArgument({ diff --git a/packages/compass-indexes/src/utils/fetch-status.ts b/packages/compass-indexes/src/utils/fetch-status.ts index a27b9c8df42..c43cb762e65 100644 --- a/packages/compass-indexes/src/utils/fetch-status.ts +++ b/packages/compass-indexes/src/utils/fetch-status.ts @@ -1,8 +1,4 @@ export enum FetchStatuses { - /** - * No support. Default status. - */ - NOT_AVAILABLE = 'NOT_AVAILABLE', /** * We do not have a list yet. */ @@ -37,7 +33,6 @@ export type FetchingStatus = 'REFRESHING' | 'POLLING' | 'FETCHING'; // List of fetch statuses when the server should not be called to avoid multiple // requests. export const NOT_FETCHABLE_STATUSES: FetchStatus[] = [ - 'NOT_AVAILABLE', 'FETCHING', 'POLLING', 'REFRESHING', diff --git a/packages/compass-indexes/test/setup-store.ts b/packages/compass-indexes/test/setup-store.ts index 10422fe801b..8c5747dc644 100644 --- a/packages/compass-indexes/test/setup-store.ts +++ b/packages/compass-indexes/test/setup-store.ts @@ -122,11 +122,12 @@ export async function setupStoreAndWait( 'READY', 'ERROR', ]); - expect(store.getState().searchIndexes.status).to.be.oneOf([ - 'NOT_AVAILABLE', - 'READY', - 'ERROR', - ]); + if (store.getState().isSearchIndexesSupported) { + expect(store.getState().searchIndexes.status).to.be.oneOf([ + 'READY', + 'ERROR', + ]); + } }); return store; }