Skip to content

Commit 203ce42

Browse files
authored
refactor(compass-global-writes): remove in-progress states (#6475)
1 parent c79c948 commit 203ce42

File tree

11 files changed

+261
-350
lines changed

11 files changed

+261
-350
lines changed

packages/compass-global-writes/src/components/create-shard-key-form.tsx

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import {
2121
import {
2222
createShardKey,
2323
type RootState,
24-
ShardingStatuses,
2524
type CreateShardKeyData,
2625
} from '../store/reducer';
2726
import { useAutocompleteFields } from '@mongodb-js/compass-field-store';
@@ -320,19 +319,11 @@ export function CreateShardKeyForm({
320319
}
321320

322321
export default connect(
323-
(state: RootState) => {
324-
return {
325-
namespace: state.namespace,
326-
isSubmittingForSharding: [
327-
ShardingStatuses.SUBMITTING_FOR_SHARDING,
328-
ShardingStatuses.SUBMITTING_FOR_SHARDING_ERROR,
329-
].includes(state.status),
330-
isCancellingSharding: [
331-
ShardingStatuses.CANCELLING_SHARDING,
332-
ShardingStatuses.CANCELLING_SHARDING_ERROR,
333-
].includes(state.status),
334-
};
335-
},
322+
(state: RootState) => ({
323+
namespace: state.namespace,
324+
isSubmittingForSharding: state.userActionInProgress === 'submitForSharding',
325+
isCancellingSharding: state.userActionInProgress === 'cancelSharding',
326+
}),
336327
{
337328
onCreateShardKey: createShardKey,
338329
}

packages/compass-global-writes/src/components/index.spec.tsx

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,6 @@ describe('Compass GlobalWrites Plugin', function () {
1515
expect(screen.getByTestId('shard-collection-button')).to.exist;
1616
});
1717

18-
it('renders plugin in SUBMITTING_FOR_SHARDING state', async function () {
19-
await renderWithStore(
20-
<GlobalWrites shardingStatus={'SUBMITTING_FOR_SHARDING'} />
21-
);
22-
expect(screen.getByTestId('shard-collection-button')).to.exist;
23-
});
24-
2518
it('renders plugin in SHARDING state', async function () {
2619
await renderWithStore(<GlobalWrites shardingStatus={'SHARDING'} />);
2720
expect(screen.getByText(/sharding your collection/i)).to.exist;

packages/compass-global-writes/src/components/index.tsx

Lines changed: 6 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -44,50 +44,31 @@ function ShardingStateView({
4444
}: {
4545
shardingStatus: Exclude<ShardingStatus, 'NOT_READY'>;
4646
}) {
47-
if (
48-
shardingStatus === ShardingStatuses.UNSHARDED ||
49-
shardingStatus === ShardingStatuses.SUBMITTING_FOR_SHARDING
50-
) {
47+
if (shardingStatus === ShardingStatuses.UNSHARDED) {
5148
return <UnshardedState />;
5249
}
5350

54-
if (
55-
shardingStatus === ShardingStatuses.SHARDING ||
56-
shardingStatus === ShardingStatuses.CANCELLING_SHARDING
57-
) {
51+
if (shardingStatus === ShardingStatuses.SHARDING) {
5852
return <ShardingState />;
5953
}
6054

61-
if (
62-
shardingStatus === ShardingStatuses.SHARDING_ERROR ||
63-
shardingStatus === ShardingStatuses.CANCELLING_SHARDING_ERROR ||
64-
shardingStatus === ShardingStatuses.SUBMITTING_FOR_SHARDING_ERROR
65-
) {
55+
if (shardingStatus === ShardingStatuses.SHARDING_ERROR) {
6656
return <ShardingError />;
6757
}
6858

69-
if (
70-
shardingStatus === ShardingStatuses.SHARD_KEY_CORRECT ||
71-
shardingStatus === ShardingStatuses.UNMANAGING_NAMESPACE
72-
) {
59+
if (shardingStatus === ShardingStatuses.SHARD_KEY_CORRECT) {
7360
return <ShardKeyCorrect />;
7461
}
7562

7663
if (shardingStatus === ShardingStatuses.SHARD_KEY_INVALID) {
7764
return <ShardKeyInvalid />;
7865
}
7966

80-
if (
81-
shardingStatus === ShardingStatuses.SHARD_KEY_MISMATCH ||
82-
shardingStatus === ShardingStatuses.UNMANAGING_NAMESPACE_MISMATCH
83-
) {
67+
if (shardingStatus === ShardingStatuses.SHARD_KEY_MISMATCH) {
8468
return <ShardKeyMismatch />;
8569
}
8670

87-
if (
88-
shardingStatus === ShardingStatuses.INCOMPLETE_SHARDING_SETUP ||
89-
shardingStatus === ShardingStatuses.SUBMITTING_FOR_SHARDING_INCOMPLETE
90-
) {
71+
if (shardingStatus === ShardingStatuses.INCOMPLETE_SHARDING_SETUP) {
9172
return <IncompleteShardingSetup />;
9273
}
9374

packages/compass-global-writes/src/components/states/incomplete-sharding-setup.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import React from 'react';
1212
import ShardKeyMarkup from '../shard-key-markup';
1313
import {
1414
resumeManagedNamespace,
15-
ShardingStatuses,
1615
type ShardZoneData,
1716
type RootState,
1817
type ShardKey,
@@ -90,7 +89,7 @@ export default connect(
9089
shardKey: state.shardKey,
9190
shardZones: state.shardZones,
9291
isSubmittingForSharding:
93-
state.status === ShardingStatuses.SUBMITTING_FOR_SHARDING_INCOMPLETE,
92+
state.userActionInProgress === 'submitForSharding',
9493
};
9594
},
9695
{

packages/compass-global-writes/src/components/states/shard-key-correct.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import {
1010
} from '@mongodb-js/compass-components';
1111
import { connect } from 'react-redux';
1212
import {
13-
ShardingStatuses,
1413
unmanageNamespace,
1514
type RootState,
1615
type ShardKey,
@@ -86,8 +85,7 @@ export default connect(
8685
namespace: state.namespace,
8786
shardKey: state.shardKey,
8887
shardZones: state.shardZones,
89-
isUnmanagingNamespace:
90-
state.status === ShardingStatuses.UNMANAGING_NAMESPACE,
88+
isUnmanagingNamespace: state.userActionInProgress === 'unmanageNamespace',
9189
};
9290
},
9391
{

packages/compass-global-writes/src/components/states/shard-key-mismatch.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import {
88
import React from 'react';
99
import ShardKeyMarkup from '../shard-key-markup';
1010
import {
11-
ShardingStatuses,
1211
unmanageNamespace,
1312
type RootState,
1413
type ShardKey,
@@ -102,8 +101,7 @@ export default connect(
102101
shardKey: state.shardKey,
103102
requestedShardKey:
104103
state.managedNamespace && getRequestedShardKey(state.managedNamespace),
105-
isUnmanagingNamespace:
106-
state.status === ShardingStatuses.UNMANAGING_NAMESPACE_MISMATCH,
104+
isUnmanagingNamespace: state.userActionInProgress === 'unmanageNamespace',
107105
};
108106
},
109107
{

packages/compass-global-writes/src/components/states/sharding-error.tsx

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,7 @@ import {
88
SpinLoader,
99
} from '@mongodb-js/compass-components';
1010
import { connect } from 'react-redux';
11-
import {
12-
cancelSharding,
13-
type RootState,
14-
ShardingStatuses,
15-
} from '../../store/reducer';
11+
import { cancelSharding, type RootState } from '../../store/reducer';
1612
import CreateShardKeyForm from '../create-shard-key-form';
1713
import {
1814
containerStyles,
@@ -68,10 +64,9 @@ export default connect(
6864
}
6965
return {
7066
shardingError: state.shardingError,
71-
isCancellingSharding:
72-
state.status === ShardingStatuses.CANCELLING_SHARDING_ERROR,
67+
isCancellingSharding: state.userActionInProgress === 'cancelSharding',
7368
isSubmittingForSharding:
74-
state.status === ShardingStatuses.SUBMITTING_FOR_SHARDING_ERROR,
69+
state.userActionInProgress === 'submitForSharding',
7570
};
7671
},
7772
{

packages/compass-global-writes/src/components/states/sharding.tsx

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,7 @@ import {
88
SpinLoader,
99
} from '@mongodb-js/compass-components';
1010
import { connect } from 'react-redux';
11-
import {
12-
cancelSharding,
13-
type RootState,
14-
ShardingStatuses,
15-
} from '../../store/reducer';
11+
import { cancelSharding, type RootState } from '../../store/reducer';
1612
import {
1713
containerStyles,
1814
bannerStyles,
@@ -62,7 +58,7 @@ export function ShardingState({
6258

6359
export default connect(
6460
(state: RootState) => ({
65-
isCancellingSharding: state.status === ShardingStatuses.CANCELLING_SHARDING,
61+
isCancellingSharding: state.userActionInProgress === 'cancelSharding',
6662
}),
6763
{
6864
onCancelSharding: cancelSharding,

0 commit comments

Comments
 (0)