Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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 @@ -320,19 +319,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.userActionInProgress === 'submitForSharding',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's use enums here instead of raw strings for safety, and to emphasize this is another kind of status.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The type safety is the same with union types. We tend to use union types in Compass, unless there is a reason to prefer enums - for example if the values are not very readable and we want to label them, or if we expect the values to change.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

which makes me wonder why we used enum for ShardingStatuses 🤔

isCancellingSharding: state.userActionInProgress === 'cancelSharding',
}),
{
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 @@ -90,7 +89,7 @@ export default connect(
shardKey: state.shardKey,
shardZones: state.shardZones,
isSubmittingForSharding:
state.status === ShardingStatuses.SUBMITTING_FOR_SHARDING_INCOMPLETE,
state.userActionInProgress === 'submitForSharding',
};
},
{
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.userActionInProgress === 'unmanageNamespace',
};
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {
import React from 'react';
import ShardKeyMarkup from '../shard-key-markup';
import {
ShardingStatuses,
unmanageNamespace,
type RootState,
type ShardKey,
Expand Down Expand Up @@ -102,8 +101,7 @@ export default connect(
shardKey: state.shardKey,
requestedShardKey:
state.managedNamespace && getRequestedShardKey(state.managedNamespace),
isUnmanagingNamespace:
state.status === ShardingStatuses.UNMANAGING_NAMESPACE_MISMATCH,
isUnmanagingNamespace: state.userActionInProgress === 'unmanageNamespace',
};
},
{
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,
Expand Down Expand Up @@ -68,10 +64,9 @@ export default connect(
}
return {
shardingError: state.shardingError,
isCancellingSharding:
state.status === ShardingStatuses.CANCELLING_SHARDING_ERROR,
isCancellingSharding: state.userActionInProgress === 'cancelSharding',
isSubmittingForSharding:
state.status === ShardingStatuses.SUBMITTING_FOR_SHARDING_ERROR,
state.userActionInProgress === 'submitForSharding',
};
},
{
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 {
containerStyles,
bannerStyles,
Expand Down Expand Up @@ -62,7 +58,7 @@ export function ShardingState({

export default connect(
(state: RootState) => ({
isCancellingSharding: state.status === ShardingStatuses.CANCELLING_SHARDING,
isCancellingSharding: state.userActionInProgress === 'cancelSharding',
}),
{
onCancelSharding: cancelSharding,
Expand Down
Loading
Loading