Skip to content
Closed
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
10 changes: 8 additions & 2 deletions packages/compass-global-writes/src/components/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
spacing,
WorkspaceContainer,
SpinLoaderWithLabel,
ConfirmationModalArea,
} from '@mongodb-js/compass-components';
import type { RootState, ShardingStatus } from '../store/reducer';
import { ShardingStatuses } from '../store/reducer';
Expand Down Expand Up @@ -55,7 +56,10 @@ function ShardingStateView({
return <UnshardedState />;
}

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

Expand All @@ -73,7 +77,9 @@ export function GlobalWrites({ shardingStatus }: GlobalWritesProps) {
return (
<div className={containerStyles}>
<WorkspaceContainer className={workspaceContentStyles}>
<ShardingStateView shardingStatus={shardingStatus} />
<ConfirmationModalArea>
<ShardingStateView shardingStatus={shardingStatus} />
</ConfirmationModalArea>
</WorkspaceContainer>
</div>
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,52 @@
import React from 'react';
import { expect } from 'chai';
import { screen } from '@mongodb-js/testing-library-compass';
import { screen, userEvent } from '@mongodb-js/testing-library-compass';
import { ShardingState } from './sharding';
import { renderWithStore } from '../../../tests/create-store';
import Sinon from 'sinon';

function renderWithProps(
props?: Partial<React.ComponentProps<typeof ShardingState>>
) {
return renderWithStore(<ShardingState {...props} />);
return renderWithStore(
<ShardingState
onCancelSharding={() => {}}
isCancellingSharding={false}
{...props}
/>
);
}

describe('Sharding', function () {
it('renders the info banner', async function () {
await renderWithProps();
expect(screen.getByRole('alert')).to.exist;
});

it('sharding request can be cancelled', async function () {
const onCancelSharding = Sinon.spy();
await renderWithProps({
onCancelSharding,
});
const btn = screen.getByRole('button', { name: 'Cancel Request' });
expect(btn).to.be.visible;

userEvent.click(btn);

expect(onCancelSharding).to.have.been.calledOnce;
});

it('when cancelling is in progress, it cannot be triggered again', async function () {
const onCancelSharding = Sinon.spy();
await renderWithProps({
isCancellingSharding: true,
onCancelSharding,
});
const btn = screen.getByTestId('cancel-sharding-btn');
expect(btn.getAttribute('aria-disabled')).to.equal('true');

userEvent.click(btn);

expect(onCancelSharding).not.to.have.been.calledOnce;
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,17 @@ import {
Banner,
BannerVariant,
Body,
Button,
css,
Link,
spacing,
} from '@mongodb-js/compass-components';
import { connect } from 'react-redux';
import {
cancelSharding,
type RootState,
ShardingStatuses,
} from '../../store/reducer';

const nbsp = '\u00a0';

Expand All @@ -17,12 +23,33 @@ const containerStyles = css({
gap: spacing[400],
});

export function ShardingState() {
const btnStyles = css({
float: 'right',
height: spacing[600],
});

interface ShardingStateProps {
isCancellingSharding: boolean;
onCancelSharding: () => void;
}

export function ShardingState({
isCancellingSharding,
onCancelSharding,
}: ShardingStateProps) {
return (
<div className={containerStyles}>
<Banner variant={BannerVariant.Info}>
<strong>Sharding your collection …</strong>
{nbsp}this should not take too long.
<Button
className={btnStyles}
data-testid="cancel-sharding-btn"
onClick={onCancelSharding}
isLoading={isCancellingSharding}
>
Cancel Request
</Button>
</Banner>
<Body>
Once your collection is sharded, this tab will show instructions on
Expand All @@ -39,4 +66,11 @@ export function ShardingState() {
);
}

export default connect()(ShardingState);
export default connect(
(state: RootState) => ({
isCancellingSharding: state.status === ShardingStatuses.CANCELLING_SHARDING,
}),
{
onCancelSharding: cancelSharding,
}
)(ShardingState);
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export type ClusterDetailsApiResponse = {
replicationSpecList: ReplicationItem[];
};

type AutomationAgentProcess = {
export type AutomationAgentProcess = {
statusType: string;
workingOnShort: string;
errorText: string;
Expand Down
Loading
Loading