Skip to content

Commit

Permalink
untangle NOT_AVAILABLE
Browse files Browse the repository at this point in the history
  • Loading branch information
lerouxb committed Sep 23, 2024
1 parent 385106a commit 14e1ff8
Show file tree
Hide file tree
Showing 9 changed files with 71 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ describe('IndexesToolbar Component', function () {
isWritable={true}
writeStateDescription={undefined}
onRefreshIndexes={() => {}}
isAtlasSearchSupported={false}
isSearchIndexesSupported={false}
isRefreshing={false}
onIndexViewChanged={() => {}}
onCreateRegularIndexClick={() => {}}
Expand Down Expand Up @@ -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 () {
Expand All @@ -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 () {
Expand Down Expand Up @@ -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,
});

Expand All @@ -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,
});

Expand Down Expand Up @@ -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');
Expand All @@ -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');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -59,7 +58,7 @@ type IndexesToolbarProps = {
onCreateRegularIndexClick: () => void;
onCreateSearchIndexClick: () => void;
writeStateDescription?: string;
isAtlasSearchSupported: boolean;
isSearchIndexesSupported: boolean;
// via withPreferences:
readOnly?: boolean;
};
Expand All @@ -74,7 +73,7 @@ export const IndexesToolbar: React.FunctionComponent<IndexesToolbarProps> = ({
isRefreshing,
writeStateDescription,
hasTooManyIndexes,
isAtlasSearchSupported,
isSearchIndexesSupported,
onRefreshIndexes,
onIndexViewChanged,
readOnly, // preferences readOnly.
Expand Down Expand Up @@ -104,7 +103,7 @@ export const IndexesToolbar: React.FunctionComponent<IndexesToolbarProps> = ({
<div className={createIndexButtonContainerStyles}>
<CreateIndexButton
isSearchManagementActive={isSearchManagementActive}
isAtlasSearchSupported={isAtlasSearchSupported}
isSearchIndexesSupported={isSearchIndexesSupported}
isWritable={isWritable}
onCreateRegularIndexClick={onCreateRegularIndexClick}
onCreateSearchIndexClick={onCreateSearchIndexClick}
Expand Down Expand Up @@ -145,7 +144,7 @@ export const IndexesToolbar: React.FunctionComponent<IndexesToolbarProps> = ({
>
Indexes
</SegmentedControlOption>
{!isAtlasSearchSupported && (
{!isSearchIndexesSupported && (
<Tooltip
align="top"
justify="middle"
Expand Down Expand Up @@ -173,7 +172,7 @@ export const IndexesToolbar: React.FunctionComponent<IndexesToolbarProps> = ({
</p>
</Tooltip>
)}
{isAtlasSearchSupported && (
{isSearchIndexesSupported && (
<SegmentedControlOption
data-testid="search-indexes-tab"
value="search-indexes"
Expand All @@ -199,7 +198,7 @@ export const IndexesToolbar: React.FunctionComponent<IndexesToolbarProps> = ({

type CreateIndexButtonProps = {
isSearchManagementActive: boolean;
isAtlasSearchSupported: boolean;
isSearchIndexesSupported: boolean;
isWritable: boolean;
onCreateRegularIndexClick: () => void;
onCreateSearchIndexClick: () => void;
Expand All @@ -211,7 +210,7 @@ export const CreateIndexButton: React.FunctionComponent<
CreateIndexButtonProps
> = ({
isSearchManagementActive,
isAtlasSearchSupported,
isSearchIndexesSupported,
isWritable,
onCreateRegularIndexClick,
onCreateSearchIndexClick,
Expand All @@ -228,7 +227,7 @@ export const CreateIndexButton: React.FunctionComponent<
[onCreateRegularIndexClick, onCreateSearchIndexClick]
);

if (isAtlasSearchSupported && isSearchManagementActive) {
if (isSearchIndexesSupported && isSearchManagementActive) {
return (
<DropdownMenuButton
data-testid="multiple-index-types-creation-dropdown"
Expand Down Expand Up @@ -264,17 +263,19 @@ export const CreateIndexButton: React.FunctionComponent<
const mapState = ({
isWritable,
isReadonlyView,
isSearchIndexesSupported,
description,
serverVersion,
searchIndexes,
indexView,
}: RootState) => ({
isWritable,
isReadonlyView,
isSearchIndexesSupported,
writeStateDescription: description,
indexView,
serverVersion,
isAtlasSearchSupported: searchIndexes.status !== FetchStatuses.NOT_AVAILABLE,
searchIndexes,
});

const mapDispatch = {
Expand Down
4 changes: 4 additions & 0 deletions packages/compass-indexes/src/modules/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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,

Expand Down
Original file line number Diff line number Diff line change
@@ -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,
});
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
});

Expand Down
2 changes: 1 addition & 1 deletion packages/compass-indexes/src/modules/search-indexes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
9 changes: 1 addition & 8 deletions packages/compass-indexes/src/stores/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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({
Expand Down
5 changes: 0 additions & 5 deletions packages/compass-indexes/src/utils/fetch-status.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
export enum FetchStatuses {
/**
* No support. Default status.
*/
NOT_AVAILABLE = 'NOT_AVAILABLE',
/**
* We do not have a list yet.
*/
Expand Down Expand Up @@ -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',
Expand Down
11 changes: 6 additions & 5 deletions packages/compass-indexes/test/setup-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

0 comments on commit 14e1ff8

Please sign in to comment.