Skip to content

Do not add a new option to conditional logic if renaming an option#1894

Merged
Crabcyborg merged 5 commits into
masterfrom
issue-2909-fix_conditional_logic_options_issue_when_renaming_option
Aug 6, 2024
Merged

Do not add a new option to conditional logic if renaming an option#1894
Crabcyborg merged 5 commits into
masterfrom
issue-2909-fix_conditional_logic_options_issue_when_renaming_option

Conversation

@AbdiTolesa
Copy link
Copy Markdown
Contributor

@AbdiTolesa AbdiTolesa commented Aug 1, 2024

Fix https://github.com/Strategy11/formidable-pro/issues/2909

Test steps

  1. Create a Product field with some product options.
  2. Add another field that conditionally shows based off the product field's value and save.
  3. Go the the Product field and rename an option.
  4. Go back to the conditional field and confirm that there is no new option added in the conditional logic row. The existing options should have been renamed instead.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Aug 1, 2024

Walkthrough

The changes in the frmAdminBuildJS function enhance the management of option elements in a select input by first checking for existing input values before adding new options. This is achieved through a newly introduced helper function, prependValueSelectWithOptionMatch, which streamlines option creation and improves code clarity and maintainability.

Changes

Files Change Summary
js/formidable_admin.js Enhanced frmAdminBuildJS to check for existing input values before creating new options. Introduced helper function prependValueSelectWithOptionMatch for improved option management.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant InputField
    participant SelectElement
    participant HelperFunction

    User->>InputField: Enter value
    InputField->>frmAdminBuildJS: Trigger check for options
    frmAdminBuildJS->>InputField: Retrieve input value
    frmAdminBuildJS->>SelectElement: Check for existing option
    alt Option exists
        SelectElement->>User: Display existing option
    else Option does not exist
        frmAdminBuildJS->>HelperFunction: Call to prepend new option
        HelperFunction->>SelectElement: Create and prepend new option
    end
Loading

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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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 as 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 resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

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.

Copy link
Copy Markdown
Contributor

@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

Outside diff range, codebase verification and nitpick comments (2)
js/formidable_admin.js (2)

5650-5658: Ensure the function is well-documented and follows best practices.

The function prependValueSelectWithOptionMatch is correctly implemented, but consider adding a comment to explain its purpose and usage.

+  /**
+   * Prepends an option to the valueSelect element if optionMatch is null.
+   * @param {HTMLElement} valueSelect - The select element to prepend the option to.
+   * @param {HTMLElement|null} optionMatch - The option element to prepend, or null to create a new one.
+   * @param {string} expectedOption - The value of the option to prepend.
+   */
  function prependValueSelectWithOptionMatch( valueSelect, optionMatch, expectedOption ) {

5631-5632: Use let instead of const for expectedOption and optionMatch due to reassignment.

The variables expectedOption and optionMatch are reassigned in several places, so using const is inappropriate. Please change these to let.

  • expectedOption reassigned on line 5631.
  • optionMatch reassigned on lines 5632, 5635, and 5637.
Analysis chain

Ensure consistent use of const and let.

Using const for variables that are not reassigned is a good practice. Ensure that expectedOption and optionMatch are not reassigned elsewhere in the code.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of `expectedOption` and `optionMatch` to ensure they are not reassigned.

# Test: Search for variable assignments. Expect: No reassignment of `expectedOption` and `optionMatch`.
rg --type js -A 5 $'expectedOption\s*='
rg --type js -A 5 $'optionMatch\s*='

Length of output: 1920

Copy link
Copy Markdown
Contributor

@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: 1

Comment thread js/formidable_admin.js
@AbdiTolesa AbdiTolesa requested a review from garretlaxton August 2, 2024 13:45
Copy link
Copy Markdown

@garretlaxton garretlaxton left a comment

Choose a reason for hiding this comment

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

This fix works great!

@AbdiTolesa AbdiTolesa requested a review from truongwp August 4, 2024 17:07
Comment thread js/formidable_admin.js Outdated
Comment thread js/formidable_admin.js Outdated
@AbdiTolesa AbdiTolesa requested a review from truongwp August 5, 2024 16:19
Copy link
Copy Markdown
Contributor

@truongwp truongwp left a comment

Choose a reason for hiding this comment

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

This looks good. Thanks @AbdiTolesa!

@truongwp truongwp requested a review from Crabcyborg August 6, 2024 07:00
Comment thread js/formidable_admin.js Outdated
Comment thread js/formidable_admin.js Outdated
@Crabcyborg Crabcyborg added this to the 6.12 milestone Aug 6, 2024
Copy link
Copy Markdown
Contributor

@Crabcyborg Crabcyborg left a comment

Choose a reason for hiding this comment

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

I made some small tweaks to fix the issues I commented on.

I just tested this and it looks like it solves the issue.

Thanks @AbdiTolesa @truongwp and @garretlaxton for working on this!

🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants