From c170975555fd25b13c477ac1bc4dba6d1a37099e Mon Sep 17 00:00:00 2001 From: Paula Stachova Date: Mon, 4 Nov 2024 17:45:50 +0100 Subject: [PATCH] fix --- .../src/store/reducer.ts | 29 ++++++++++++++----- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/packages/compass-global-writes/src/store/reducer.ts b/packages/compass-global-writes/src/store/reducer.ts index 97d638e023c..2c2279f44f3 100644 --- a/packages/compass-global-writes/src/store/reducer.ts +++ b/packages/compass-global-writes/src/store/reducer.ts @@ -215,11 +215,9 @@ export type RootState = { | ShardingStatuses.UNSHARDED | ShardingStatuses.SUBMITTING_FOR_SHARDING | ShardingStatuses.CANCELLING_SHARDING; - /** - * note: shardKey might exist even for unsharded. - * if the collection was sharded previously and then unmanaged - */ shardKey?: ShardKey; + // shardKey might exist if the collection was sharded before + // and then unmanaged shardingError?: never; pollingTimeout?: never; } @@ -487,14 +485,29 @@ const reducer: Reducer = (state = initialState, action) => { ) && (state.status === ShardingStatuses.CANCELLING_SHARDING || state.status === ShardingStatuses.SHARDING_ERROR || - state.status === ShardingStatuses.CANCELLING_SHARDING_ERROR) + state.status === ShardingStatuses.CANCELLING_SHARDING_ERROR) && // the error might come before the cancel request was processed + !state.shardKey + ) { + return { + ...state, + status: ShardingStatuses.UNSHARDED, + shardingError: undefined, + }; + } + + if ( + isAction( + action, + GlobalWritesActionTypes.CancellingShardingFinished + ) && + state.status === ShardingStatuses.CANCELLING_SHARDING && + state.shardKey ) { return { ...state, - status: state.shardKey - ? ShardingStatuses.INCOMPLETE_SHARDING_SETUP - : ShardingStatuses.UNSHARDED, + shardKey: state.shardKey, + status: ShardingStatuses.INCOMPLETE_SHARDING_SETUP, shardingError: undefined, }; }