Skip to content

Commit e37fc16

Browse files
committed
Address comment to add tooltip
1 parent 73cb0b1 commit e37fc16

File tree

3 files changed

+49
-12
lines changed

3 files changed

+49
-12
lines changed

packages/compass-collection/src/components/collection-header-actions/collection-header-actions.spec.tsx

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,5 +265,34 @@ describe('CollectionHeaderActions [Component]', function () {
265265

266266
expect(onOpenMockDataModal).to.have.been.calledOnce;
267267
});
268+
269+
it('should disable button for deeply nested collections', async function () {
270+
mockUseAssignment.returns({
271+
assignment: {
272+
assignmentData: {
273+
variant: 'mockDataGeneratorVariant', // Treatment variant
274+
},
275+
},
276+
});
277+
278+
await renderCollectionHeaderActions(
279+
{
280+
namespace: 'test.collection',
281+
isReadonly: false,
282+
hasSchemaAnalysisData: true,
283+
analyzedSchemaDepth: 5, // Exceeds MAX_COLLECTION_NESTING_DEPTH (3)
284+
schemaAnalysisStatus: 'complete',
285+
onOpenMockDataModal: sinon.stub(),
286+
},
287+
{},
288+
atlasConnectionInfo
289+
);
290+
291+
const button = screen.getByTestId(
292+
'collection-header-generate-mock-data-button'
293+
);
294+
expect(button).to.exist;
295+
expect(button).to.have.attribute('aria-disabled', 'true');
296+
});
268297
});
269298
});

packages/compass-collection/src/components/collection-header-actions/collection-header-actions.tsx

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,14 @@ const CollectionHeaderActions: React.FunctionComponent<
9999
isInMockDataTreatmentVariant &&
100100
atlasMetadata && // Only show in Atlas
101101
!isReadonly && // Don't show for readonly collections (views)
102-
!sourceName && // sourceName indicates it's a view
103-
analyzedSchemaDepth <= MAX_COLLECTION_NESTING_DEPTH; // Filter out overly nested collections
102+
!sourceName; // sourceName indicates it's a view
103+
104+
const exceedsMaxNestingDepth =
105+
analyzedSchemaDepth > MAX_COLLECTION_NESTING_DEPTH;
106+
107+
const isCollectionEmpty =
108+
!hasSchemaAnalysisData &&
109+
schemaAnalysisStatus !== SCHEMA_ANALYSIS_STATE_ANALYZING;
104110

105111
return (
106112
<div
@@ -124,16 +130,13 @@ const CollectionHeaderActions: React.FunctionComponent<
124130
)}
125131
{shouldShowMockDataButton && (
126132
<Tooltip
127-
enabled={
128-
!hasSchemaAnalysisData &&
129-
schemaAnalysisStatus !== SCHEMA_ANALYSIS_STATE_ANALYZING
130-
}
133+
enabled={exceedsMaxNestingDepth || isCollectionEmpty}
131134
trigger={
132135
<div>
133136
<Button
134137
data-testid="collection-header-generate-mock-data-button"
135138
size={ButtonSize.Small}
136-
disabled={!hasSchemaAnalysisData}
139+
disabled={!hasSchemaAnalysisData || exceedsMaxNestingDepth}
137140
onClick={onOpenMockDataModal}
138141
leftGlyph={<Icon glyph="Sparkle" />}
139142
>
@@ -142,7 +145,10 @@ const CollectionHeaderActions: React.FunctionComponent<
142145
</div>
143146
}
144147
>
145-
Please add data to your collection to generate similar mock documents
148+
{exceedsMaxNestingDepth &&
149+
'At this time we are unable to generate mock data for collections that have deeply nested documents'}
150+
{isCollectionEmpty &&
151+
'Please add data to your collection to generate similar mock documents'}
146152
</Tooltip>
147153
)}
148154
{atlasMetadata && (

packages/compass-collection/src/components/collection-header/collection-header.spec.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,7 @@ describe('CollectionHeader [Component]', function () {
473473
expect(button).to.have.attribute('aria-disabled', 'true');
474474
});
475475

476-
it('should not show Mock Data Generator button for collections with excessive nesting depth', async function () {
476+
it('should disable Mock Data Generator button for collections with excessive nesting depth', async function () {
477477
await renderCollectionHeaderWithExperimentation(
478478
{
479479
isAtlas: true,
@@ -495,9 +495,11 @@ describe('CollectionHeader [Component]', function () {
495495
atlasConnectionInfo
496496
);
497497

498-
expect(
499-
screen.queryByTestId('collection-header-generate-mock-data-button')
500-
).to.not.exist;
498+
const button = screen.getByTestId(
499+
'collection-header-generate-mock-data-button'
500+
);
501+
expect(button).to.exist;
502+
expect(button).to.have.attribute('aria-disabled', 'true');
501503
});
502504

503505
it('should not show Mock Data Generator button for readonly collections (views)', async function () {

0 commit comments

Comments
 (0)