Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: handling of nested array props overriding #133

Merged
merged 2 commits into from
Jan 28, 2025

Conversation

koladilip
Copy link
Collaborator

@koladilip koladilip commented Jan 28, 2025

What are the changes introduced in this PR?

Before:
Input:

[
  {
    "from": "$.properties",
    "to": "$.properties"
  },
  {
    "to": "$.properties.products[0].category",
    "from": "$.category"
  }
]

Output:

{
    "properties": [{
        ...$.properties,
        "products": [{
            "category": $.category
        }]
    }]
}

After fix:
Output:

{
    "properties": {
        ...$.properties,
        "products": [{
            "category": $.category
        }]
    }
}

Also now the following works and previously it was giving an error:

[
  {
    "from": "$.properties",
    "to": "$.properties"
  },
  {
    "to": "$.properties.products[0].category",
    "from": "$.category"
  },
 {
    "to": "$.properties.products[1].category",
    "from": "$.category"
  }
]

What is the related Linear task?

Resolves INT-3184

Please explain the objectives of your changes below

Put down any required details on the broader aspect of your changes. If there are any dependent changes, mandatorily mention them here

Any changes to existing capabilities/behaviour, mention the reason & what are the changes ?

N/A

Any new dependencies introduced with this change?

N/A

Any new generic utility introduced or modified. Please explain the changes.

N/A

Any technical or performance related pointers to consider with the change?

N/A

@coderabbitai review


Developer checklist

  • My code follows the style guidelines of this project

  • No breaking changes are being introduced.

  • All related docs linked with the PR?

  • All changes manually tested?

  • Any documentation changes needed with this change?

  • Is the PR limited to 10 file changes?

  • Is the PR limited to one linear task?

  • Are relevant unit and component test-cases added?

Reviewer checklist

  • Is the type of change in the PR title appropriate as per the changes?

  • Verified that there are no credentials or confidential data exposed with the changes.

Summary by CodeRabbit

  • New Features
    • Added a new mapping scenario for handling nested arrays, allowing for dynamic reassignment of values based on specified paths.
  • Refactor
    • Minor internal optimizations to array index filtering and part processing logic.
    • Adjusted control flow in utility conversion functions.

Note: These changes are primarily internal improvements that do not directly impact end-user functionality.

@koladilip koladilip requested a review from a team as a code owner January 28, 2025 12:48
Copy link

coderabbitai bot commented Jan 28, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

The pull request introduces modifications to the src/utils/converter.ts file, specifically focusing on the processArrayIndexFilter and handleNextParts functions. The changes involve reordering a variable declaration in processArrayIndexFilter and adding a new conditional check in handleNextParts that allows for an early return when processing output parts. These modifications subtly alter the control flow without fundamentally changing the core logic of the functions. Additionally, new mapping scenarios have been added to the test files to support the updated functionality.

Changes

File Change Summary
src/utils/converter.ts - Reordered objectExpr declaration in processArrayIndexFilter
- Added new conditional check in handleNextParts for early return with regular selectors
test/scenarios/mappings/data.ts - Added new mapping scenario with mappingsPath: 'override_nested_arrays.json', input: { properties: { type: 'bar', products: [{ name: 'a' }, { name: 'b' }] } }, output: { properties: { products: [{ category: 'bar' }, { category: 'bar' }], type: 'bar' } }
test/scenarios/mappings/override_nested_arrays.json - Added new JSON mappings for properties within a nested array, including mappings for $.properties and $.properties.type to product categories

Possibly related PRs

Suggested reviewers

  • aashishmalik
  • chandumlg
  • sandeepdsvs
  • utsabc

Poem

🐰 A Rabbit's Ode to Code Refactoring 🐰

In converter's realm, a subtle dance,
Lines shift and flow with gentle chance,
Early returns, a whisker's might,
Refactoring code with pure delight!
Hop, hop, hooray for cleaner ways! 🌟


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 06b222d and 78813b8.

📒 Files selected for processing (2)
  • test/scenarios/mappings/data.ts (1 hunks)
  • test/scenarios/mappings/override_nested_arrays.json (1 hunks)
✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@koladilip koladilip requested a review from utsabc January 28, 2025 12:49
Copy link
Contributor

github-actions bot commented Jan 28, 2025

Coverage report

St.
Category Percentage Covered / Total
🟢 Statements
93.2% (-6.68% 🔻)
4839/5192
🟢 Branches
92.68% (-7.25% 🔻)
1216/1312
🟢 Functions 100% 387/387
🟢 Lines
93.2% (-6.68% 🔻)
4839/5192
Show files with reduced coverage 🔻
St.
File Statements Branches Functions Lines
🟢 engine.ts
95.33% (-4.67% 🔻)
88.46% (-11.54% 🔻)
100%
95.33% (-4.67% 🔻)
🟢 lexer.ts
87.18% (-12.82% 🔻)
91.93% (-8.07% 🔻)
100%
87.18% (-12.82% 🔻)
🟢 parser.ts
88.56% (-11.44% 🔻)
89.78% (-10.22% 🔻)
100%
88.56% (-11.44% 🔻)
🟢 utils/common.ts 100%
88.89% (-11.11% 🔻)
100% 100%
🟢 utils/converter.ts
88.87% (-9.95% 🔻)
83.87% (-15.41% 🔻)
100%
88.87% (-9.95% 🔻)

Test suite run success

219 tests passing in 7 suites.

Report generated by 🧪jest coverage report action from 78813b8

Copy link

codecov bot commented Jan 28, 2025

Codecov Report

Attention: Patch coverage is 50.00000% with 2 lines in your changes missing coverage. Please review.

Project coverage is 91.50%. Comparing base (97d95e8) to head (78813b8).
Report is 67 commits behind head on main.

Files with missing lines Patch % Lines
src/utils/converter.ts 50.00% 2 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##              main     #133      +/-   ##
===========================================
- Coverage   100.00%   91.50%   -8.50%     
===========================================
  Files           14       18       +4     
  Lines         4565     5192     +627     
  Branches      1082     1145      +63     
===========================================
+ Hits          4565     4751     +186     
- Misses           0      431     +431     
- Partials         0       10      +10     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
src/utils/converter.ts (1)

377-379: The changes effectively address the nested array props issue.

The solution elegantly fixes the nested array properties overriding by:

  1. Ensuring proper validation before accessing array elements
  2. Adding an early return for regular selectors to prevent unnecessary processing

This maintains the JSON template engine's integrity while fixing the specific issue without introducing breaking changes.

Also applies to: 88-88

🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 378-379: src/utils/converter.ts#L378-L379
Added lines #L378 - L379 were not covered by tests

🪛 GitHub Check: Coverage annotations (🧪 jest-coverage-report-action)

[warning] 378-378: 🧾 Statement is not covered
Warning! Not covered statement


[warning] 379-379: 🧾 Statement is not covered
Warning! Not covered statement


[warning] 377-379: 🌿 Branch is not covered
Warning! Not covered branch

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between abf135c and 06b222d.

📒 Files selected for processing (1)
  • src/utils/converter.ts (2 hunks)
🧰 Additional context used
🪛 GitHub Check: codecov/patch
src/utils/converter.ts

[warning] 378-379: src/utils/converter.ts#L378-L379
Added lines #L378 - L379 were not covered by tests

🪛 GitHub Check: Coverage annotations (🧪 jest-coverage-report-action)
src/utils/converter.ts

[warning] 378-378: 🧾 Statement is not covered
Warning! Not covered statement


[warning] 379-379: 🧾 Statement is not covered
Warning! Not covered statement


[warning] 377-379: 🌿 Branch is not covered
Warning! Not covered branch

🔇 Additional comments (2)
src/utils/converter.ts (2)

88-88: LGTM! Good reordering of variable declaration.

Moving the variable declaration after validation is a logical improvement as it ensures we validate the array elements before accessing them.


377-379: Add test coverage for the new conditional.

The new conditional that handles regular selectors is a crucial part of fixing nested array props overriding, but it lacks test coverage. This could lead to potential regressions.

Let's verify the impact of this change:

Would you like me to help generate test cases to cover this new conditional? This should include:

  1. Test case with regular selectors that trigger the early return
  2. Test case with nested array properties to verify the fix
🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 378-379: src/utils/converter.ts#L378-L379
Added lines #L378 - L379 were not covered by tests

🪛 GitHub Check: Coverage annotations (🧪 jest-coverage-report-action)

[warning] 378-378: 🧾 Statement is not covered
Warning! Not covered statement


[warning] 379-379: 🧾 Statement is not covered
Warning! Not covered statement


[warning] 377-379: 🌿 Branch is not covered
Warning! Not covered branch

sandeepdsvs
sandeepdsvs previously approved these changes Jan 28, 2025
@koladilip koladilip merged commit 80fc165 into main Jan 28, 2025
14 of 15 checks passed
@koladilip koladilip deleted the fix/handinging-overriding-array-props branch January 28, 2025 13:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants