Skip to content
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
3cf163e
implement raw schema confirmation screen
kpamaran Sep 8, 2025
b4d1784
Merge branch 'main' into mock-data-generator-raw-schema-confirmation-…
kpamaran Sep 8, 2025
7fbb335
shorthand schema render logic in confirmation step
kpamaran Sep 9, 2025
2dfa720
nit
kpamaran Sep 9, 2025
0518349
move tests
kpamaran Sep 9, 2025
be20bc1
revert
kpamaran Sep 9, 2025
7873b6e
nit
kpamaran Sep 9, 2025
780c398
Merge branch 'main' into mock-data-generator-raw-schema-confirmation-…
kpamaran Sep 9, 2025
3ce421a
nit
kpamaran Sep 9, 2025
adf4eac
nit
kpamaran Sep 9, 2025
05aa795
address smaller feedback
kpamaran Sep 10, 2025
5c8e35c
nit
kpamaran Sep 10, 2025
cf25bab
rename
kpamaran Sep 10, 2025
c13f44b
define and handle unsupported state
kpamaran Sep 10, 2025
833fd37
nit
kpamaran Sep 10, 2025
78e3f5a
downgrade log severity
kpamaran Sep 10, 2025
ef9dfc8
add compass-crud as a dep to compass-collection
kpamaran Sep 10, 2025
f0d817a
Merge branch 'main' into mock-data-generator-raw-schema-confirmation-…
kpamaran Sep 10, 2025
65b9a9e
remove validation
kpamaran Sep 10, 2025
e411dd9
avoid cyclical dep
kpamaran Sep 11, 2025
df6c2a6
increase readability given multipel tooltip messages
kpamaran Sep 11, 2025
2b2cc7d
Merge branch 'main' into mock-data-generator-raw-schema-confirmation-…
kpamaran Sep 11, 2025
3634213
add className prop to HadronDocument
kpamaran Sep 12, 2025
d178f00
fix grammar
kpamaran Sep 12, 2025
90ef737
Remove error handling branch
kpamaran Sep 15, 2025
a74d752
Merge branch 'main' into mock-data-generator-raw-schema-confirmation-…
kpamaran Sep 15, 2025
e0181f0
fix sentence
kpamaran Sep 15, 2025
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 @@ -145,6 +145,8 @@ const CollectionHeaderActions: React.FunctionComponent<
</div>
}
>
{/* todo within (CLOUDP-333853): update disabled open-modal button
tooltip to communicate if schema analysis is incomplete */}
{exceedsMaxNestingDepth &&
'At this time we are unable to generate mock data for collections that have deeply nested documents'}
{isCollectionEmpty &&
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import React from 'react';

// TODO: More to come from CLOUDP-333853, CLOUDP-333854
const FakerSchemaEditor = () => {
const FakerSchemaEditorScreen = () => {
return (
<div data-testid="faker-schema-editor">
Schema Editor Content Placeholder
</div>
);
};

export default FakerSchemaEditor;
export default FakerSchemaEditorScreen;
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@ describe('MockDataGeneratorModal', () => {
async function renderModal({
isOpen = true,
currentStep = MockDataGeneratorStep.SCHEMA_CONFIRMATION,
enableGenAISampleDocumentPassing = false,
mockServices = createMockServices(),
connectionInfo,
}: {
isOpen?: boolean;
enableGenAISampleDocumentPassing?: boolean;
currentStep?: MockDataGeneratorStep;
mockServices?: any;
connectionInfo?: ConnectionInfo;
Expand Down Expand Up @@ -63,7 +65,12 @@ describe('MockDataGeneratorModal', () => {
<Provider store={store}>
<MockDataGeneratorModal />
</Provider>,
connectionInfo
connectionInfo,
{
preferences: {
enableGenAISampleDocumentPassing,
},
}
);
}

Expand Down Expand Up @@ -204,6 +211,37 @@ describe('MockDataGeneratorModal', () => {
).to.equal('true');
});

it('displays the namespace', async () => {
await renderModal();
expect(screen.queryByText('test.collection')).to.exist;
});

it('uses the appropriate copy when Generative AI sample document passing is enabled', async () => {
await renderModal({ enableGenAISampleDocumentPassing: true });
expect(screen.queryByText('Sample Documents Collected')).to.exist;
expect(
screen.queryByText(
'A sample of document values from your collection will be sent to an LLM for processing.'
)
).to.exist;
// fragment from { "name": "John" }
expect(screen.queryByText('"John"')).to.exist;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we use getBy* instead of queryBy* where we check that an element does exist? queryBy* will not throw an error if it doesn't find the element, potentially failing silently.

expect(screen.queryByText('"String"')).to.not.exist;
});

it('uses the appropriate copy when Generative AI sample document passing is disabled', async () => {
await renderModal();
expect(screen.queryByText('Document Schema Identified')).to.exist;
expect(
screen.queryByText(
'We have identified the following schema from your documents. This schema will be sent to an LLM for processing.'
)
).to.exist;
// fragment from { "name": "String" }
expect(screen.queryByText('"String"')).to.exist;
expect(screen.queryByText('"John"')).to.not.exist;
});

it('renders the faker schema editor when the confirm button is clicked', async () => {
await renderModal();

Expand All @@ -230,10 +268,9 @@ describe('MockDataGeneratorModal', () => {
expect(screen.queryByTestId('faker-schema-editor')).to.not.exist;
});

// todo: assert a user-friendly error is displayed (CLOUDP-333852)
expect(screen.getByText('LLM Request failed. Please confirm again.')).to
.exist;
});

// todo: assert that closing then re-opening the modal after an LLM err removes the err message
});

describe('on the generate data step', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ import {
generateFakerMappings,
mockDataGeneratorPreviousButtonClicked,
} from '../../modules/collection-tab';
import { default as SchemaConfirmationScreen } from './raw-schema-confirmation';
import FakerSchemaEditor from './faker-schema-editor';
import RawSchemaConfirmationScreen from './raw-schema-confirmation-screen';
import FakerSchemaEditorScreen from './faker-schema-editor-screen';
import ScriptScreen from './script-screen';

const footerStyles = css`
Expand Down Expand Up @@ -56,9 +56,9 @@ const MockDataGeneratorModal = ({
const modalBodyContent = useMemo(() => {
switch (currentStep) {
case MockDataGeneratorStep.SCHEMA_CONFIRMATION:
return <SchemaConfirmationScreen />;
return <RawSchemaConfirmationScreen />;
case MockDataGeneratorStep.SCHEMA_EDITOR:
return <FakerSchemaEditor />;
return <FakerSchemaEditorScreen />;
case MockDataGeneratorStep.DOCUMENT_COUNT:
return <></>; // TODO: CLOUDP-333856
case MockDataGeneratorStep.PREVIEW_DATA:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
import React from 'react';
import { connect } from 'react-redux';

import {
css,
palette,
spacing,
Banner,
BannerVariant,
Code,
Body,
} from '@mongodb-js/compass-components';

import { usePreference } from 'compass-preferences-model/provider';
import toSimplifiedFieldInfo from './to-simplified-field-info';
import type { CollectionState } from '../../modules/collection-tab';
import type { SchemaAnalysisState } from '../../schema-analysis-types';
import type { MockDataGeneratorState } from './types';

interface RawSchemaConfirmationScreenProps {
schemaAnalysis: SchemaAnalysisState;
namespace: string;
fakerSchemaGenerationStatus: MockDataGeneratorState['status'];
}

const namespaceStyles = css({
marginTop: spacing[200],
marginBottom: spacing[400],
});

const descriptionStyles = css({
marginBottom: spacing[200],
});

const codeStyles = css({
maxHeight: '30vh',
});

const errorBannerStyles = css({
marginTop: spacing[400],
});

const errorBannerTextStyles = css({
color: palette.red.dark2,
});

const RawSchemaConfirmationScreen = ({
schemaAnalysis,
namespace,
fakerSchemaGenerationStatus,
}: RawSchemaConfirmationScreenProps) => {
const enableSampleDocumentPassing = usePreference(
'enableGenAISampleDocumentPassing'
);

const subtitleText = enableSampleDocumentPassing
? 'Sample Documents Collected'
: 'Document Schema Identified';

const descriptionText = enableSampleDocumentPassing
? 'A sample of document values from your collection will be sent to an LLM for processing.'
Copy link
Collaborator

Choose a reason for hiding this comment

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

I realize this is from Figma, but just going to say, the wording here seems odd, "document value" is somewhat clear but it's definitely not standard terminology. Can this be

Suggested change
? 'A sample of document values from your collection will be sent to an LLM for processing.'
? 'A sample of documens from your collection will be sent to an LLM for processing.'

?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Certainly

: 'We have identified the following schema from your documents. This schema will be sent to an LLM for processing.';

return (
<div data-testid="raw-schema-confirmation">
{schemaAnalysis.status === 'complete' ? (
<>
<Body className={namespaceStyles}>{namespace}</Body>
Copy link
Collaborator

Choose a reason for hiding this comment

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

Looks like we want to show the namespace on all screens according to Figma. This should probably go in mock-data-generator-modal.tsx so it's shared between all the screens.

<Body as="h2" baseFontSize={16} weight="medium">
{subtitleText}
</Body>
<Body className={descriptionStyles}>{descriptionText}</Body>
<Code language="javascript" copyable={false} className={codeStyles}>
{enableSampleDocumentPassing
? JSON.stringify(schemaAnalysis.sampleDocument, null, 4)
Copy link
Collaborator

Choose a reason for hiding this comment

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

What happens with types that are not representible in JSON?

The Figma designs seem to be aiming for something like our DocumentListView component rather than JSON

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Changed to the Document component. I don't think there should be any more representation issues on the schema-only or sample-doc variants

: JSON.stringify(
toSimplifiedFieldInfo(schemaAnalysis.processedSchema),
null,
4
)}
</Code>
{fakerSchemaGenerationStatus === 'error' && (
<Banner
variant={BannerVariant.Danger}
className={errorBannerStyles}
>
<Body className={errorBannerTextStyles}>
LLM Request failed. Please confirm again.
</Body>
</Banner>
)}
</>
) : (
// Not reachable since schema analysis must be finished before the modal can be opened
<Body>We are analyzing your collection.</Body>
)}
</div>
);
};

const mapStateToProps = (state: CollectionState) => {
const schemaAnalysis = state.schemaAnalysis;
const fakerSchemaGenerationStatus = state.fakerSchemaGeneration.status;

return {
schemaAnalysis,
namespace: state.namespace,
fakerSchemaGenerationStatus,
};
};

const ConnectedRawSchemaConfirmationScreen = connect(
mapStateToProps,
{}
)(RawSchemaConfirmationScreen);

export default ConnectedRawSchemaConfirmationScreen;

This file was deleted.

Loading
Loading