Skip to content

Commit 23270b2

Browse files
authored
chore(compass-collection): Mock data generator design items CLOUDP-352955 (#7500)
* Mock data generator compass design items
1 parent a3c4dc7 commit 23270b2

File tree

5 files changed

+56
-96
lines changed

5 files changed

+56
-96
lines changed

packages/compass-collection/src/components/mock-data-generator-modal/faker-schema-editor-screen.tsx

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ const FakerSchemaEditorContent = ({
6161
onSchemaConfirmed,
6262
}: {
6363
fakerSchema: FakerSchema;
64-
onSchemaConfirmed: (isConfirmed: boolean) => void;
64+
onSchemaConfirmed: () => void;
6565
}) => {
6666
const track = useTelemetry();
6767
const [fakerSchemaFormValues, setFakerSchemaFormValues] =
@@ -86,10 +86,6 @@ const FakerSchemaEditorContent = ({
8686
const activeFakerFunction = fakerSchemaFormValues[activeField]?.fakerMethod;
8787
const activeFakerArgs = fakerSchemaFormValues[activeField]?.fakerArgs;
8888

89-
const resetIsSchemaConfirmed = () => {
90-
onSchemaConfirmed(false);
91-
};
92-
9389
const onJsonTypeSelect = (newJsonType: MongoDBFieldType) => {
9490
const currentMapping = fakerSchemaFormValues[activeField];
9591
const originalLlmMapping = originalLlmMappings.current[activeField];
@@ -124,7 +120,6 @@ const FakerSchemaEditorContent = ({
124120
...fakerSchemaFormValues,
125121
[activeField]: newMapping,
126122
});
127-
resetIsSchemaConfirmed();
128123
}
129124
};
130125

@@ -159,7 +154,6 @@ const FakerSchemaEditorContent = ({
159154
...fakerSchemaFormValues,
160155
[activeField]: newMapping,
161156
});
162-
resetIsSchemaConfirmed();
163157
}
164158
};
165159

@@ -170,6 +164,7 @@ const FakerSchemaEditorContent = ({
170164
activeField={activeField}
171165
fields={fieldPaths}
172166
onFieldSelect={setActiveField}
167+
fakerSchema={fakerSchemaFormValues}
173168
/>
174169
{activeJsonType && activeFakerFunction && (
175170
<FakerMappingSelector
@@ -185,7 +180,7 @@ const FakerSchemaEditorContent = ({
185180
size={ButtonSize.Small}
186181
className={confirmMappingsButtonStyles}
187182
variant={ButtonVariant.Primary}
188-
onClick={() => onSchemaConfirmed(true)}
183+
onClick={onSchemaConfirmed}
189184
>
190185
Confirm mappings
191186
</Button>
@@ -197,7 +192,7 @@ const FakerSchemaEditorScreen = ({
197192
onSchemaConfirmed,
198193
fakerSchemaGenerationState,
199194
}: {
200-
onSchemaConfirmed: (isConfirmed: boolean) => void;
195+
onSchemaConfirmed: () => void;
201196
fakerSchemaGenerationState: MockDataGeneratorState;
202197
}) => {
203198
return (

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

Lines changed: 27 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,30 @@ describe('MockDataGeneratorModal', () => {
405405
expect(screen.getByTestId('faker-schema-editor-loader')).to.exist;
406406
});
407407

408+
it('the next button is disabled when the faker schema generation is in progress', async () => {
409+
const mockServices = createMockServices();
410+
mockServices.atlasAiService.getMockDataSchema = () =>
411+
new Promise((resolve) =>
412+
setTimeout(
413+
() =>
414+
resolve({
415+
fields: [],
416+
}),
417+
1
418+
)
419+
);
420+
421+
await renderModal({ mockServices });
422+
423+
// advance to the schema editor step
424+
userEvent.click(screen.getByText('Confirm'));
425+
expect(screen.getByTestId('faker-schema-editor-loader')).to.exist;
426+
427+
expect(
428+
screen.getByTestId('next-step-button').getAttribute('aria-disabled')
429+
).to.equal('true');
430+
});
431+
408432
it('shows the faker schema editor when the faker schema generation is completed', async () => {
409433
await renderModal({
410434
mockServices: mockServicesWithMockDataResponse,
@@ -684,95 +708,25 @@ describe('MockDataGeneratorModal', () => {
684708
expect(screen.queryByText(/100000/)).to.not.exist;
685709
});
686710

687-
it('disables the Next button when the faker schema mapping is not confirmed', async () => {
711+
it('clicking the confirm schema mapping button advances to the document count step', async () => {
688712
await renderModal({
689713
mockServices: mockServicesWithMockDataResponse,
690714
schemaAnalysis: mockSchemaAnalysis,
691715
});
692716

693717
// advance to the schema editor step
694718
userEvent.click(screen.getByText('Confirm'));
695-
await waitFor(() => {
696-
expect(screen.getByTestId('faker-schema-editor')).to.exist;
697-
});
698-
699-
expect(
700-
screen.getByTestId('next-step-button').getAttribute('aria-disabled')
701-
).to.equal('true');
702-
});
703719

704-
it('resets the confirm schema mapping state when the user clicks the back button then goes back to the schema editor step', async () => {
705-
await renderModal({
706-
mockServices: mockServicesWithMockDataResponse,
707-
schemaAnalysis: mockSchemaAnalysis,
708-
});
709-
710-
// advance to the schema editor step
711-
userEvent.click(screen.getByText('Confirm'));
712720
await waitFor(() => {
713721
expect(screen.getByTestId('faker-schema-editor')).to.exist;
714722
});
715-
expect(
716-
screen.getByTestId('next-step-button').getAttribute('aria-disabled')
717-
).to.equal('true');
718-
// click confirm mappings button
719-
userEvent.click(screen.getByText('Confirm mappings'));
720-
expect(
721-
screen.getByTestId('next-step-button').getAttribute('aria-disabled')
722-
).to.equal('false');
723-
724-
// click back button
725-
userEvent.click(screen.getByText('Back'));
726-
await waitFor(() => {
727-
expect(screen.getByTestId('raw-schema-confirmation')).to.exist;
728-
});
729-
730-
// click next button to advance to the schema editor step again
731-
userEvent.click(screen.getByTestId('next-step-button'));
732-
await waitFor(() => {
733-
expect(screen.getByTestId('faker-schema-editor')).to.exist;
734-
});
735-
// the next button should be disabled again
736-
expect(
737-
screen.getByTestId('next-step-button').getAttribute('aria-disabled')
738-
).to.equal('true');
739-
});
740-
741-
it('preserves the confirm schema mapping state when the user clicks the next button then goes back to the schema editor step', async () => {
742-
await renderModal({
743-
mockServices: mockServicesWithMockDataResponse,
744-
schemaAnalysis: mockSchemaAnalysis,
745-
});
746723

747-
// advance to the schema editor step
748-
userEvent.click(screen.getByText('Confirm'));
749-
await waitFor(() => {
750-
expect(screen.getByTestId('faker-schema-editor')).to.exist;
751-
});
752-
expect(
753-
screen.getByTestId('next-step-button').getAttribute('aria-disabled')
754-
).to.equal('true');
755-
// click confirm mappings button
756724
userEvent.click(screen.getByText('Confirm mappings'));
757-
expect(
758-
screen.getByTestId('next-step-button').getAttribute('aria-disabled')
759-
).to.equal('false');
760-
761-
// click next button
762-
userEvent.click(screen.getByTestId('next-step-button'));
763-
await waitFor(() => {
764-
expect(screen.queryByTestId('faker-schema-editor')).to.not.exist;
765-
});
766725

767-
// click back button to go back to the schema editor step
768-
userEvent.click(screen.getByText('Back'));
769726
await waitFor(() => {
770-
expect(screen.getByTestId('faker-schema-editor')).to.exist;
727+
expect(screen.getByText('Specify Number of Documents to Generate')).to
728+
.exist;
771729
});
772-
// the next button should not be disabled
773-
expect(
774-
screen.getByTestId('next-step-button').getAttribute('aria-disabled')
775-
).to.equal('false');
776730
});
777731

778732
it('fires a track event when the user changes the JSON field type', async () => {

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

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,6 @@ const MockDataGeneratorModal = ({
7676
namespace,
7777
fakerSchemaGenerationState,
7878
}: Props) => {
79-
const [isSchemaConfirmed, setIsSchemaConfirmed] =
80-
React.useState<boolean>(false);
8179
const [documentCount, setDocumentCount] = React.useState<number>(
8280
DEFAULT_DOCUMENT_COUNT
8381
);
@@ -94,7 +92,7 @@ const MockDataGeneratorModal = ({
9492
case MockDataGeneratorStep.SCHEMA_EDITOR:
9593
return (
9694
<FakerSchemaEditorScreen
97-
onSchemaConfirmed={setIsSchemaConfirmed}
95+
onSchemaConfirmed={onNextStep}
9896
fakerSchemaGenerationState={fakerSchemaGenerationState}
9997
/>
10098
);
@@ -123,6 +121,7 @@ const MockDataGeneratorModal = ({
123121
fakerSchemaGenerationState,
124122
documentCount,
125123
setDocumentCount,
124+
onNextStep,
126125
]);
127126

128127
useEffect(() => {
@@ -133,7 +132,7 @@ const MockDataGeneratorModal = ({
133132

134133
const isNextButtonDisabled =
135134
(currentStep === MockDataGeneratorStep.SCHEMA_EDITOR &&
136-
!isSchemaConfirmed) ||
135+
fakerSchemaGenerationState.status !== 'completed') ||
137136
(currentStep === MockDataGeneratorStep.DOCUMENT_COUNT &&
138137
documentCount < 1) ||
139138
(currentStep === MockDataGeneratorStep.DOCUMENT_COUNT &&
@@ -158,14 +157,6 @@ const MockDataGeneratorModal = ({
158157
const shouldShowNamespace =
159158
currentStep !== MockDataGeneratorStep.GENERATE_DATA;
160159

161-
const handlePreviousClick = () => {
162-
if (currentStep === MockDataGeneratorStep.SCHEMA_EDITOR) {
163-
// reset isSchemaConfirmed state when previous step is clicked
164-
setIsSchemaConfirmed(false);
165-
}
166-
onPreviousStep();
167-
};
168-
169160
const onModalClose = useCallback(() => {
170161
track('Mock Data Generator Dismissed', {
171162
screen: currentStep,
@@ -203,7 +194,7 @@ const MockDataGeneratorModal = ({
203194
</ModalBody>
204195
<ModalFooter className={footerStyles}>
205196
<Button
206-
onClick={handlePreviousClick}
197+
onClick={onPreviousStep}
207198
disabled={currentStep === MockDataGeneratorStep.SCHEMA_CONFIRMATION}
208199
>
209200
Back

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@ import {
66
palette,
77
useDarkMode,
88
Body,
9+
Icon,
910
} from '@mongodb-js/compass-components';
11+
import { UNRECOGNIZED_FAKER_METHOD } from '../../modules/collection-tab';
12+
import type { FakerSchema } from './types';
1013

1114
const fieldsContainerStyles = css({
1215
width: '40%',
@@ -30,6 +33,9 @@ const buttonStyles = css({
3033
padding: spacing[200],
3134
textAlign: 'left',
3235
fontWeight: 500,
36+
display: 'flex',
37+
alignItems: 'center',
38+
gap: '8px',
3339
});
3440

3541
const activeStylesLight = css({
@@ -73,12 +79,23 @@ type SidebarProps = {
7379
activeField: string;
7480
onFieldSelect: (field: string) => void;
7581
fields: Array<string>;
82+
fakerSchema?: FakerSchema;
83+
};
84+
85+
const shouldShowUnrecognizedIcon = (
86+
field: string,
87+
fakerSchema?: FakerSchema
88+
): boolean => {
89+
const mapping = fakerSchema?.[field];
90+
91+
return !!mapping && mapping.fakerMethod === UNRECOGNIZED_FAKER_METHOD;
7692
};
7793

7894
const FieldSelector: React.FunctionComponent<SidebarProps> = ({
7995
activeField,
8096
fields,
8197
onFieldSelect,
98+
fakerSchema,
8299
}) => {
83100
const darkMode = useDarkMode();
84101

@@ -109,6 +126,9 @@ const FieldSelector: React.FunctionComponent<SidebarProps> = ({
109126
onClick={() => onFieldSelect(field)}
110127
>
111128
{field}
129+
{shouldShowUnrecognizedIcon(field, fakerSchema) && (
130+
<Icon glyph="ImportantWithCircle" />
131+
)}
112132
</button>
113133
))}
114134
</div>

packages/compass-collection/src/components/mock-data-generator-modal/script-generation-utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -708,7 +708,7 @@ function generateFakerValue(
708708
mapping: FakerFieldMapping
709709
): string | number | boolean | Date | null | undefined {
710710
const method =
711-
mapping.fakerMethod === 'unrecognized'
711+
mapping.fakerMethod === UNRECOGNIZED_FAKER_METHOD
712712
? getDefaultFakerMethod(mapping.mongoType)
713713
: mapping.fakerMethod;
714714

0 commit comments

Comments
 (0)