Skip to content

Commit 36e331f

Browse files
authored
feat(compass-collection): Move assign call for Mock Data Generator inside check for collection type - CLOUDP-347301 (#7501)
* Gate behind assign call * Hide time series * WIP
1 parent a18236d commit 36e331f

File tree

5 files changed

+102
-9
lines changed

5 files changed

+102
-9
lines changed

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

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ describe('CollectionHeaderActions [Component]', function () {
5454
<CollectionHeaderActions
5555
namespace="test.test"
5656
isReadonly={false}
57+
isTimeSeries={false}
5758
onOpenMockDataModal={sinon.stub()}
5859
hasSchemaAnalysisData={true}
5960
analyzedSchemaDepth={2}
@@ -221,14 +222,46 @@ describe('CollectionHeaderActions [Component]', function () {
221222
};
222223

223224
it('should call useAssignment with correct parameters', async function () {
225+
await renderCollectionHeaderActions(
226+
{
227+
namespace: 'test.collection',
228+
isReadonly: false,
229+
},
230+
{},
231+
atlasConnectionInfo
232+
);
233+
234+
expect(mockUseAssignment).to.have.been.calledWith(
235+
ExperimentTestName.mockDataGenerator,
236+
true // trackIsInSample - Experiment viewed analytics event
237+
);
238+
});
239+
240+
it('should call useAssignment with trackIsInSample set to false in non-Atlas environments', async function () {
224241
await renderCollectionHeaderActions({
225242
namespace: 'test.collection',
226243
isReadonly: false,
227244
});
228245

229246
expect(mockUseAssignment).to.have.been.calledWith(
230247
ExperimentTestName.mockDataGenerator,
231-
true // trackIsInSample - Experiment viewed analytics event
248+
false // Not eligible - no Atlas metadata
249+
);
250+
});
251+
252+
it('should call useAssignment with trackIsInSample set to false for readonly collections', async function () {
253+
await renderCollectionHeaderActions(
254+
{
255+
namespace: 'test.collection',
256+
isReadonly: true,
257+
},
258+
{},
259+
atlasConnectionInfo
260+
);
261+
262+
expect(mockUseAssignment).to.have.been.calledWith(
263+
ExperimentTestName.mockDataGenerator,
264+
false // Not eligible - readonly collection
232265
);
233266
});
234267

@@ -358,6 +391,20 @@ describe('CollectionHeaderActions [Component]', function () {
358391
expect(button).to.exist;
359392
expect(button).to.have.attribute('aria-disabled', 'true');
360393
});
394+
395+
it('should not show button for time series collections', async function () {
396+
await renderCollectionHeaderActions(
397+
{
398+
isTimeSeries: true,
399+
},
400+
{},
401+
atlasConnectionInfo
402+
);
403+
404+
expect(
405+
screen.queryByTestId('collection-header-generate-mock-data-button')
406+
).to.not.exist;
407+
});
361408
});
362409
});
363410
});

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

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ function buildChartsUrl(
6363
type CollectionHeaderActionsProps = {
6464
namespace: string;
6565
isReadonly: boolean;
66+
isTimeSeries: boolean;
6667
editViewName?: string;
6768
sourceName?: string;
6869
sourcePipeline?: unknown[];
@@ -78,6 +79,7 @@ const CollectionHeaderActions: React.FunctionComponent<
7879
> = ({
7980
namespace,
8081
isReadonly,
82+
isTimeSeries,
8183
editViewName,
8284
sourceName,
8385
sourcePipeline,
@@ -99,24 +101,28 @@ const CollectionHeaderActions: React.FunctionComponent<
99101
'enableGenAISampleDocumentPassing'
100102
);
101103

104+
const { database, collection } = toNS(namespace);
105+
106+
const isMockDataGeneratorEligible = Boolean(
107+
atlasMetadata && // Only show in Atlas
108+
!isReadonly && // Don't show for readonly collections (views)
109+
!isTimeSeries && // Don't show for time series collections
110+
!sourceName // sourceName indicates it's a view
111+
);
112+
102113
// Get experiment assignment for Mock Data Generator
103114
const mockDataGeneratorAssignment = useAssignment(
104115
ExperimentTestName.mockDataGenerator,
105-
true // trackIsInSample - this will fire the "Experiment Viewed" event
116+
isMockDataGeneratorEligible // Only track eligible collections
106117
);
107118

108-
const { database, collection } = toNS(namespace);
109-
110119
// Check if user is in treatment group for Mock Data Generator experiment
111120
const isInMockDataTreatmentVariant =
112121
mockDataGeneratorAssignment?.assignment?.assignmentData?.variant ===
113122
ExperimentTestGroup.mockDataGeneratorVariant;
114123

115124
const shouldShowMockDataButton =
116-
isInMockDataTreatmentVariant &&
117-
atlasMetadata && // Only show in Atlas
118-
!isReadonly && // Don't show for readonly collections (views)
119-
!sourceName; // sourceName indicates it's a view
125+
isMockDataGeneratorEligible && isInMockDataTreatmentVariant;
120126

121127
const exceedsMaxNestingDepth =
122128
analyzedSchemaDepth > MAX_COLLECTION_NESTING_DEPTH;

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ const CollectionHeader: React.FunctionComponent<CollectionHeaderProps> = ({
185185
<CollectionHeaderActions
186186
editViewName={editViewName}
187187
isReadonly={isReadonly}
188+
isTimeSeries={isTimeSeries}
188189
namespace={namespace}
189190
sourceName={sourceName}
190191
sourcePipeline={sourcePipeline}

packages/compass-collection/src/stores/collection-tab.spec.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,42 @@ describe('Collection Tab Content store', function () {
263263
.deep.eq(defaultMetadata);
264264
});
265265
});
266+
267+
it('should not assign experiment for readonly collections', async function () {
268+
const assignExperiment = sandbox.spy(() => Promise.resolve(null));
269+
270+
await configureStore(
271+
undefined,
272+
{},
273+
{ assignExperiment },
274+
mockAtlasConnectionInfo,
275+
undefined,
276+
undefined,
277+
{ ...defaultMetadata, isReadonly: true }
278+
);
279+
280+
// Wait a bit to ensure assignment would have happened if it was going to
281+
await new Promise((resolve) => setTimeout(resolve, 50));
282+
expect(assignExperiment).to.not.have.been.called;
283+
});
284+
285+
it('should not assign experiment for time series collections', async function () {
286+
const assignExperiment = sandbox.spy(() => Promise.resolve(null));
287+
288+
await configureStore(
289+
undefined,
290+
{},
291+
{ assignExperiment },
292+
mockAtlasConnectionInfo,
293+
undefined,
294+
undefined,
295+
{ ...defaultMetadata, isTimeSeries: true }
296+
);
297+
298+
// Wait a bit to ensure assignment would have happened if it was going to
299+
await new Promise((resolve) => setTimeout(resolve, 50));
300+
expect(assignExperiment).to.not.have.been.called;
301+
});
266302
});
267303

268304
describe('schema analysis on collection load', function () {

packages/compass-collection/src/stores/collection-tab.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,11 @@ export function activatePlugin(
143143
store.dispatch(collectionMetadataFetched(metadata));
144144

145145
// Assign experiment for Mock Data Generator
146-
// Only assign when we're connected to Atlas and the org-level setting for AI features is enabled
146+
// Only assign when we're connected to Atlas, the org-level setting for AI features is enabled,
147+
// and the collection supports the Mock Data Generator feature (not readonly/timeseries)
147148
if (
149+
!metadata.isReadonly &&
150+
!metadata.isTimeSeries &&
148151
connectionInfoRef.current?.atlasMetadata?.clusterName && // Ensures we only assign in Atlas
149152
isAIFeatureEnabled(preferences.getPreferences()) // Ensures org-level AI features setting is enabled
150153
) {

0 commit comments

Comments
 (0)