Skip to content

Commit 05aa795

Browse files
committed
address smaller feedback
1 parent adf4eac commit 05aa795

File tree

6 files changed

+55
-40
lines changed

6 files changed

+55
-40
lines changed

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,12 +95,14 @@ const CollectionHeaderActions: React.FunctionComponent<
9595
mockDataGeneratorAssignment?.assignment?.assignmentData?.variant ===
9696
ExperimentTestGroup.mockDataGeneratorVariant;
9797

98-
const shouldShowMockDataButton =
98+
let shouldShowMockDataButton =
9999
isInMockDataTreatmentVariant &&
100100
atlasMetadata && // Only show in Atlas
101101
!isReadonly && // Don't show for readonly collections (views)
102102
!sourceName; // sourceName indicates it's a view
103103

104+
// shouldShowMockDataButton = true;
105+
104106
const exceedsMaxNestingDepth =
105107
analyzedSchemaDepth > MAX_COLLECTION_NESTING_DEPTH;
106108

@@ -145,7 +147,7 @@ const CollectionHeaderActions: React.FunctionComponent<
145147
</div>
146148
}
147149
>
148-
{/* todo within (CLOUDP-333853): update disabled open-modal button
150+
{/* TODO(CLOUDP-333853): update disabled open-modal button
149151
tooltip to communicate if schema analysis is incomplete */}
150152
{exceedsMaxNestingDepth &&
151153
'At this time we are unable to generate mock data for collections that have deeply nested documents'}

packages/compass-collection/src/components/mock-data-generator-modal/mock-data-generator-modal.spec.tsx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -213,32 +213,32 @@ describe('MockDataGeneratorModal', () => {
213213

214214
it('displays the namespace', async () => {
215215
await renderModal();
216-
expect(screen.queryByText('test.collection')).to.exist;
216+
expect(screen.getByText('test.collection')).to.exist;
217217
});
218218

219219
it('uses the appropriate copy when Generative AI sample document passing is enabled', async () => {
220220
await renderModal({ enableGenAISampleDocumentPassing: true });
221-
expect(screen.queryByText('Sample Documents Collected')).to.exist;
221+
expect(screen.getByText('Sample Documents Collected')).to.exist;
222222
expect(
223-
screen.queryByText(
224-
'A sample of document values from your collection will be sent to an LLM for processing.'
223+
screen.getByText(
224+
'A sample of documents from your collection will be sent to an LLM for processing.'
225225
)
226226
).to.exist;
227227
// fragment from { "name": "John" }
228-
expect(screen.queryByText('"John"')).to.exist;
228+
expect(screen.getByText('"John"')).to.exist;
229229
expect(screen.queryByText('"String"')).to.not.exist;
230230
});
231231

232232
it('uses the appropriate copy when Generative AI sample document passing is disabled', async () => {
233233
await renderModal();
234-
expect(screen.queryByText('Document Schema Identified')).to.exist;
234+
expect(screen.getByText('Document Schema Identified')).to.exist;
235235
expect(
236236
screen.queryByText(
237237
'We have identified the following schema from your documents. This schema will be sent to an LLM for processing.'
238238
)
239239
).to.exist;
240240
// fragment from { "name": "String" }
241-
expect(screen.queryByText('"String"')).to.exist;
241+
expect(screen.getByText('"String"')).to.exist;
242242
expect(screen.queryByText('"John"')).to.not.exist;
243243
});
244244

packages/compass-collection/src/components/mock-data-generator-modal/mock-data-generator-modal.tsx

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { connect } from 'react-redux';
33

44
import {
55
css,
6+
Body,
67
Button,
78
ButtonVariant,
89
ModalBody,
@@ -36,13 +37,19 @@ const rightButtonsStyles = css`
3637
flex-direction: row;
3738
`;
3839

40+
const namespaceStyles = css({
41+
marginTop: spacing[200],
42+
marginBottom: spacing[400],
43+
});
44+
3945
interface Props {
4046
isOpen: boolean;
4147
onClose: () => void;
4248
currentStep: MockDataGeneratorStep;
4349
onNextStep: () => void;
4450
onConfirmSchema: () => Promise<void>;
4551
onPreviousStep: () => void;
52+
namespace: string;
4653
}
4754

4855
const MockDataGeneratorModal = ({
@@ -52,6 +59,7 @@ const MockDataGeneratorModal = ({
5259
onNextStep,
5360
onConfirmSchema,
5461
onPreviousStep,
62+
namespace,
5563
}: Props) => {
5664
const modalBodyContent = useMemo(() => {
5765
switch (currentStep) {
@@ -78,6 +86,9 @@ const MockDataGeneratorModal = ({
7886
}
7987
};
8088

89+
const shouldShowNamespace =
90+
currentStep !== MockDataGeneratorStep.GENERATE_DATA;
91+
8192
return (
8293
<Modal
8394
size="large"
@@ -91,6 +102,9 @@ const MockDataGeneratorModal = ({
91102
>
92103
<ModalHeader title="Generate Mock Data" />
93104
<ModalBody>
105+
{shouldShowNamespace && (
106+
<Body className={namespaceStyles}>{namespace}</Body>
107+
)}
94108
<div data-testid={`generate-mock-data-step-${currentStep}`}>
95109
{modalBodyContent}
96110
</div>
@@ -120,6 +134,7 @@ const MockDataGeneratorModal = ({
120134
const mapStateToProps = (state: CollectionState) => ({
121135
isOpen: state.mockDataGenerator.isModalOpen,
122136
currentStep: state.mockDataGenerator.currentStep,
137+
namespace: state.namespace,
123138
});
124139

125140
const ConnectedMockDataGeneratorModal = connect(mapStateToProps, {

packages/compass-collection/src/components/mock-data-generator-modal/raw-schema-confirmation-screen.tsx

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import {
77
spacing,
88
Banner,
99
BannerVariant,
10-
Code,
1110
Body,
1211
} from '@mongodb-js/compass-components';
1312

@@ -16,26 +15,23 @@ import toSimplifiedFieldInfo from './to-simplified-field-info';
1615
import type { CollectionState } from '../../modules/collection-tab';
1716
import type { SchemaAnalysisState } from '../../schema-analysis-types';
1817
import type { MockDataGeneratorState } from './types';
18+
import { Document } from '@mongodb-js/compass-crud';
1919

2020
interface RawSchemaConfirmationScreenProps {
2121
schemaAnalysis: SchemaAnalysisState;
22-
namespace: string;
2322
fakerSchemaGenerationStatus: MockDataGeneratorState['status'];
2423
}
2524

26-
const namespaceStyles = css({
27-
marginTop: spacing[200],
28-
marginBottom: spacing[400],
25+
const documentContainerStyles = css({
26+
backgroundColor: palette.gray.light3,
27+
border: `1px solid ${palette.gray.light2}`,
28+
borderRadius: spacing[400],
2929
});
3030

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

35-
const codeStyles = css({
36-
maxHeight: '30vh',
37-
});
38-
3935
const errorBannerStyles = css({
4036
marginTop: spacing[400],
4137
});
@@ -46,39 +42,40 @@ const errorBannerTextStyles = css({
4642

4743
const RawSchemaConfirmationScreen = ({
4844
schemaAnalysis,
49-
namespace,
5045
fakerSchemaGenerationStatus,
5146
}: RawSchemaConfirmationScreenProps) => {
52-
const enableSampleDocumentPassing = usePreference(
47+
let enableSampleDocumentPassing = usePreference(
5348
'enableGenAISampleDocumentPassing'
5449
);
5550

51+
// enableSampleDocumentPassing = false;
52+
5653
const subtitleText = enableSampleDocumentPassing
5754
? 'Sample Documents Collected'
5855
: 'Document Schema Identified';
5956

6057
const descriptionText = enableSampleDocumentPassing
61-
? 'A sample of document values from your collection will be sent to an LLM for processing.'
58+
? 'A sample of documents from your collection will be sent to an LLM for processing.'
6259
: 'We have identified the following schema from your documents. This schema will be sent to an LLM for processing.';
6360

6461
return (
6562
<div data-testid="raw-schema-confirmation">
6663
{schemaAnalysis.status === 'complete' ? (
6764
<>
68-
<Body className={namespaceStyles}>{namespace}</Body>
6965
<Body as="h2" baseFontSize={16} weight="medium">
7066
{subtitleText}
7167
</Body>
7268
<Body className={descriptionStyles}>{descriptionText}</Body>
73-
<Code language="javascript" copyable={false} className={codeStyles}>
74-
{enableSampleDocumentPassing
75-
? JSON.stringify(schemaAnalysis.sampleDocument, null, 4)
76-
: JSON.stringify(
77-
toSimplifiedFieldInfo(schemaAnalysis.processedSchema),
78-
null,
79-
4
80-
)}
81-
</Code>
69+
<div className={documentContainerStyles}>
70+
<Document
71+
editable={false}
72+
doc={
73+
enableSampleDocumentPassing
74+
? schemaAnalysis.sampleDocument
75+
: toSimplifiedFieldInfo(schemaAnalysis.processedSchema)
76+
}
77+
/>
78+
</div>
8279
{fakerSchemaGenerationStatus === 'error' && (
8380
<Banner
8481
variant={BannerVariant.Danger}
@@ -104,7 +101,6 @@ const mapStateToProps = (state: CollectionState) => {
104101

105102
return {
106103
schemaAnalysis,
107-
namespace: state.namespace,
108104
fakerSchemaGenerationStatus,
109105
};
110106
};

packages/compass-collection/src/transform-schema-to-field-info.spec.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1137,7 +1137,7 @@ describe('processSchema', function () {
11371137
};
11381138

11391139
expect(() => processSchema(schema)).to.throw(
1140-
'invalid fieldPath "field[invalid": "[]" can only appear at the end of field parts'
1140+
"invalid fieldPath 'field[invalid': '[]' can only appear at the end of field parts"
11411141
);
11421142
});
11431143

@@ -1167,7 +1167,7 @@ describe('processSchema', function () {
11671167
};
11681168

11691169
expect(() => processSchema(schema)).to.throw(
1170-
'invalid fieldPath "field[]invalid": "[]" can only appear at the end of field parts'
1170+
"invalid fieldPath 'field[]invalid': '[]' can only appear at the end of field parts"
11711171
);
11721172
});
11731173

@@ -1216,11 +1216,11 @@ describe('processSchema', function () {
12161216
};
12171217

12181218
expect(() => processSchema(schema)).to.throw(
1219-
'invalid fieldPath "parent.": field parts cannot be empty'
1219+
"invalid fieldPath 'parent.': field parts cannot be empty"
12201220
);
12211221
});
12221222

1223-
it('throws error for field part that is only "[]"', function () {
1223+
it('throws error for a field part that only contains "[]"', function () {
12241224
const schema: Schema = {
12251225
fields: [
12261226
{
@@ -1246,7 +1246,7 @@ describe('processSchema', function () {
12461246
};
12471247

12481248
expect(() => processSchema(schema)).to.throw(
1249-
"expected fieldPath to have a non-empty part before '[]'"
1249+
"invalid fieldPath '[]': field parts must have characters other than '[]'"
12501250
);
12511251
});
12521252
});

packages/compass-collection/src/transform-schema-to-field-info.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -239,12 +239,14 @@ function validateFieldPath(fieldPath: string) {
239239
for (const part of parts) {
240240
if (part === '') {
241241
throw new Error(
242-
`invalid fieldPath "${fieldPath}": field parts cannot be empty`
242+
`invalid fieldPath '${fieldPath}': field parts cannot be empty`
243243
);
244244
}
245245

246246
if (part.replaceAll('[]', '') === '') {
247-
throw Error("expected fieldPath to have a non-empty part before '[]'");
247+
throw new Error(
248+
`invalid fieldPath '${fieldPath}': field parts must have characters other than '[]'`
249+
);
248250
}
249251

250252
// Check that [] only appears as complete pairs and only at the end of the part
@@ -256,7 +258,7 @@ function validateFieldPath(fieldPath: string) {
256258
const remaining = part.replace(/(\[\])+$/, '');
257259
if (remaining.includes('[') || remaining.includes(']')) {
258260
throw new Error(
259-
`invalid fieldPath "${fieldPath}": "[]" can only appear at the end of field parts`
261+
`invalid fieldPath '${fieldPath}': '[]' can only appear at the end of field parts`
260262
);
261263
}
262264
}

0 commit comments

Comments
 (0)