Skip to content

Commit

Permalink
refactor(compass-global-writes): remove in-progress states (#6475)
Browse files Browse the repository at this point in the history
  • Loading branch information
paula-stacho authored Nov 15, 2024
1 parent c79c948 commit 203ce42
Show file tree
Hide file tree
Showing 11 changed files with 261 additions and 350 deletions.
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',
isCancellingSharding: state.userActionInProgress === 'cancelSharding',
}),
{
onCreateShardKey: createShardKey,
}
Expand Down
7 changes: 0 additions & 7 deletions packages/compass-global-writes/src/components/index.spec.tsx
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

0 comments on commit 203ce42

Please sign in to comment.