Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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,6 +21,7 @@ import { usePreference } from 'compass-preferences-model/provider';
import IndexFlowSection from './index-flow-section';
import QueryFlowSection from './query-flow-section';
import toNS from 'mongodb-ns';
import CreateIndexOptionsAccordion from './create-index-options-accordion';

const createIndexModalFieldsStyles = css({
margin: `${spacing[600]}px 0 ${spacing[800]}px 0`,
Expand Down Expand Up @@ -165,28 +166,52 @@ function CreateIndexForm({
collectionName={collectionName}
/>
)}

{/* TODO in CLOUDP-314036: update the accordion design */}
<Accordion data-testid="create-index-modal-toggle-options" text="Options">
<div
data-testid="create-index-modal-options"
className={createIndexModalOptionStyles}
{showIndexesGuidanceVariant ? (
<CreateIndexOptionsAccordion>
<div
data-testid="create-index-modal-options"
className={createIndexModalOptionStyles}
>
<CheckboxInput name="unique"></CheckboxInput>
<CollapsibleInput name="name"></CollapsibleInput>
<CollapsibleInput name="expireAfterSeconds"></CollapsibleInput>
<CollapsibleInput name="partialFilterExpression"></CollapsibleInput>
<CollapsibleInput name="wildcardProjection"></CollapsibleInput>
<CollapsibleInput name="collation"></CollapsibleInput>
{hasColumnstoreIndexesSupport(serverVersion) && (
<CollapsibleInput name="columnstoreProjection"></CollapsibleInput>
)}
<CheckboxInput name="sparse"></CheckboxInput>
{showRollingIndexOption && (
<CheckboxInput name="buildInRollingProcess"></CheckboxInput>
)}
</div>
</CreateIndexOptionsAccordion>
) : (
<Accordion
Copy link
Member

@Anemy Anemy May 7, 2025

Choose a reason for hiding this comment

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

Why can't we use the existing accordion here? It would be nice to keep things standard in Compass where we can. If it's design changes here, maybe we should update the existing accordion?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

removed all these changes and we ended up only having to change the copy

data-testid="create-index-modal-toggle-options"
text="Options"
>
<CheckboxInput name="unique"></CheckboxInput>
<CollapsibleInput name="name"></CollapsibleInput>
<CollapsibleInput name="expireAfterSeconds"></CollapsibleInput>
<CollapsibleInput name="partialFilterExpression"></CollapsibleInput>
<CollapsibleInput name="wildcardProjection"></CollapsibleInput>
<CollapsibleInput name="collation"></CollapsibleInput>
{hasColumnstoreIndexesSupport(serverVersion) && (
<CollapsibleInput name="columnstoreProjection"></CollapsibleInput>
)}
<CheckboxInput name="sparse"></CheckboxInput>
{showRollingIndexOption && (
<CheckboxInput name="buildInRollingProcess"></CheckboxInput>
)}
</div>
</Accordion>
<div
data-testid="create-index-modal-options"
className={createIndexModalOptionStyles}
>
<CheckboxInput name="unique"></CheckboxInput>
<CollapsibleInput name="name"></CollapsibleInput>
<CollapsibleInput name="expireAfterSeconds"></CollapsibleInput>
<CollapsibleInput name="partialFilterExpression"></CollapsibleInput>
<CollapsibleInput name="wildcardProjection"></CollapsibleInput>
<CollapsibleInput name="collation"></CollapsibleInput>
{hasColumnstoreIndexesSupport(serverVersion) && (
<CollapsibleInput name="columnstoreProjection"></CollapsibleInput>
)}
<CheckboxInput name="sparse"></CheckboxInput>
{showRollingIndexOption && (
<CheckboxInput name="buildInRollingProcess"></CheckboxInput>
)}
</div>
</Accordion>
)}
</>
);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import React from 'react';
import { render, screen, userEvent } from '@mongodb-js/testing-library-compass';
import { expect } from 'chai';
import CreateIndexOptionsAccordion from './create-index-options-accordion';

describe('CreateIndexOptionsAccordion', () => {
it('renders the button with "Options" text', () => {
render(
<CreateIndexOptionsAccordion>Test Content</CreateIndexOptionsAccordion>
);
expect(screen.getByText('Options')).to.exist;
});

it('toggles the accordion content when the button is clicked', () => {
render(
<CreateIndexOptionsAccordion>Test Content</CreateIndexOptionsAccordion>
);

const button = screen.getByRole('button', { name: /options/i });
expect(screen.queryByText('Test Content')).to.not.exist;

userEvent.click(button);
expect(screen.getByText('Test Content')).to.exist;

userEvent.click(button);
expect(screen.queryByText('Test Content')).to.not.exist;
});

it('renders the correct icon based on the open state', () => {
render(
<CreateIndexOptionsAccordion>Test Content</CreateIndexOptionsAccordion>
);

const button = screen.getByRole('button', { name: /options/i });
expect(
screen.getByTestId('create-index-options-accordion-icon')
).to.have.attribute('aria-label', 'Chevron Right Icon');

userEvent.click(button);
expect(
screen.getByTestId('create-index-options-accordion-icon')
).to.have.attribute('aria-label', 'Chevron Down Icon');
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import {
Body,
css,
Icon,
palette,
useDarkMode,
} from '@mongodb-js/compass-components';
import React, { useState } from 'react';

const buttonStyles = css({
fontWeight: 'bold',
display: 'flex',
alignItems: 'center',
paddingLeft: 0,
paddingRight: 0,
border: 'none',
background: 'none',
boxShadow: 'none',
'&:hover': {
cursor: 'pointer',
},
});

const iconStyles = css({
marginLeft: '4px',
});

const CreateIndexOptionsAccordion = ({
children,
}: {
children: React.ReactNode;
}) => {
const [open, setOpen] = useState(false);
const darkMode = useDarkMode();

const onOpenChange = () => {
setOpen(!open);
};

return (
<>
<button
className={buttonStyles}
type="button"
aria-expanded={open ? 'true' : 'false'}
onClick={onOpenChange}
>
<Body baseFontSize={16} weight="medium">
Options
</Body>
<Icon
color={darkMode ? palette.gray.base : palette.gray.dark1}
className={iconStyles}
glyph={open ? 'ChevronDown' : 'ChevronRight'}
data-testid="create-index-options-accordion-icon"
/>
</button>

{open && <>{children}</>}
</>
);
};

export default CreateIndexOptionsAccordion;
Loading