Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -54,6 +54,7 @@ describe('CollectionHeaderActions [Component]', function () {
<CollectionHeaderActions
namespace="test.test"
isReadonly={false}
isTimeSeries={false}
onOpenMockDataModal={sinon.stub()}
hasSchemaAnalysisData={true}
analyzedSchemaDepth={2}
Expand Down Expand Up @@ -221,14 +222,46 @@ describe('CollectionHeaderActions [Component]', function () {
};

it('should call useAssignment with correct parameters', async function () {
await renderCollectionHeaderActions(
{
namespace: 'test.collection',
isReadonly: false,
},
{},
atlasConnectionInfo
);

expect(mockUseAssignment).to.have.been.calledWith(
ExperimentTestName.mockDataGenerator,
true // trackIsInSample - Experiment viewed analytics event
);
});

it('should call useAssignment with trackIsInSample set to false in non-Atlas environments', async function () {
await renderCollectionHeaderActions({
namespace: 'test.collection',
isReadonly: false,
});

expect(mockUseAssignment).to.have.been.calledWith(
ExperimentTestName.mockDataGenerator,
true // trackIsInSample - Experiment viewed analytics event
false // Not eligible - no Atlas metadata
);
});

it('should call useAssignment with trackIsInSample set to false for readonly collections', async function () {
await renderCollectionHeaderActions(
{
namespace: 'test.collection',
isReadonly: true,
},
{},
atlasConnectionInfo
);

expect(mockUseAssignment).to.have.been.calledWith(
ExperimentTestName.mockDataGenerator,
false // Not eligible - readonly collection
);
});

Expand Down Expand Up @@ -358,6 +391,20 @@ describe('CollectionHeaderActions [Component]', function () {
expect(button).to.exist;
expect(button).to.have.attribute('aria-disabled', 'true');
});

it('should not show button for time series collections', async function () {
await renderCollectionHeaderActions(
{
isTimeSeries: true,
},
{},
atlasConnectionInfo
);

expect(
screen.queryByTestId('collection-header-generate-mock-data-button')
).to.not.exist;
});
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ function buildChartsUrl(
type CollectionHeaderActionsProps = {
namespace: string;
isReadonly: boolean;
isTimeSeries: boolean;
editViewName?: string;
sourceName?: string;
sourcePipeline?: unknown[];
Expand All @@ -78,6 +79,7 @@ const CollectionHeaderActions: React.FunctionComponent<
> = ({
namespace,
isReadonly,
isTimeSeries,
editViewName,
sourceName,
sourcePipeline,
Expand All @@ -99,24 +101,28 @@ const CollectionHeaderActions: React.FunctionComponent<
'enableGenAISampleDocumentPassing'
);

const { database, collection } = toNS(namespace);

const isMockDataGeneratorEligible = Boolean(
atlasMetadata && // Only show in Atlas
!isReadonly && // Don't show for readonly collections (views)
!isTimeSeries && // Don't show for time series collections
!sourceName // sourceName indicates it's a view
);

// Get experiment assignment for Mock Data Generator
const mockDataGeneratorAssignment = useAssignment(
ExperimentTestName.mockDataGenerator,
true // trackIsInSample - this will fire the "Experiment Viewed" event
isMockDataGeneratorEligible // Only track eligible collections
);

const { database, collection } = toNS(namespace);

// Check if user is in treatment group for Mock Data Generator experiment
const isInMockDataTreatmentVariant =
mockDataGeneratorAssignment?.assignment?.assignmentData?.variant ===
ExperimentTestGroup.mockDataGeneratorVariant;

const shouldShowMockDataButton =
isInMockDataTreatmentVariant &&
atlasMetadata && // Only show in Atlas
!isReadonly && // Don't show for readonly collections (views)
!sourceName; // sourceName indicates it's a view
isMockDataGeneratorEligible && isInMockDataTreatmentVariant;

const exceedsMaxNestingDepth =
analyzedSchemaDepth > MAX_COLLECTION_NESTING_DEPTH;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ const CollectionHeader: React.FunctionComponent<CollectionHeaderProps> = ({
<CollectionHeaderActions
editViewName={editViewName}
isReadonly={isReadonly}
isTimeSeries={isTimeSeries}
namespace={namespace}
sourceName={sourceName}
sourcePipeline={sourcePipeline}
Expand Down
36 changes: 36 additions & 0 deletions packages/compass-collection/src/stores/collection-tab.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,42 @@ describe('Collection Tab Content store', function () {
.deep.eq(defaultMetadata);
});
});

it('should not assign experiment for readonly collections', async function () {
const assignExperiment = sandbox.spy(() => Promise.resolve(null));

await configureStore(
undefined,
{},
{ assignExperiment },
mockAtlasConnectionInfo,
undefined,
undefined,
{ ...defaultMetadata, isReadonly: true }
);

// Wait a bit to ensure assignment would have happened if it was going to
await new Promise((resolve) => setTimeout(resolve, 50));
expect(assignExperiment).to.not.have.been.called;
});

it('should not assign experiment for time series collections', async function () {
const assignExperiment = sandbox.spy(() => Promise.resolve(null));

await configureStore(
undefined,
{},
{ assignExperiment },
mockAtlasConnectionInfo,
undefined,
undefined,
{ ...defaultMetadata, isTimeSeries: true }
);

// Wait a bit to ensure assignment would have happened if it was going to
await new Promise((resolve) => setTimeout(resolve, 50));
expect(assignExperiment).to.not.have.been.called;
});
});

describe('schema analysis on collection load', function () {
Expand Down
5 changes: 4 additions & 1 deletion packages/compass-collection/src/stores/collection-tab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,11 @@ export function activatePlugin(
store.dispatch(collectionMetadataFetched(metadata));

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