fix(form): avoid splitting property names in schema path
The schema path passed to custom components in the formInfo prop didn't handle property names containing underscore as expected.
Now the schema id is not split when a property name can be found in the form data matching all or some leading parts of the schema id.
Review:
- [ ] Commits are atomic
- [ ] Commits have the correct type for the changes made
- [ ] Commits with breaking changes are marked as such
Browsers tested:
(Check any that applies, it's ok to leave boxes unchecked if testing something didn't seem relevant.)
Windows:
- [ ] Chrome
- [ ] Edge
- [ ] Firefox
Linux:
- [ ] Chrome
- [ ] Firefox
macOS:
- [ ] Chrome
- [ ] Firefox
- [ ] Safari
Mobile:
- [ ] Chrome on Android
- [ ] iOS
Summary by CodeRabbit
-
Refactor
- Improved the logic for extracting nested property paths in forms.
- Enhanced handling of complex property identifiers, ensuring more accurate mapping of form data.
Documentation has been published to https://lundalogik.github.io/lime-elements/versions/PR-2884/
Walkthrough
The pull request updates the SchemaField class by revising the logic in the getSchemaPath method to build a property path array from a given schemaId. The updated approach identifies start and end indices based on the schemaId and the component's name. Additionally, a new private method splitSchemaId is introduced to split the schemaId into an array of property names in a controlled manner, preserving elements that contain the separator and verifying the existence of keys in formData.
Changes
| File | Change Summary |
|---|---|
src/components/.../schema-field.ts |
Updated getSchemaPath to compute a property path array from schemaId. Added private method splitSchemaId to split the schemaId into an array while preserving separators and validating against formData. |
Sequence Diagram(s)
sequenceDiagram
participant Client as Caller
participant SF as SchemaField
Client->>SF: getSchemaPath(schemaId)
SF->>SF: Calculate start/end indices from schemaId
SF->>SF: Call splitSchemaId(schemaId, separator)
SF->>SF: Iteratively build property path by checking keys in formData
SF-->>Client: Return property path array
📜 Recent review details
Configuration used: CodeRabbit UI Review profile: ASSERTIVE Plan: Pro
📥 Commits
Reviewing files that changed from the base of the PR and between 0869328e28af2a73d7f7164181fce30fbccad20b and 0a7c6f469eb3de2d0ae308cebd85ea6811c8fb22.
📒 Files selected for processing (1)
-
src/components/form/fields/schema-field.ts(2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (3)
- GitHub Check: Docs / Publish Docs
- GitHub Check: Test
- GitHub Check: Build
🔇 Additional comments (3)
src/components/form/fields/schema-field.ts (3)
4-4: Good use ofhasfor nested property checks.Importing
hasfromlodash-escan be beneficial for succinct and reliable nested property checks. No further concerns here.
308-323:❓ Verification inconclusive
Validate slicing logic for schema ID edge cases.
Consider verifying how this logic behaves if
this.props.nameis absent from theschemaIdor when underscores appear unexpectedly in the property names. Make sure negative indices or missing splits don’t produce unintended paths.
🏁 Script executed:
#!/bin/bash # Verify test coverage for getSchemaPath edge cases fd test | xargs rg -A 10 "getSchemaPath"Length of output: 40
Action Required: Add Unit Tests for Schema ID Slicing Edge Cases
The current test search for
getSchemaPathdidn’t yield any matching tests. This raises concerns about unverified edge scenarios. Please ensure that there are tests covering cases such as:
- When
this.props.nameis not found in theschemaId.- When underscores appear unexpectedly in property names, potentially leading to negative indices or improper slicing.
Manually verify that the slicing logic in
src/components/form/fields/schema-field.ts(lines 308–323) behaves correctly under these conditions.
325-361:❓ Verification inconclusive
Ensure thorough testing of
splitSchemaId.The approach for building the path by peeling off valid keys seems sound. However, confirm that it works correctly for array indexes, nested objects, and property names containing underscores. Robust tests help ensure no hidden corner cases remain.
🏁 Script executed:
#!/bin/bash # Scan test files for splitSchemaId usage or coverage fd test | xargs rg -A 10 "splitSchemaId"Length of output: 40
Ensure Robust Test Coverage for splitSchemaId
Our initial search for tests referencing splitSchemaId returned no results. Please verify manually whether comprehensive tests exist—or add tests—to cover scenarios including:
- Array indexes as keys.
- Nested object paths.
- Property names containing the separator or underscores.
This will help ensure the function handles all edge cases appropriately.
✨ Finishing Touches
- [ ] 📝 Generate Docstrings
🪧 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
@coderabbitaiin 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
@coderabbitaiin 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 pauseto pause the reviews on a PR. -
@coderabbitai resumeto resume the paused reviews. -
@coderabbitai reviewto trigger an incremental review. This is useful when automatic reviews are disabled for the repository. -
@coderabbitai full reviewto do a full review from scratch and review all the files again. -
@coderabbitai summaryto regenerate the summary of the PR. -
@coderabbitai generate docstringsto generate docstrings for this PR. -
@coderabbitai resolveresolve all the CodeRabbit review comments. -
@coderabbitai configurationto show the current CodeRabbit configuration for the repository. -
@coderabbitai helpto get help.
Other keywords and placeholders
- Add
@coderabbitai ignoreanywhere in the PR description to prevent this PR from being reviewed. - Add
@coderabbitai summaryto generate the high-level summary at a specific location in the PR description. - Add
@coderabbitaianywhere in the PR title to generate the title automatically.
CodeRabbit Configuration File (.coderabbit.yaml)
- You can programmatically configure CodeRabbit by adding a
.coderabbit.yamlfile 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.