Skip to content

Commit 43fa226

Browse files
committed
refactor: remove in-progress states
1 parent 2f2a8c6 commit 43fa226

File tree

10 files changed

+88
-217
lines changed

10 files changed

+88
-217
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';
@@ -317,19 +316,11 @@ export function CreateShardKeyForm({
317316
}
318317

319318
export default connect(
320-
(state: RootState) => {
321-
return {
322-
namespace: state.namespace,
323-
isSubmittingForSharding: [
324-
ShardingStatuses.SUBMITTING_FOR_SHARDING,
325-
ShardingStatuses.SUBMITTING_FOR_SHARDING_ERROR,
326-
].includes(state.status),
327-
isCancellingSharding: [
328-
ShardingStatuses.CANCELLING_SHARDING,
329-
ShardingStatuses.CANCELLING_SHARDING_ERROR,
330-
].includes(state.status),
331-
};
332-
},
319+
(state: RootState) => ({
320+
namespace: state.namespace,
321+
isSubmittingForSharding: !!state.isSubmittingForSharding,
322+
isCancellingSharding: !!state.isCancellingSharding,
323+
}),
333324
{
334325
onCreateShardKey: createShardKey,
335326
}

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 & 3 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,
@@ -92,8 +91,7 @@ export default connect(
9291
namespace: state.namespace,
9392
shardKey: state.shardKey,
9493
shardZones: state.shardZones,
95-
isSubmittingForSharding:
96-
state.status === ShardingStatuses.SUBMITTING_FOR_SHARDING_INCOMPLETE,
94+
isSubmittingForSharding: !!state.isSubmittingForSharding,
9795
};
9896
},
9997
{

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.isUnmanagingNamespace,
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
@@ -10,7 +10,6 @@ import {
1010
import React from 'react';
1111
import ShardKeyMarkup from '../shard-key-markup';
1212
import {
13-
ShardingStatuses,
1413
unmanageNamespace,
1514
type RootState,
1615
type ShardKey,
@@ -104,8 +103,7 @@ export default connect(
104103
shardKey: state.shardKey,
105104
requestedShardKey:
106105
state.managedNamespace && getRequestedShardKey(state.managedNamespace),
107-
isUnmanagingNamespace:
108-
state.status === ShardingStatuses.UNMANAGING_NAMESPACE_MISMATCH,
106+
isUnmanagingNamespace: !!state.isUnmanagingNamespace,
109107
};
110108
},
111109
{

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

Lines changed: 3 additions & 9 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 { containerStyles, bannerStyles } from '../common-styles';
1814

@@ -69,10 +65,8 @@ export default connect(
6965
}
7066
return {
7167
shardingError: state.shardingError,
72-
isCancellingSharding:
73-
state.status === ShardingStatuses.CANCELLING_SHARDING_ERROR,
74-
isSubmittingForSharding:
75-
state.status === ShardingStatuses.SUBMITTING_FOR_SHARDING_ERROR,
68+
isCancellingSharding: !!state.isCancellingSharding,
69+
isSubmittingForSharding: !!state.isSubmittingForSharding,
7670
};
7771
},
7872
{

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

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,7 @@ import {
1010
SpinLoader,
1111
} from '@mongodb-js/compass-components';
1212
import { connect } from 'react-redux';
13-
import {
14-
cancelSharding,
15-
type RootState,
16-
ShardingStatuses,
17-
} from '../../store/reducer';
13+
import { cancelSharding, type RootState } from '../../store/reducer';
1814
import { containerStyles, bannerStyles } from '../common-styles';
1915

2016
const nbsp = '\u00a0';
@@ -65,7 +61,7 @@ export function ShardingState({
6561

6662
export default connect(
6763
(state: RootState) => ({
68-
isCancellingSharding: state.status === ShardingStatuses.CANCELLING_SHARDING,
64+
isCancellingSharding: !!state.isCancellingSharding,
6965
}),
7066
{
7167
onCancelSharding: cancelSharding,

packages/compass-global-writes/src/store/index.spec.ts

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ describe('GlobalWritesStore Store', function () {
254254
shouldAdvanceTime: true,
255255
});
256256
const promise = store.dispatch(createShardKey(shardKeyData));
257-
expect(store.getState().status).to.equal('SUBMITTING_FOR_SHARDING');
257+
expect(store.getState().isSubmittingForSharding).to.equal(true);
258258
mockManagedNamespace = true;
259259
await promise;
260260
expect(store.getState().status).to.equal('SHARDING');
@@ -264,6 +264,7 @@ describe('GlobalWritesStore Store', function () {
264264
clock.tick(POLLING_INTERVAL);
265265
await waitFor(() => {
266266
expect(store.getState().status).to.equal('SHARD_KEY_CORRECT');
267+
expect(store.getState().isSubmittingForSharding).to.be.undefined;
267268
});
268269
});
269270

@@ -283,7 +284,7 @@ describe('GlobalWritesStore Store', function () {
283284
shouldAdvanceTime: true,
284285
});
285286
const promise = store.dispatch(createShardKey(shardKeyData));
286-
expect(store.getState().status).to.equal('SUBMITTING_FOR_SHARDING');
287+
expect(store.getState().isSubmittingForSharding).to.equal(true);
287288
await promise;
288289
expect(store.getState().status).to.equal('SHARDING');
289290

@@ -292,6 +293,7 @@ describe('GlobalWritesStore Store', function () {
292293
clock.tick(POLLING_INTERVAL);
293294
await waitFor(() => {
294295
expect(store.getState().status).to.equal('SHARDING_ERROR');
296+
expect(store.getState().isSubmittingForSharding).to.be.undefined;
295297
expect(store.getState().shardingError).to.equal(
296298
`Failed to shard ${NS}`
297299
); // the original error text was: `before timestamp[01:02:03.456]Failed to shard ${NS}`
@@ -310,9 +312,10 @@ describe('GlobalWritesStore Store', function () {
310312

311313
// user tries to submit for sharding, but the request fails
312314
const promise = store.dispatch(createShardKey(shardKeyData));
313-
expect(store.getState().status).to.equal('SUBMITTING_FOR_SHARDING');
315+
expect(store.getState().isSubmittingForSharding).to.equal(true);
314316
await promise;
315317
expect(store.getState().status).to.equal('UNSHARDED');
318+
expect(store.getState().isSubmittingForSharding).to.be.undefined;
316319
});
317320

318321
it('sharding -> valid shard key', async function () {
@@ -448,9 +451,7 @@ describe('GlobalWritesStore Store', function () {
448451
// user asks to resume geosharding
449452
const promise = store.dispatch(resumeManagedNamespace());
450453
mockManagedNamespace = true;
451-
expect(store.getState().status).to.equal(
452-
'SUBMITTING_FOR_SHARDING_INCOMPLETE'
453-
);
454+
expect(store.getState().isSubmittingForSharding).to.equal(true);
454455
await promise;
455456

456457
// sharding
@@ -460,10 +461,11 @@ describe('GlobalWritesStore Store', function () {
460461
clock.tick(POLLING_INTERVAL);
461462
await waitFor(() => {
462463
expect(store.getState().status).to.equal('SHARD_KEY_CORRECT');
464+
expect(store.getState().isSubmittingForSharding).to.be.undefined;
463465
});
464466
});
465467

466-
it('incomplete setup -> sharding -> incomplete setup (request was cancelled)', async function () {
468+
it.only('incomplete setup -> sharding -> incomplete setup (request was cancelled)', async function () {
467469
// initial state -> incomplete shardingSetup
468470
clock = sinon.useFakeTimers({
469471
shouldAdvanceTime: true,
@@ -479,9 +481,7 @@ describe('GlobalWritesStore Store', function () {
479481

480482
// user asks to resume geosharding
481483
const promise = store.dispatch(resumeManagedNamespace());
482-
expect(store.getState().status).to.equal(
483-
'SUBMITTING_FOR_SHARDING_INCOMPLETE'
484-
);
484+
expect(store.getState().isSubmittingForSharding).to.equal(true);
485485
await promise;
486486

487487
// sharding
@@ -493,6 +493,8 @@ describe('GlobalWritesStore Store', function () {
493493
clock.tick(POLLING_INTERVAL);
494494
await waitFor(() => {
495495
expect(store.getState().status).to.equal('INCOMPLETE_SHARDING_SETUP');
496+
expect(store.getState().isSubmittingForSharding).to.be.undefined;
497+
expect(store.getState().isCancellingSharding).to.be.undefined;
496498
});
497499
});
498500

@@ -513,14 +515,13 @@ describe('GlobalWritesStore Store', function () {
513515

514516
// user asks to resume geosharding
515517
const promise = store.dispatch(resumeManagedNamespace());
516-
expect(store.getState().status).to.equal(
517-
'SUBMITTING_FOR_SHARDING_INCOMPLETE'
518-
);
518+
expect(store.getState().isSubmittingForSharding).to.equal(true);
519519
await promise;
520520

521521
// it failed
522522
await waitFor(() => {
523523
expect(store.getState().status).to.equal('INCOMPLETE_SHARDING_SETUP');
524+
expect(store.getState().isSubmittingForSharding).to.be.undefined;
524525
});
525526
});
526527

@@ -537,9 +538,10 @@ describe('GlobalWritesStore Store', function () {
537538

538539
// user asks to unmanage
539540
const promise = store.dispatch(unmanageNamespace());
540-
expect(store.getState().status).to.equal('UNMANAGING_NAMESPACE');
541+
expect(store.getState().isUnmanagingNamespace).to.equal(true);
541542
await promise;
542543
expect(store.getState().status).to.equal('INCOMPLETE_SHARDING_SETUP');
544+
expect(store.getState().isUnmanagingNamespace).to.be.undefined;
543545
});
544546

545547
it('valid shard key -> valid shard key (failed unmanage attempt)', async function () {
@@ -559,9 +561,10 @@ describe('GlobalWritesStore Store', function () {
559561
// user asks to unmanage
560562
mockFailure = true;
561563
const promise = store.dispatch(unmanageNamespace());
562-
expect(store.getState().status).to.equal('UNMANAGING_NAMESPACE');
564+
expect(store.getState().isUnmanagingNamespace).to.equal(true);
563565
await promise;
564566
expect(store.getState().status).to.equal('SHARD_KEY_CORRECT');
567+
expect(store.getState().isUnmanagingNamespace).to.be.undefined;
565568
});
566569

567570
context('invalid and mismatching shard keys', function () {
@@ -654,11 +657,10 @@ describe('GlobalWritesStore Store', function () {
654657

655658
// user asks to unmanage
656659
const promise = store.dispatch(unmanageNamespace());
657-
expect(store.getState().status).to.equal(
658-
'UNMANAGING_NAMESPACE_MISMATCH'
659-
);
660+
expect(store.getState().isUnmanagingNamespace).to.equal(true);
660661
await promise;
661662
expect(store.getState().status).to.equal('INCOMPLETE_SHARDING_SETUP');
663+
expect(store.getState().isUnmanagingNamespace).to.be.undefined;
662664
});
663665
});
664666

@@ -707,7 +709,7 @@ describe('GlobalWritesStore Store', function () {
707709
// user submits the form
708710
const promise = store.dispatch(createShardKey(shardKeyData));
709711
mockShardingError = false;
710-
expect(store.getState().status).to.equal('SUBMITTING_FOR_SHARDING_ERROR');
712+
expect(store.getState().isSubmittingForSharding).to.equal(true);
711713
await promise;
712714
expect(store.getState().status).to.equal('SHARDING');
713715

@@ -716,6 +718,7 @@ describe('GlobalWritesStore Store', function () {
716718
clock.tick(POLLING_INTERVAL);
717719
await waitFor(() => {
718720
expect(store.getState().status).to.equal('SHARD_KEY_CORRECT');
721+
expect(store.getState().isSubmittingForSharding).to.be.undefined;
719722
});
720723
});
721724

0 commit comments

Comments
 (0)