Skip to content

Conversation

jcobis
Copy link
Collaborator

@jcobis jcobis commented Sep 22, 2025

Description

Connect the document generation engine to the result screen to render the output script.
Updates the array length map mocked up in previous PR to be simpler.

Screenshot 2025-09-24 at 1 12 07 PM Screenshot 2025-09-24 at 1 12 11 PM

(Note that I was branching off another PR before it was merged, which is why there are some commits appended in the commit history)

Checklist

  • New tests and/or benchmarks are included
  • Documentation is changed or added
  • If this change updates the UI, screenshots/videos are added and a design review is requested
  • I have signed the MongoDB Contributor License Agreement (https://www.mongodb.com/legal/contributor-agreement)

Types of changes

  • Backport Needed
  • Patch (non-breaking change which fixes an issue)
  • Minor (non-breaking change which adds functionality)
  • Major (fix or feature that would cause existing functionality to change)

@github-actions github-actions bot added the feat label Sep 22, 2025
@jcobis jcobis added the no release notes Fix or feature not for release notes label Sep 22, 2025
@jcobis jcobis marked this pull request as ready for review September 22, 2025 22:20
@jcobis jcobis requested a review from a team as a code owner September 22, 2025 22:20
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR connects the document generation engine to the Mock Data Generator's result screen to render the output script. It refactors the array length mapping system from a complex nested structure to a simpler flat mapping using dot notation with [] markers for arrays, and integrates this with the script generation utilities.

  • Updates processSchema to return both field information and array length mapping
  • Simplifies ArrayLengthMap type from nested object structure to flat Record<string, number>
  • Connects the script generation to the result screen component with proper data flow

Reviewed Changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
transform-schema-to-field-info.ts Adds array length calculation and updates processSchema to return both field info and array length map
transform-schema-to-field-info.spec.ts Updates tests to handle new processSchema return structure with fieldInfo and arrayLengthMap properties
schema-analysis-types.ts Adds arrayLengthMap property to SchemaAnalysisCompletedState interface
collection-tab.ts Updates reducer and action to handle arrayLengthMap from processSchema result
to-simplified-field-info.ts Updates function signature to accept fieldInfo property from processSchema result
script-screen.tsx Integrates script generation with faker schema and array length map, renders actual generated script
script-generation-utils.ts Simplifies ArrayLengthMap type and updates rendering logic to use flat dot notation paths
script-generation-utils.spec.ts Updates test cases to use simplified array length map structure
mock-data-generator-modal.tsx Connects array length map from schema analysis to script screen component
mock-data-generator-modal.spec.tsx Updates tests to provide completed faker schema generation state for script screen tests

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Just a general note, you have a lot of logic in this file formatting the script (and it still looks pretty messy) whereas we already have prettier bundled in the app and use it in other parts of the app for output code formatting, you can remove all this indenting logic and just format the script at the very end of this process:

import { prettify } from '@mongodb-js/code-editor';

// ...

funciton renderScript() {
  // ...
  return prettify(unformattedScriptString, 'javascript')
}

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good to know, changed!

Comment on lines 96 to 98
if (fakerSchemaGenerationState.status === 'completed') {
return (
<ScriptScreen
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is a weird split in component responsibilities, feels better suited for the ScriptScreen. So is the property passing, all this stuff is coming from state, so you should just connect the ScriptScreen component to this state directly as the redux documentation recommends

<Code
copyable={scriptResult.success}
language={Language.JavaScript}
style={{ maxHeight: '230px', overflowY: 'auto' }}
Copy link
Collaborator

Choose a reason for hiding this comment

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

That's an unexpected usage of style property, this is static, so can be defined as a className outside of render with css({})

Comment on lines 134 to 141
{!scriptResult.success && (
<Banner variant="danger">
<strong>Script Generation Failed:</strong> {scriptResult.error}
<br />
Please go back to the start screen to re-submit the collection
schema.
</Banner>
)}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Spacing is off here

image

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fixed
Screenshot 2025-09-25 at 1 02 09 PM

expect(result.script).to.contain(expectedReturnBlock);
expect(result.script).to.contain('Array.from');
expect(result.script).to.contain('length: 3');
expect(result.script).to.contain('faker.lorem.word()');
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Changing some of the simpler tests to be less strict because formatting is now handled by prettier

@jcobis jcobis requested a review from gribnoysup September 25, 2025 18:48
@jcobis jcobis merged commit b60d946 into main Oct 1, 2025
217 of 228 checks passed
@jcobis jcobis deleted the CLOUDP-333858 branch October 1, 2025 15:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feat no release notes Fix or feature not for release notes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants