@@ -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 } ;
@@ -340,6 +356,26 @@ const reducer: Reducer<RootState, Action> = (state = initialState, action) => {
340356 } ;
341357 }
342358
359+ if (
360+ isAction < CancellingShardingErroredAction > (
361+ action ,
362+ GlobalWritesActionTypes . CancellingShardingErrored
363+ ) ||
364+ isAction < UnmanagingNamespaceErroredAction > (
365+ action ,
366+ GlobalWritesActionTypes . UnmanagingNamespaceErrored
367+ ) ||
368+ isAction < SubmittingForShardingErroredAction > (
369+ action ,
370+ GlobalWritesActionTypes . SubmittingForShardingErrored
371+ )
372+ ) {
373+ return {
374+ ...state ,
375+ userActionInProgress : undefined ,
376+ } ;
377+ }
378+
343379 if (
344380 isAction < SubmittingForShardingStartedAction > (
345381 action ,
@@ -389,22 +425,6 @@ const reducer: Reducer<RootState, Action> = (state = initialState, action) => {
389425 } ;
390426 }
391427
392- if (
393- isAction < CancellingShardingErroredAction > (
394- action ,
395- GlobalWritesActionTypes . CancellingShardingErrored
396- ) ||
397- isAction < UnmanagingNamespaceErroredAction > (
398- action ,
399- GlobalWritesActionTypes . UnmanagingNamespaceErrored
400- )
401- ) {
402- return {
403- ...state ,
404- userActionInProgress : undefined ,
405- } ;
406- }
407-
408428 if (
409429 isAction < CancellingShardingFinishedAction > (
410430 action ,
@@ -418,6 +438,7 @@ const reducer: Reducer<RootState, Action> = (state = initialState, action) => {
418438 ...state ,
419439 userActionInProgress : undefined ,
420440 managedNamespace : undefined ,
441+ shardKey : state . shardKey ,
421442 shardingError : undefined ,
422443 status : ShardingStatuses . UNSHARDED ,
423444 } ;
@@ -441,22 +462,6 @@ const reducer: Reducer<RootState, Action> = (state = initialState, action) => {
441462 } ;
442463 }
443464
444- if (
445- isAction < SubmittingForShardingErroredAction > (
446- action ,
447- GlobalWritesActionTypes . SubmittingForShardingErrored
448- ) &&
449- ( state . status === ShardingStatuses . UNSHARDED ||
450- state . status === ShardingStatuses . SHARDING_ERROR ||
451- state . status === ShardingStatuses . INCOMPLETE_SHARDING_SETUP )
452- ) {
453- return {
454- ...state ,
455- managedNamepsace : undefined ,
456- userActionInProgress : undefined ,
457- } ;
458- }
459-
460465 if (
461466 isAction < UnmanagingNamespaceStartedAction > (
462467 action ,
@@ -777,13 +782,15 @@ export const fetchNamespaceShardKey = (): GlobalWritesThunkAction<
777782 ] ) ;
778783
779784 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
783785 if ( ! shardingError ) {
786+ // there is neither a shardKey nor shardingError
787+ // means sharding is in progress
784788 dispatch ( setNamespaceBeingSharded ( ) ) ;
785789 return ;
786790 }
791+ // if there is an existing shard key and an error both,
792+ // means we have a key mismatch
793+ // this will be handled in NamespaceShardKeyFetched
787794 dispatch ( {
788795 type : GlobalWritesActionTypes . NamespaceShardingErrorFetched ,
789796 error : shardingError ,
0 commit comments