Skip to content

Commit 18d9d55

Browse files
committed
more cleanup
1 parent 46e6b3d commit 18d9d55

File tree

1 file changed

+35
-16
lines changed
  • packages/compass-global-writes/src/store

1 file changed

+35
-16
lines changed

packages/compass-global-writes/src/store/reducer.ts

Lines changed: 35 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -187,20 +187,18 @@ export type RootState = {
187187
namespace: string;
188188
managedNamespace?: ManagedNamespace;
189189
shardZones: ShardZoneData[];
190-
userActionInProgress?:
191-
| 'submitForSharding'
192-
| 'cancelSharding'
193-
| 'unmanageNamespace';
194190
} & (
195191
| {
196192
status: ShardingStatuses.LOADING_ERROR;
197-
userActionInProgress?: never;
198193
shardKey?: ShardKey;
199-
shardingError?: never;
200194
loadingError: string;
195+
//////////////
196+
userActionInProgress?: never;
197+
shardingError?: never;
201198
}
202199
| {
203200
status: ShardingStatuses.NOT_READY;
201+
//////////////
204202
userActionInProgress?: never;
205203
shardKey?: never;
206204
shardingError?: never;
@@ -209,9 +207,8 @@ export type RootState = {
209207
| {
210208
status: ShardingStatuses.UNSHARDED;
211209
userActionInProgress?: 'submitForSharding';
212-
shardKey?: ShardKey;
213-
// shardKey might exist if the collection was sharded before
214-
// and then unmanaged
210+
//////////////
211+
shardKey?: never;
215212
shardingError?: never;
216213
loadingError?: never;
217214
}
@@ -223,23 +220,41 @@ export type RootState = {
223220
* if the collection was sharded previously and then unmanaged
224221
*/
225222
shardKey?: ShardKey;
223+
//////////////
226224
shardingError?: never;
227225
loadingError?: never;
228226
}
229227
| {
230228
status: ShardingStatuses.SHARDING_ERROR;
231229
userActionInProgress?: 'cancelSharding' | 'submitForSharding';
232-
shardKey?: never;
233230
shardingError: string;
231+
//////////////
232+
shardKey?: never;
234233
loadingError?: never;
235234
}
236235
| {
237236
status:
238237
| ShardingStatuses.SHARD_KEY_CORRECT
239-
| ShardingStatuses.SHARD_KEY_INVALID
240-
| ShardingStatuses.SHARD_KEY_MISMATCH
241-
| ShardingStatuses.INCOMPLETE_SHARDING_SETUP;
238+
| ShardingStatuses.SHARD_KEY_MISMATCH;
239+
userActionInProgress?: 'unmanageNamespace';
240+
shardKey: ShardKey;
241+
//////////////
242+
shardingError?: never;
243+
loadingError?: never;
244+
}
245+
| {
246+
status: ShardingStatuses.SHARD_KEY_INVALID;
247+
shardKey: ShardKey;
248+
//////////////
249+
userActionInProgress?: never;
250+
shardingError?: never;
251+
loadingError?: never;
252+
}
253+
| {
254+
status: ShardingStatuses.INCOMPLETE_SHARDING_SETUP;
255+
userActionInProgress?: 'cancelSharding' | 'submitForSharding';
242256
shardKey: ShardKey;
257+
//////////////
243258
shardingError?: never;
244259
loadingError?: never;
245260
}
@@ -296,6 +311,7 @@ const reducer: Reducer<RootState, Action> = (state = initialState, action) => {
296311
action.shardKey,
297312
state.managedNamespace
298313
),
314+
userActionInProgress: undefined,
299315
shardKey: action.shardKey,
300316
shardingError: undefined,
301317
};
@@ -419,6 +435,7 @@ const reducer: Reducer<RootState, Action> = (state = initialState, action) => {
419435
userActionInProgress: undefined,
420436
managedNamespace: undefined,
421437
shardingError: undefined,
438+
shardKey: undefined,
422439
status: ShardingStatuses.UNSHARDED,
423440
};
424441
}
@@ -777,13 +794,15 @@ export const fetchNamespaceShardKey = (): GlobalWritesThunkAction<
777794
]);
778795

779796
if (managedNamespace && !shardKey) {
780-
// if there is an existing shard key and an error both,
781-
// means we have a key mismatch
782-
// this will be handled in NamespaceShardKeyFetched
783797
if (!shardingError) {
798+
// there is neither a shardKey nor shardingError
799+
// means sharding is in progress
784800
dispatch(setNamespaceBeingSharded());
785801
return;
786802
}
803+
// if there is an existing shard key and an error both,
804+
// means we have a key mismatch
805+
// this will be handled in NamespaceShardKeyFetched
787806
dispatch({
788807
type: GlobalWritesActionTypes.NamespaceShardingErrorFetched,
789808
error: shardingError,

0 commit comments

Comments
 (0)