Skip to content
Merged
Show file tree
Hide file tree
Changes from 11 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 @@ -57,6 +57,8 @@ describe('CollectionHeaderActions [Component]', function () {
namespace="test.test"
isReadonly={false}
onOpenMockDataModal={sinon.stub()}
hasSchemaAnalysisData={true}
analyzedSchemaDepth={2}
{...props}
/>
</PreferencesProvider>
Expand Down Expand Up @@ -221,119 +223,6 @@ describe('CollectionHeaderActions [Component]', function () {
},
};

it('should not show Mock Data Generator button when user is in control group', async function () {
mockUseAssignment.returns({
assignment: {
assignmentData: {
variant: 'mockDataGeneratorControl',
},
},
});

await renderCollectionHeaderActions(
{
namespace: 'test.collection',
isReadonly: false,
},
{},
atlasConnectionInfo
);

expect(
screen.queryByTestId('collection-header-generate-mock-data-button')
).to.not.exist;
});

it('should not show Mock Data Generator button when not in Atlas', async function () {
mockUseAssignment.returns({
assignment: {
assignmentData: {
variant: 'treatment',
},
},
});

await renderCollectionHeaderActions({
namespace: 'test.collection',
isReadonly: false,
// Don't pass atlasConnectionInfo, to simulate not being in Atlas
});

expect(
screen.queryByTestId('collection-header-generate-mock-data-button')
).to.not.exist;
});

it('should not show Mock Data Generator button for readonly collections', async function () {
mockUseAssignment.returns({
assignment: {
assignmentData: {
variant: 'treatment',
},
},
});

await renderCollectionHeaderActions(
{
namespace: 'test.collection',
isReadonly: true,
},
{},
atlasConnectionInfo
);

expect(
screen.queryByTestId('collection-header-generate-mock-data-button')
).to.not.exist;
});

it('should not show Mock Data Generator button for views (sourceName present)', async function () {
mockUseAssignment.returns({
assignment: {
assignmentData: {
variant: 'treatment',
},
},
});

await renderCollectionHeaderActions(
{
namespace: 'test.collection',
isReadonly: false,
sourceName: 'source-collection',
},
{},
atlasConnectionInfo
);

expect(
screen.queryByTestId('collection-header-generate-mock-data-button')
).to.not.exist;
});

it('should show Mock Data Generator button when user is in treatment group and in Atlas', async function () {
mockUseAssignment.returns({
assignment: {
assignmentData: {
variant: 'mockDataGeneratorVariant',
},
},
});

await renderCollectionHeaderActions(
{
namespace: 'test.collection',
isReadonly: false,
},
{},
atlasConnectionInfo
);

expect(
screen.getByTestId('collection-header-generate-mock-data-button')
).to.exist;
});

it('should call useAssignment with correct parameters', async function () {
await renderCollectionHeaderActions({
namespace: 'test.collection',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ import {
ExperimentTestGroup,
} from '@mongodb-js/compass-telemetry/provider';

/**
* Maximum allowed nesting depth for collections to show Mock Data Generator
*/
const MAX_COLLECTION_NESTING_DEPTH = 3;

const collectionHeaderActionsStyles = css({
display: 'flex',
alignItems: 'center',
Expand Down Expand Up @@ -47,6 +52,8 @@ type CollectionHeaderActionsProps = {
sourceName?: string;
sourcePipeline?: unknown[];
onOpenMockDataModal: () => void;
hasSchemaAnalysisData: boolean;
analyzedSchemaDepth: number;
};

const CollectionHeaderActions: React.FunctionComponent<
Expand All @@ -58,6 +65,8 @@ const CollectionHeaderActions: React.FunctionComponent<
sourceName,
sourcePipeline,
onOpenMockDataModal,
hasSchemaAnalysisData,
analyzedSchemaDepth,
}: CollectionHeaderActionsProps) => {
const connectionInfo = useConnectionInfo();
const { id: connectionId, atlasMetadata } = connectionInfo;
Expand All @@ -84,10 +93,8 @@ const CollectionHeaderActions: React.FunctionComponent<
isInMockDataTreatmentVariant &&
atlasMetadata && // Only show in Atlas
!isReadonly && // Don't show for readonly collections (views)
!sourceName; // sourceName indicates it's a view
// TODO: CLOUDP-337090: also filter out overly nested collections

const hasData = true; // TODO: CLOUDP-337090
!sourceName && // sourceName indicates it's a view
analyzedSchemaDepth <= MAX_COLLECTION_NESTING_DEPTH; // Filter out overly nested collections
Copy link
Member

Choose a reason for hiding this comment

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

Filters deeply nested collections: The Mock Data Generator button now only appears for collections with a maximum nesting depth of 3 levels or fewer. Collections with 4 or more levels of nested documents or arrays will not show the button

Have we considered instead keeping the button and having it disabled with a tooltip? As a user I could see it being confusing why its showing up on one collection and not another. Additionally if the button is showing and then vanishes.

I'm also a bit curious on this requirement, what is the cause of this limitation? Maybe we can mention that in a comment.

Copy link
Collaborator Author

@jcobis jcobis Sep 8, 2025

Choose a reason for hiding this comment

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

Good question, this was something that I brought up to Designs as well, and where they decided to hide the button. (See Kevin's question about the same thing)

Copy link
Member

Choose a reason for hiding this comment

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

Left a comment in that thread, I think we should bring it back up with design with the considerations. Right now this would be introducing some confusing UX for users and some UI that asynchronously disappears without indication.

Copy link
Member

Choose a reason for hiding this comment

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

Got the okay from design in the thread, not too sure on the text though, left a suggestion but feel free to interpret it in a way that makes sense to you!

At this time we are unable to generate mock data for collections with documents that have a deeply nested schema.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Responded in the Figma thread with a few slight copy suggestions!


return (
<div
Expand All @@ -111,13 +118,13 @@ const CollectionHeaderActions: React.FunctionComponent<
)}
{shouldShowMockDataButton && (
<Tooltip
enabled={!hasData}
enabled={!hasSchemaAnalysisData}
trigger={
<div>
<Button
data-testid="collection-header-generate-mock-data-button"
size={ButtonSize.Small}
disabled={!hasData}
disabled={!hasSchemaAnalysisData}
onClick={onOpenMockDataModal}
leftGlyph={<Icon glyph="Sparkle" />}
>
Expand Down
Loading
Loading