sartography / spiff-arena

SpiffWorkflow is a software development platform for building, running, and monitoring executable diagrams
https://www.spiffworkflow.org/
GNU Lesser General Public License v2.1
44 stars 34 forks source link

do not invalidate a numeric range field if it is unset and not required #1478

Closed jasquat closed 2 weeks ago

jasquat commented 2 weeks ago

Addresses https://github.com/sartography/spiff-arena/issues/647#issuecomment-2089568978

This adds in some conditionals so the numeric range field is not invalidated when it is unset and not required. It also cleans up the conditionals a bit and allows for text to be set in the state. Before the text would go away on reload which seemed confusing to me so set the state and let it run through validations on submit seems more intuitive to me.

coderabbitai[bot] commented 2 weeks ago
Walkthrough ## Walkthrough The recent updates primarily focus on enhancing form validation and error handling in two components. In `CustomForm.tsx`, the validation logic for minimum and maximum values has been refined, alongside improvements in error messages. `NumericRangeField.tsx` introduces a new validation step in the `parseNumberString` function to ensure the input matches a specific numeric format before processing. ## Changes | File Path | Change Summary | |-----------|----------------| | `.../CustomForm.tsx` | Refactored validation for `min` and `max` values; improved error handling and messages; added `_uiSchemaPassedIn` parameter. | | `.../NumericRangeField/NumericRangeField.tsx` | Added a conditional check in `parseNumberString` to validate the format of the input string using `matchNumberRegex`. |

Recent Review Details **Configuration used: .coderabbit.yaml** **Review profile: CHILL**
Commits Files that changed from the base of the PR and between d463cba4c5bdd251f761fa4b9a52d454bd6034f2 and 63d944edffef301a79b2eca8c71cf1b9c98d54a5.
Files selected for processing (2) * spiffworkflow-frontend/src/components/CustomForm.tsx (2 hunks) * spiffworkflow-frontend/src/rjsf/custom_widgets/NumericRangeField/NumericRangeField.tsx (1 hunks)
Additional comments not posted (1)
spiffworkflow-frontend/src/rjsf/custom_widgets/NumericRangeField/NumericRangeField.tsx (1)
`86-88`: Ensure the regex `matchNumberRegex` is robust enough for number validation.
Verification successful --- The regex pattern `matchNumberRegex` used in the `parseNumberString` function is defined as `/^[0-9,.-]*$/`. This pattern matches any string composed entirely of the characters 0-9, comma, period, and hyphen. It allows for an empty string as well due to the `*` quantifier, which matches zero or more of the preceding element. ### Analysis of the Regex Pattern: 1. **Numeric Characters**: It correctly includes all numeric characters (0-9). 2. **Decimal and Negative Values**: The inclusion of the period (`.`) and hyphen (`-`) allows for the representation of decimal and negative numbers, respectively. 3. **Commas**: The inclusion of commas supports number formatting in some locales, which use commas as thousand separators. 4. **Potential Issues**: - The regex does not enforce the correct placement of commas, periods, or hyphens. For example, it would incorrectly validate strings like `12.34.56`, `--123`, or `1,2,3,4`. - It allows multiple commas, periods, and hyphens anywhere in the string, which might not be intended. Given this analysis, while the regex does allow a broad range of numeric representations, it might not strictly enforce the correct format of numbers, especially concerning the placement and repetition of special characters like the decimal point and hyphen. This could lead to potential issues with data validation if strict number formatting is required. ### Conclusion: The regex `matchNumberRegex` provides a basic level of numeric validation but lacks precision in enforcing correct numeric formats. Depending on the application's requirements for number input validation, this might or might not be sufficient. If strict validation is necessary, the regex should be refined to enforce correct placements of commas, periods, and hyphens. - **Recommendation**: Review the requirements for number validation in the application and consider refining the regex if stricter validation is needed.
Scripts Executed The following scripts were executed for the analysis: --- Script: ```shell #!/bin/bash # Description: Verify the robustness of `matchNumberRegex` used in `parseNumberString` function. # Find the definition of `matchNumberRegex` and display its pattern. rg --files-with-matches --type typescript $'export const matchNumberRegex =' | xargs cat ``` Length of output: 124 --- --- Script: ```shell #!/bin/bash # Description: Verify the robustness of `matchNumberRegex` used in `parseNumberString` function. # Correcting the file type specification to search within TypeScript files. rg --files-with-matches 'export const matchNumberRegex =' *.ts* | xargs cat ``` Length of output: 125 --- --- Script: ```shell #!/bin/bash # Description: Verify the robustness of `matchNumberRegex` used in `parseNumberString` function. # Adjusting the script to search recursively without specifying file patterns incorrectly. rg --files-with-matches 'export const matchNumberRegex =' --glob '*.ts*' | xargs cat ``` Length of output: 9621
--- 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 - [X](https://twitter.com/intent/tweet?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A&url=https%3A//coderabbit.ai) - [Mastodon](https://mastodon.social/share?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A%20https%3A%2F%2Fcoderabbit.ai) - [Reddit](https://www.reddit.com/submit?title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&text=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code.%20Check%20it%20out%3A%20https%3A//coderabbit.ai) - [LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fcoderabbit.ai&mini=true&title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&summary=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code)
Tips ### Chat There are 3 ways to chat with [CodeRabbit](https://coderabbit.ai): - Review comments: Directly reply to a review comment made by CodeRabbit. Example: - `I pushed a fix in commit .` - `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.` 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 a review. This is useful when automatic reviews are disabled for the repository. - `@coderabbitai resolve` resolve all the CodeRabbit review comments. - `@coderabbitai help` to get help. Additionally, you can add `@coderabbitai ignore` anywhere in the PR description to prevent this PR from being reviewed. ### CodeRabbit Configration 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](https://docs.coderabbit.ai/guides/configure-coderabbit) 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](https://coderabbit.ai/docs) for detailed information on how to use CodeRabbit. - Join our [Discord Community](https://discord.com/invite/GsXnASn26c) to get help, request features, and share feedback. - Follow us on [X/Twitter](https://twitter.com/coderabbitai) for updates and announcements.