diff --git a/packages/compass-global-writes/src/components/index.tsx b/packages/compass-global-writes/src/components/index.tsx
index f53173abf37..ff0a5b02fa4 100644
--- a/packages/compass-global-writes/src/components/index.tsx
+++ b/packages/compass-global-writes/src/components/index.tsx
@@ -47,7 +47,10 @@ function ShardingStateView({
);
}
- if (shardingStatus === ShardingStatuses.UNSHARDED) {
+ if (
+ shardingStatus === ShardingStatuses.UNSHARDED ||
+ shardingStatus === ShardingStatuses.SUBMITTING_FOR_SHARDING
+ ) {
return ;
}
diff --git a/packages/compass-global-writes/src/components/states/unsharded.tsx b/packages/compass-global-writes/src/components/states/unsharded.tsx
index 39b37e17186..a6a0406d93f 100644
--- a/packages/compass-global-writes/src/components/states/unsharded.tsx
+++ b/packages/compass-global-writes/src/components/states/unsharded.tsx
@@ -23,7 +23,7 @@ import {
import { useAutocompleteFields } from '@mongodb-js/compass-field-store';
import { connect } from 'react-redux';
import type { CreateShardKeyData, RootState } from '../../store/reducer';
-import { createShardKey } from '../../store/reducer';
+import { createShardKey, ShardingStatuses } from '../../store/reducer';
const nbsp = '\u00a0';
@@ -329,7 +329,7 @@ export function UnshardedState(props: UnshardedStateProps) {
export default connect(
(state: RootState) => ({
namespace: state.namespace,
- isLoading: state.createShardkey.isLoading,
+ isLoading: state.status === ShardingStatuses.SUBMITTING_FOR_SHARDING,
}),
{
onCreateShardKey: createShardKey,
diff --git a/packages/compass-global-writes/src/store/reducer.ts b/packages/compass-global-writes/src/store/reducer.ts
index e9b9ccf80f0..17e1dba65db 100644
--- a/packages/compass-global-writes/src/store/reducer.ts
+++ b/packages/compass-global-writes/src/store/reducer.ts
@@ -21,9 +21,9 @@ export type CreateShardKeyData = Pick<
enum GlobalWritesActionTypes {
IsManagedNamespaceFetched = 'global-writes/IsManagedNamespaceFetched',
- ShardingInProgressStarted = 'global-writes/ShardingInProgressStarted',
- ShardingInProgressFinished = 'global-writes/ShardingInProgressFinished',
- ShardingInProgressErrored = 'global-writes/ShardingInProgressErrored',
+ SubmittingForShardingStarted = 'global-writes/SubmittingForShardingStarted',
+ SubmittingForShardingFinished = 'global-writes/SubmittingForShardingFinished',
+ SubmittingForShardingErrored = 'global-writes/SubmittingForShardingErrored',
}
type IsManagedNamespaceFetchedAction = {
@@ -31,16 +31,16 @@ type IsManagedNamespaceFetchedAction = {
isNamespaceManaged: boolean;
};
-type ShardingInProgressStartedAction = {
- type: GlobalWritesActionTypes.ShardingInProgressStarted;
+type SubmittingForShardingStartedAction = {
+ type: GlobalWritesActionTypes.SubmittingForShardingStarted;
};
-type ShardingInProgressFinishedAction = {
- type: GlobalWritesActionTypes.ShardingInProgressFinished;
+type SubmittingForShardingFinishedAction = {
+ type: GlobalWritesActionTypes.SubmittingForShardingFinished;
};
-type ShardingInProgressErroredAction = {
- type: GlobalWritesActionTypes.ShardingInProgressErrored;
+type SubmittingForShardingErroredAction = {
+ type: GlobalWritesActionTypes.SubmittingForShardingErrored;
};
export enum ShardingStatuses {
@@ -54,6 +54,12 @@ export enum ShardingStatuses {
*/
UNSHARDED = 'UNSHARDED',
+ /**
+ * State when user submits namespace to be sharded and
+ * we are waiting for server to accept the request.
+ */
+ SUBMITTING_FOR_SHARDING = 'SUBMITTING_FOR_SHARDING',
+
/**
* Namespace is being sharded.
*/
@@ -66,18 +72,12 @@ export type RootState = {
namespace: string;
isNamespaceSharded: boolean;
status: ShardingStatus;
- createShardkey: {
- isLoading: boolean;
- };
};
const initialState: RootState = {
namespace: '',
isNamespaceSharded: false,
status: ShardingStatuses.NOT_READY,
- createShardkey: {
- isLoading: false,
- },
};
const reducer: Reducer = (state = initialState, action) => {
@@ -97,46 +97,39 @@ const reducer: Reducer = (state = initialState, action) => {
}
if (
- isAction(
+ isAction(
action,
- GlobalWritesActionTypes.ShardingInProgressStarted
+ GlobalWritesActionTypes.SubmittingForShardingStarted
)
) {
return {
...state,
- createShardkey: {
- isLoading: true,
- },
+ status: ShardingStatuses.SUBMITTING_FOR_SHARDING,
};
}
if (
- isAction(
+ isAction(
action,
- GlobalWritesActionTypes.ShardingInProgressFinished
+ GlobalWritesActionTypes.SubmittingForShardingFinished
)
) {
return {
...state,
isNamespaceSharded: true,
status: ShardingStatuses.SHARDING,
- createShardkey: {
- isLoading: false,
- },
};
}
if (
- isAction(
+ isAction(
action,
- GlobalWritesActionTypes.ShardingInProgressErrored
+ GlobalWritesActionTypes.SubmittingForShardingErrored
)
) {
return {
...state,
- createShardkey: {
- isLoading: false,
- },
+ status: ShardingStatuses.UNSHARDED,
};
}
@@ -198,9 +191,9 @@ export const createShardKey =
data: CreateShardKeyData
): GlobalWritesThunkAction<
Promise,
- | ShardingInProgressStartedAction
- | ShardingInProgressFinishedAction
- | ShardingInProgressErroredAction
+ | SubmittingForShardingStartedAction
+ | SubmittingForShardingFinishedAction
+ | SubmittingForShardingErroredAction
> =>
async (
dispatch,
@@ -215,7 +208,7 @@ export const createShardKey =
const { clusterName, projectId } = connectionInfoRef.current.atlasMetadata;
dispatch({
- type: GlobalWritesActionTypes.ShardingInProgressStarted,
+ type: GlobalWritesActionTypes.SubmittingForShardingStarted,
});
try {
@@ -224,7 +217,7 @@ export const createShardKey =
clusterName,
});
dispatch({
- type: GlobalWritesActionTypes.ShardingInProgressFinished,
+ type: GlobalWritesActionTypes.SubmittingForShardingFinished,
});
} catch (error) {
logger.log.error(
@@ -243,7 +236,7 @@ export const createShardKey =
variant: 'important',
});
dispatch({
- type: GlobalWritesActionTypes.ShardingInProgressErrored,
+ type: GlobalWritesActionTypes.SubmittingForShardingErrored,
});
}
};