Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import {
import {
createShardKey,
type RootState,
ShardingStatuses,
type CreateShardKeyData,
} from '../store/reducer';
import { useAutocompleteFields } from '@mongodb-js/compass-field-store';
Expand Down Expand Up @@ -317,19 +316,11 @@ export function CreateShardKeyForm({
}

export default connect(
(state: RootState) => {
return {
namespace: state.namespace,
isSubmittingForSharding: [
ShardingStatuses.SUBMITTING_FOR_SHARDING,
ShardingStatuses.SUBMITTING_FOR_SHARDING_ERROR,
].includes(state.status),
isCancellingSharding: [
ShardingStatuses.CANCELLING_SHARDING,
ShardingStatuses.CANCELLING_SHARDING_ERROR,
].includes(state.status),
};
},
(state: RootState) => ({
namespace: state.namespace,
isSubmittingForSharding: !!state.isSubmittingForSharding,
isCancellingSharding: !!state.isCancellingSharding,
}),
{
onCreateShardKey: createShardKey,
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,6 @@ describe('Compass GlobalWrites Plugin', function () {
expect(screen.getByTestId('shard-collection-button')).to.exist;
});

it('renders plugin in SUBMITTING_FOR_SHARDING state', async function () {
await renderWithStore(
<GlobalWrites shardingStatus={'SUBMITTING_FOR_SHARDING'} />
);
expect(screen.getByTestId('shard-collection-button')).to.exist;
});

it('renders plugin in SHARDING state', async function () {
await renderWithStore(<GlobalWrites shardingStatus={'SHARDING'} />);
expect(screen.getByText(/sharding your collection/i)).to.exist;
Expand Down
31 changes: 6 additions & 25 deletions packages/compass-global-writes/src/components/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,50 +44,31 @@ function ShardingStateView({
}: {
shardingStatus: Exclude<ShardingStatus, 'NOT_READY'>;
}) {
if (
shardingStatus === ShardingStatuses.UNSHARDED ||
shardingStatus === ShardingStatuses.SUBMITTING_FOR_SHARDING
) {
if (shardingStatus === ShardingStatuses.UNSHARDED) {
return <UnshardedState />;
}

if (
shardingStatus === ShardingStatuses.SHARDING ||
shardingStatus === ShardingStatuses.CANCELLING_SHARDING
) {
if (shardingStatus === ShardingStatuses.SHARDING) {
return <ShardingState />;
}

if (
shardingStatus === ShardingStatuses.SHARDING_ERROR ||
shardingStatus === ShardingStatuses.CANCELLING_SHARDING_ERROR ||
shardingStatus === ShardingStatuses.SUBMITTING_FOR_SHARDING_ERROR
) {
if (shardingStatus === ShardingStatuses.SHARDING_ERROR) {
return <ShardingError />;
}

if (
shardingStatus === ShardingStatuses.SHARD_KEY_CORRECT ||
shardingStatus === ShardingStatuses.UNMANAGING_NAMESPACE
) {
if (shardingStatus === ShardingStatuses.SHARD_KEY_CORRECT) {
return <ShardKeyCorrect />;
}

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

if (
shardingStatus === ShardingStatuses.SHARD_KEY_MISMATCH ||
shardingStatus === ShardingStatuses.UNMANAGING_NAMESPACE_MISMATCH
) {
if (shardingStatus === ShardingStatuses.SHARD_KEY_MISMATCH) {
return <ShardKeyMismatch />;
}

if (
shardingStatus === ShardingStatuses.INCOMPLETE_SHARDING_SETUP ||
shardingStatus === ShardingStatuses.SUBMITTING_FOR_SHARDING_INCOMPLETE
) {
if (shardingStatus === ShardingStatuses.INCOMPLETE_SHARDING_SETUP) {
return <IncompleteShardingSetup />;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import React from 'react';
import ShardKeyMarkup from '../shard-key-markup';
import {
resumeManagedNamespace,
ShardingStatuses,
type ShardZoneData,
type RootState,
type ShardKey,
Expand Down Expand Up @@ -92,8 +91,7 @@ export default connect(
namespace: state.namespace,
shardKey: state.shardKey,
shardZones: state.shardZones,
isSubmittingForSharding:
state.status === ShardingStatuses.SUBMITTING_FOR_SHARDING_INCOMPLETE,
isSubmittingForSharding: !!state.isSubmittingForSharding,
};
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {
} from '@mongodb-js/compass-components';
import { connect } from 'react-redux';
import {
ShardingStatuses,
unmanageNamespace,
type RootState,
type ShardKey,
Expand Down Expand Up @@ -86,8 +85,7 @@ export default connect(
namespace: state.namespace,
shardKey: state.shardKey,
shardZones: state.shardZones,
isUnmanagingNamespace:
state.status === ShardingStatuses.UNMANAGING_NAMESPACE,
isUnmanagingNamespace: !!state.isUnmanagingNamespace,
};
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {
import React from 'react';
import ShardKeyMarkup from '../shard-key-markup';
import {
ShardingStatuses,
unmanageNamespace,
type RootState,
type ShardKey,
Expand Down Expand Up @@ -104,8 +103,7 @@ export default connect(
shardKey: state.shardKey,
requestedShardKey:
state.managedNamespace && getRequestedShardKey(state.managedNamespace),
isUnmanagingNamespace:
state.status === ShardingStatuses.UNMANAGING_NAMESPACE_MISMATCH,
isUnmanagingNamespace: !!state.isUnmanagingNamespace,
};
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,7 @@ import {
SpinLoader,
} from '@mongodb-js/compass-components';
import { connect } from 'react-redux';
import {
cancelSharding,
type RootState,
ShardingStatuses,
} from '../../store/reducer';
import { cancelSharding, type RootState } from '../../store/reducer';
import CreateShardKeyForm from '../create-shard-key-form';
import { containerStyles, bannerStyles } from '../common-styles';

Expand Down Expand Up @@ -69,10 +65,8 @@ export default connect(
}
return {
shardingError: state.shardingError,
isCancellingSharding:
state.status === ShardingStatuses.CANCELLING_SHARDING_ERROR,
isSubmittingForSharding:
state.status === ShardingStatuses.SUBMITTING_FOR_SHARDING_ERROR,
isCancellingSharding: !!state.isCancellingSharding,
isSubmittingForSharding: !!state.isSubmittingForSharding,
};
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,7 @@ import {
SpinLoader,
} from '@mongodb-js/compass-components';
import { connect } from 'react-redux';
import {
cancelSharding,
type RootState,
ShardingStatuses,
} from '../../store/reducer';
import { cancelSharding, type RootState } from '../../store/reducer';
import { containerStyles, bannerStyles } from '../common-styles';

const nbsp = '\u00a0';
Expand Down Expand Up @@ -65,7 +61,7 @@ export function ShardingState({

export default connect(
(state: RootState) => ({
isCancellingSharding: state.status === ShardingStatuses.CANCELLING_SHARDING,
isCancellingSharding: !!state.isCancellingSharding,
}),
{
onCancelSharding: cancelSharding,
Expand Down
41 changes: 22 additions & 19 deletions packages/compass-global-writes/src/store/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ describe('GlobalWritesStore Store', function () {
shouldAdvanceTime: true,
});
const promise = store.dispatch(createShardKey(shardKeyData));
expect(store.getState().status).to.equal('SUBMITTING_FOR_SHARDING');
expect(store.getState().isSubmittingForSharding).to.equal(true);
mockManagedNamespace = true;
await promise;
expect(store.getState().status).to.equal('SHARDING');
Expand All @@ -264,6 +264,7 @@ describe('GlobalWritesStore Store', function () {
clock.tick(POLLING_INTERVAL);
await waitFor(() => {
expect(store.getState().status).to.equal('SHARD_KEY_CORRECT');
expect(store.getState().isSubmittingForSharding).to.be.undefined;
});
});

Expand All @@ -283,7 +284,7 @@ describe('GlobalWritesStore Store', function () {
shouldAdvanceTime: true,
});
const promise = store.dispatch(createShardKey(shardKeyData));
expect(store.getState().status).to.equal('SUBMITTING_FOR_SHARDING');
expect(store.getState().isSubmittingForSharding).to.equal(true);
await promise;
expect(store.getState().status).to.equal('SHARDING');

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

// user tries to submit for sharding, but the request fails
const promise = store.dispatch(createShardKey(shardKeyData));
expect(store.getState().status).to.equal('SUBMITTING_FOR_SHARDING');
expect(store.getState().isSubmittingForSharding).to.equal(true);
await promise;
expect(store.getState().status).to.equal('UNSHARDED');
expect(store.getState().isSubmittingForSharding).to.be.undefined;
});

it('sharding -> valid shard key', async function () {
Expand Down Expand Up @@ -448,9 +451,7 @@ describe('GlobalWritesStore Store', function () {
// user asks to resume geosharding
const promise = store.dispatch(resumeManagedNamespace());
mockManagedNamespace = true;
expect(store.getState().status).to.equal(
'SUBMITTING_FOR_SHARDING_INCOMPLETE'
);
expect(store.getState().isSubmittingForSharding).to.equal(true);
await promise;

// sharding
Expand All @@ -460,10 +461,11 @@ describe('GlobalWritesStore Store', function () {
clock.tick(POLLING_INTERVAL);
await waitFor(() => {
expect(store.getState().status).to.equal('SHARD_KEY_CORRECT');
expect(store.getState().isSubmittingForSharding).to.be.undefined;
});
});

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

// user asks to resume geosharding
const promise = store.dispatch(resumeManagedNamespace());
expect(store.getState().status).to.equal(
'SUBMITTING_FOR_SHARDING_INCOMPLETE'
);
expect(store.getState().isSubmittingForSharding).to.equal(true);
await promise;

// sharding
Expand All @@ -493,6 +493,8 @@ describe('GlobalWritesStore Store', function () {
clock.tick(POLLING_INTERVAL);
await waitFor(() => {
expect(store.getState().status).to.equal('INCOMPLETE_SHARDING_SETUP');
expect(store.getState().isSubmittingForSharding).to.be.undefined;
expect(store.getState().isCancellingSharding).to.be.undefined;
});
});

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

// user asks to resume geosharding
const promise = store.dispatch(resumeManagedNamespace());
expect(store.getState().status).to.equal(
'SUBMITTING_FOR_SHARDING_INCOMPLETE'
);
expect(store.getState().isSubmittingForSharding).to.equal(true);
await promise;

// it failed
await waitFor(() => {
expect(store.getState().status).to.equal('INCOMPLETE_SHARDING_SETUP');
expect(store.getState().isSubmittingForSharding).to.be.undefined;
});
});

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

// user asks to unmanage
const promise = store.dispatch(unmanageNamespace());
expect(store.getState().status).to.equal('UNMANAGING_NAMESPACE');
expect(store.getState().isUnmanagingNamespace).to.equal(true);
await promise;
expect(store.getState().status).to.equal('INCOMPLETE_SHARDING_SETUP');
expect(store.getState().isUnmanagingNamespace).to.be.undefined;
});

it('valid shard key -> valid shard key (failed unmanage attempt)', async function () {
Expand All @@ -559,9 +561,10 @@ describe('GlobalWritesStore Store', function () {
// user asks to unmanage
mockFailure = true;
const promise = store.dispatch(unmanageNamespace());
expect(store.getState().status).to.equal('UNMANAGING_NAMESPACE');
expect(store.getState().isUnmanagingNamespace).to.equal(true);
await promise;
expect(store.getState().status).to.equal('SHARD_KEY_CORRECT');
expect(store.getState().isUnmanagingNamespace).to.be.undefined;
});

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

// user asks to unmanage
const promise = store.dispatch(unmanageNamespace());
expect(store.getState().status).to.equal(
'UNMANAGING_NAMESPACE_MISMATCH'
);
expect(store.getState().isUnmanagingNamespace).to.equal(true);
await promise;
expect(store.getState().status).to.equal('INCOMPLETE_SHARDING_SETUP');
expect(store.getState().isUnmanagingNamespace).to.be.undefined;
});
});

Expand Down Expand Up @@ -707,7 +709,7 @@ describe('GlobalWritesStore Store', function () {
// user submits the form
const promise = store.dispatch(createShardKey(shardKeyData));
mockShardingError = false;
expect(store.getState().status).to.equal('SUBMITTING_FOR_SHARDING_ERROR');
expect(store.getState().isSubmittingForSharding).to.equal(true);
await promise;
expect(store.getState().status).to.equal('SHARDING');

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

Expand Down
Loading
Loading