Skip to content

[678] feat: Add form field standardizer module - #167

Merged
VitalyyP merged 6 commits into
mainfrom
678-feature/add-form-field-standardizer
Jun 10, 2025
Merged

[678] feat: Add form field standardizer module#167
VitalyyP merged 6 commits into
mainfrom
678-feature/add-form-field-standardizer

Conversation

@VitalyyP

@VitalyyP VitalyyP commented Jun 9, 2025

Copy link
Copy Markdown
Contributor
  • Added new form field standardizer module
  • Applied the standardizer to generate consistent (standardized) form field names

- Add form field standardizer module to standardize form field names\n- Create utility functions for field name standardization\n- Add comprehensive test suite for standardization logic\n- Register module in app.js
@VitalyyP
VitalyyP requested a review from killev as a code owner June 9, 2025 15:11
@coderabbitai

coderabbitai Bot commented Jun 9, 2025

Copy link
Copy Markdown
Contributor
📝 Walkthrough

"""

Walkthrough

A new module, form-field-standardizer, has been added and registered in the application configuration. This module hooks into the form saving process to standardize field names in form documents using a new utility function. The form module schema was extended with a read-only instructions field. The form widget configuration was simplified by removing a toolbar import. A new style rule was added for instructions fields. Comprehensive tests for the utility function are included.

Changes

File(s) Change Summary
website/app.js Registers the new form-field-standardizer module in the application configuration.
website/modules/form-field-standardizer/index.js Adds a module improving the form module by standardizing field names before saving forms.
website/utils/standardizeFieldNames.js Adds the standardizeFieldNames utility function to normalize field names in form documents.
website/utils/standardizeFieldNames.test.js Adds tests verifying correctness and robustness of the standardizeFieldNames function.
website/modules/@apostrophecms/form/index.js Improves the form module by adding a read-only instructions field with default guidance text.
website/modules/@apostrophecms/form-widget/index.js Removes import and usage of headingToolbar from the form widget’s rich-text intro field configuration.
website/modules/asset/ui/src/scss/_form.scss Adds CSS rule to style disabled .apos-input elements inside .apos-field--instructions containers.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant ApostropheCMS
    participant form-field-standardizer
    participant standardizeFieldNames

    User->>ApostropheCMS: Submit form
    ApostropheCMS->>form-field-standardizer: @apostrophecms/form:beforeSave event
    form-field-standardizer->>standardizeFieldNames: standardizeFieldNames(doc)
    standardizeFieldNames-->>form-field-standardizer: Standardized doc
    form-field-standardizer-->>ApostropheCMS: Proceed with saving standardized doc
Loading

Possibly related PRs

Suggested reviewers

  • yuramax
  • IhorMasechko
    """

📜 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 823184f and 72dd811.

📒 Files selected for processing (1)
  • website/modules/@apostrophecms/form/index.js (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • website/modules/@apostrophecms/form/index.js
⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: unit-tests
  • GitHub Check: e2e-tests
  • GitHub Check: lint
  • GitHub Check: security-scan
✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @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.

@VitalyyP VitalyyP changed the title feat: Add form field standardizer module [678] feat: Add form field standardizer module Jun 9, 2025

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (2)
website/utils/standardizeFieldNames.js (1)

5-22: Consider documenting the mutation behavior and adding error handling.

The function correctly implements field name standardization with good defensive programming. However, consider these improvements:

  1. Mutation: The function mutates the input document, which might be unexpected. Consider adding JSDoc to clarify this behavior.
  2. Error handling: No validation that STANDARD_FORM_FIELD_NAMES is properly structured.
  3. Return value: Consider returning a boolean or count indicating if any changes were made.

Add JSDoc documentation:

+/**
+ * Standardizes field names in a document's contents.items array.
+ * Mutates the input document in-place.
+ * @param {Object} doc - The document to standardize
+ */
 const standardizeFieldNames = (doc) => {

Consider adding basic validation:

 const standardizeFieldNames = (doc) => {
   if (!doc) return;
   const fieldNames = Object.values(STANDARD_FORM_FIELD_NAMES);
+  if (!Array.isArray(fieldNames) || fieldNames.length === 0) return;
website/modules/form-field-standardizer/index.js (1)

10-18: Good integration pattern with room for error handling.

The module correctly follows ApostropheCMS conventions using the improve pattern and registers the event handler appropriately. Consider adding error handling for robustness:

Add error handling to prevent save failures:

 handlers(self) {
   return {
     '@apostrophecms/form:beforeSave': {
       standardizeFieldNames(req, doc) {
-        standardizeFieldNames(doc);
+        try {
+          standardizeFieldNames(doc);
+        } catch (error) {
+          self.apos.util.error('Failed to standardize field names:', error);
+          // Continue with save - don't block form saving due to standardization errors
+        }
       },
     },
   };
 },
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 9876de9 and 6dbb058.

📒 Files selected for processing (4)
  • website/app.js (1 hunks)
  • website/modules/form-field-standardizer/index.js (1 hunks)
  • website/utils/standardizeFieldNames.js (1 hunks)
  • website/utils/standardizeFieldNames.test.js (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
website/utils/standardizeFieldNames.test.js (1)
website/utils/standardizeFieldNames.js (2)
  • require (1-3)
  • standardizeFieldNames (5-22)
⏰ Context from checks skipped due to timeout of 90000ms (6)
  • GitHub Check: e2e-tests
  • GitHub Check: lint
  • GitHub Check: security-scan
  • GitHub Check: unit-tests
  • GitHub Check: Analyze (javascript-typescript)
  • GitHub Check: Analyze (actions)
🔇 Additional comments (1)
website/app.js (1)

104-104: LGTM! Proper module registration.

The module is correctly registered following ApostropheCMS conventions and is appropriately placed near other form-related modules.

Comment thread website/utils/standardizeFieldNames.test.js
@github-actions

github-actions Bot commented Jun 9, 2025

Copy link
Copy Markdown

🔍 Vulnerabilities of apostrophe-cms:test

📦 Image Reference apostrophe-cms:test
digestsha256:768f5055e6e2e2f32aa18910cbe62efbab5486550bc23cd52a2d0669247b28c0
vulnerabilitiescritical: 0 high: 3 medium: 0 low: 0
platformlinux/amd64
size289 MB
packages971
📦 Base Image node:23-alpine
also known as
  • 23-alpine3.22
  • 23.11-alpine
  • 23.11-alpine3.22
  • 23.11.1-alpine
  • 23.11.1-alpine3.22
digestsha256:b9d38d589853406ff0d4364f21969840c3e0397087643aef8eede40edbb6c7cd
vulnerabilitiescritical: 0 high: 0 medium: 0 low: 0
critical: 0 high: 1 medium: 0 low: 0 async 0.9.2 (npm)

pkg:npm/async@0.9.2

high 7.8: CVE--2021--43138 OWASP Top Ten 2017 Category A9 - Using Components with Known Vulnerabilities

Affected range<2.6.4
Fixed version2.6.4, 3.2.2
CVSS Score7.8
CVSS VectorCVSS:3.1/AV:L/AC:L/PR:N/UI:R/S:U/C:H/I:H/A:H
EPSS Score1.061%
EPSS Percentile77th percentile
Description

A vulnerability exists in Async through 3.2.1 (fixed in 3.2.2), which could let a malicious user obtain privileges via the mapValues() method.

critical: 0 high: 1 medium: 0 low: 0 connect-multiparty 2.2.0 (npm)

pkg:npm/connect-multiparty@2.2.0

high 7.8: CVE--2022--29623 Unrestricted Upload of File with Dangerous Type

Affected range<=2.2.0
Fixed versionNot Fixed
CVSS Score7.8
CVSS VectorCVSS:3.1/AV:L/AC:L/PR:N/UI:R/S:U/C:H/I:H/A:H
EPSS Score0.334%
EPSS Percentile56th percentile
Description

An arbitrary file upload vulnerability in the file upload module of Express Connect-Multiparty 2.2.0 allows attackers to execute arbitrary code via a crafted PDF file. NOTE: the Supplier has not verified this vulnerability report.

critical: 0 high: 1 medium: 0 low: 0 async 1.5.2 (npm)

pkg:npm/async@1.5.2

high 7.8: CVE--2021--43138 OWASP Top Ten 2017 Category A9 - Using Components with Known Vulnerabilities

Affected range<2.6.4
Fixed version2.6.4, 3.2.2
CVSS Score7.8
CVSS VectorCVSS:3.1/AV:L/AC:L/PR:N/UI:R/S:U/C:H/I:H/A:H
EPSS Score1.061%
EPSS Percentile77th percentile
Description

A vulnerability exists in Async through 3.2.1 (fixed in 3.2.2), which could let a malicious user obtain privileges via the mapValues() method.

coderabbitai[bot]
coderabbitai Bot previously approved these changes Jun 9, 2025
coderabbitai[bot]
coderabbitai Bot previously approved these changes Jun 9, 2025
coderabbitai[bot]
coderabbitai Bot previously approved these changes Jun 9, 2025
@VitalyyP VitalyyP self-assigned this Jun 9, 2025
yuramax
yuramax previously approved these changes Jun 9, 2025

@yuramax yuramax left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM!

IhorMasechko
IhorMasechko previously approved these changes Jun 10, 2025

@IhorMasechko IhorMasechko left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

- Add instructions field to form module with field order guidance\n- Remove heading toolbar from form widget for consistency\n- Update form styles for instructions field

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 04e044f and 823184f.

📒 Files selected for processing (3)
  • website/modules/@apostrophecms/form-widget/index.js (1 hunks)
  • website/modules/@apostrophecms/form/index.js (1 hunks)
  • website/modules/asset/ui/src/scss/_form.scss (1 hunks)
✅ Files skipped from review due to trivial changes (2)
  • website/modules/asset/ui/src/scss/_form.scss
  • website/modules/@apostrophecms/form-widget/index.js
⏰ Context from checks skipped due to timeout of 90000ms (6)
  • GitHub Check: security-scan
  • GitHub Check: e2e-tests
  • GitHub Check: lint
  • GitHub Check: unit-tests
  • GitHub Check: Analyze (actions)
  • GitHub Check: Analyze (javascript-typescript)

Comment thread website/modules/@apostrophecms/form/index.js
@sonarqubecloud

Copy link
Copy Markdown

@Anton-88
Anton-88 requested review from IhorMasechko and yuramax June 10, 2025 10:42

@killev killev left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Well done

@Anton-88 Anton-88 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Great work!

@VitalyyP
VitalyyP merged commit c6ef756 into main Jun 10, 2025
@VitalyyP
VitalyyP deleted the 678-feature/add-form-field-standardizer branch June 10, 2025 11:50
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.

5 participants