Skip to content

Commit

Permalink
feat(compass-global-writes): sharding in progress state COMPASS-8277 (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
paula-stacho authored Oct 15, 2024
1 parent 11209f0 commit eab7899
Show file tree
Hide file tree
Showing 8 changed files with 604 additions and 86 deletions.
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;
});
});
38 changes: 36 additions & 2 deletions packages/compass-global-writes/src/components/states/sharding.tsx
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);
16 changes: 16 additions & 0 deletions packages/compass-global-writes/src/plugin-title.spec.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import React from 'react';
import { expect } from 'chai';
import { PluginTitle } from './plugin-title';
import { render, screen } from '@mongodb-js/testing-library-compass';

describe('PluginTitle', function () {
it('Renders a warning', function () {
render(<PluginTitle showWarning={true} />);
expect(screen.getByLabelText('warning')).to.be.visible;
});

it('Does not render a warning', function () {
render(<PluginTitle showWarning={false} />);
expect(screen.queryByLabelText('warning')).not.to.exist;
});
});
3 changes: 2 additions & 1 deletion packages/compass-global-writes/src/plugin-title.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const iconStylesDark = css({
color: palette.yellow.base,
});

const PluginTitle = ({ showWarning }: { showWarning: boolean }) => {
export const PluginTitle = ({ showWarning }: { showWarning: boolean }) => {
const darkMode = useDarkMode();
return (
<div data-testid="global-writes-tab-title" className={containerStyles}>
Expand All @@ -50,6 +50,7 @@ const PluginTitle = ({ showWarning }: { showWarning: boolean }) => {
>
<Icon
glyph="ImportantWithCircle"
aria-label="warning"
className={cx(
warningIconStyles,
iconStylesLight,
Expand Down
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

0 comments on commit eab7899

Please sign in to comment.