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

make custom fields case sensitive #1242

Merged
merged 17 commits into from
Oct 18, 2024
Merged

make custom fields case sensitive #1242

merged 17 commits into from
Oct 18, 2024

Conversation

jwetzell
Copy link
Collaborator

@jwetzell jwetzell commented Oct 4, 2024

  • removes the lower casing of custom fields
  • doesn't allow duplicate custom fields from CustomFieldForm

@jwetzell jwetzell marked this pull request as draft October 4, 2024 13:59
Copy link
Contributor

coderabbitai bot commented Oct 4, 2024

Walkthrough

The pull request introduces updates to the CustomFieldForm component to incorporate a new useCustomFields hook for retrieving custom field data. This data is utilized to enforce uniqueness in the label input field during validation. Additionally, changes are made to the sanitiseCustomFields function in the parserFunctions.ts file, allowing for case-sensitive keys, alongside modifications to the corresponding test cases in parserFunctions.test.ts to reflect these updates.

Changes

File Change Summary
apps/client/src/features/app-settings/panel/feature-settings-panel/custom-fields/CustomFieldForm.tsx Added import for useCustomFields hook; updated validation logic for label input to enforce uniqueness.
apps/server/src/utils/tests/parserFunctions.test.ts Modified test cases for sanitiseCustomFields to change key test3 to Test3; expanded tests for parseRundown.
apps/server/src/utils/parserFunctions.ts Updated sanitiseCustomFields to derive key from field.label directly, allowing for case-sensitive keys.

Possibly related PRs

  • Merge import #1164: The changes in the main PR regarding the CustomFieldForm component's validation logic for the label input field may relate to the merging functionality discussed in PR Merge import #1164, as both involve handling project data and ensuring data integrity during user interactions.

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 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.

@jwetzell jwetzell changed the title custom field work make custom fields case sensitive Oct 9, 2024
@jwetzell jwetzell marked this pull request as ready for review October 9, 2024 01:17
@jwetzell jwetzell requested a review from cpvalente October 9, 2024 01:17
Copy link
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: 2

🧹 Outside diff range and nitpick comments (3)
apps/client/src/features/app-settings/panel/feature-settings-panel/custom-fields/CustomFieldForm.tsx (1)

23-24: LGTM: New hook used correctly. Consider adding a comment for clarity.

The useCustomFields hook is correctly used at the component's top level. To improve code readability, consider adding a brief comment explaining the purpose of this data:

// Fetch existing custom fields for uniqueness validation
const { data } = useCustomFields();

This addition would help other developers quickly understand the intent behind using this hook.

apps/server/src/utils/__tests__/parserFunctions.test.ts (2)

Line range hint 356-461: Good addition of event linking test cases, consider adding custom fields test

The new test cases for parseRundown() linking are valuable additions that improve the overall test coverage. However, to align more closely with the PR objectives:

Consider adding a test case that includes custom fields with varying case to ensure that their case sensitivity is preserved during rundown parsing. This would help validate that the changes to custom field handling are correctly reflected in the parsed rundown.


Line range hint 1-461: Overall, changes align well with PR objectives, with room for minor improvements

The updates to the test cases for sanitiseCustomFields correctly reflect the new case-sensitive behavior of custom fields, which is the primary objective of this PR. The preservation of case in keys and labels is now properly tested, ensuring that the implementation maintains this behavior.

The addition of new test cases for event linking in parseRundown(), while not directly related to the custom fields objective, improves the overall test coverage and is a positive change.

To further strengthen the alignment with the PR objectives, consider:

  1. Adding a test case in parseRundown() that includes custom fields with varying case to ensure their case sensitivity is preserved during rundown parsing.
  2. Reviewing other parts of the codebase where custom fields are used to ensure consistent case-sensitive handling.
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 86e6f8b and 3e11085.

📒 Files selected for processing (3)
  • apps/client/src/features/app-settings/panel/feature-settings-panel/custom-fields/CustomFieldForm.tsx (3 hunks)
  • apps/server/src/utils/tests/parserFunctions.test.ts (3 hunks)
  • apps/server/src/utils/parserFunctions.ts (1 hunks)
🧰 Additional context used
🔇 Additional comments (7)
apps/client/src/features/app-settings/panel/feature-settings-panel/custom-fields/CustomFieldForm.tsx (2)

9-9: LGTM: New hook import added correctly.

The useCustomFields hook has been imported properly, maintaining consistency with other imports in the file. This addition aligns with the PR objective of modifying custom fields handling.


Line range hint 1-108: Overall implementation is solid, with one minor adjustment needed.

The changes successfully implement the PR objectives of making custom fields unique and introducing case sensitivity. The new useCustomFields hook is correctly imported and used, and the validation logic has been updated to check for uniqueness.

However, there's one minor adjustment needed in the uniqueness check to ensure proper case sensitivity handling. Once this is addressed, the implementation will fully meet the PR objectives.

Great job on the implementation! The code is clean, well-structured, and achieves the intended goals with minimal changes.

apps/server/src/utils/parserFunctions.ts (2)

313-313: LGTM: Case-sensitive custom fields implemented.

The change to use field.label directly as the key for newCustomFields successfully implements case-sensitive custom fields, aligning with the PR objective.


Line range hint 313-336: Verify impact on case-sensitive changes.

The switch to case-sensitive custom fields might affect other parts of the application that rely on case-insensitive lookups.

Please run the following script to identify potential areas that might be affected:

This script will help identify areas in the codebase where custom fields are accessed, iterated, or compared. Review these areas to ensure they handle the new case-sensitive behavior correctly.

✅ Verification successful

Impact on case-sensitive changes is verified and no issues were found.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Search for usage of custom fields in the codebase

# Test: Look for places where custom fields are accessed
echo "Searching for custom field access patterns:"
rg --type typescript --type javascript 'customFields\[.*\]' -g '!*test*'

# Test: Look for places where custom fields are iterated
echo "\nSearching for custom field iteration patterns:"
rg --type typescript --type javascript 'Object\.keys\(.*customFields.*\)' -g '!*test*'

# Test: Look for places where custom fields are compared
echo "\nSearching for custom field comparison patterns:"
rg --type typescript --type javascript '(===|!==|==|!=).*customFields\[.*\]' -g '!*test*'

Length of output: 673


Script:

#!/bin/bash
# Description: Search for usage of custom fields in the codebase with corrected file types

# Test: Look for places where custom fields are accessed
echo "Searching for custom field access patterns:"
rg --type js --type jsx --type ts --type tsx 'customFields\[.*\]' -g '!*test*'

# Test: Look for places where custom fields are iterated
echo "\nSearching for custom field iteration patterns:"
rg --type js --type jsx --type ts --type tsx 'Object\.keys\(.*customFields.*\)' -g '!*test*'

# Test: Look for places where custom fields are compared
echo "\nSearching for custom field comparison patterns:"
rg --type js --type jsx --type ts --type tsx '(===|!==|==|!=).*customFields\[.*\]' -g '!*test*'

Length of output: 670


Script:

#!/bin/bash
# Description: Search for usage of custom fields in the codebase using file extension patterns

# Test: Look for places where custom fields are accessed
echo "Searching for custom field access patterns:"
rg 'customFields\[.*\]' --glob '*.js' --glob '*.jsx' --glob '*.ts' --glob '*.tsx' -g '!*test*'

# Test: Look for places where custom fields are iterated
echo "\nSearching for custom field iteration patterns:"
rg 'Object\.keys\(.*customFields.*\)' --glob '*.js' --glob '*.jsx' --glob '*.ts' --glob '*.tsx' -g '!*test*'

# Test: Look for places where custom fields are compared
echo "\nSearching for custom field comparison patterns:"
rg '(===|!==|==|!=).*customFields\[.*\]' --glob '*.js' --glob '*.jsx' --glob '*.ts' --glob '*.tsx' -g '!*test*'

Length of output: 2109

apps/server/src/utils/__tests__/parserFunctions.test.ts (3)

282-282: LGTM: Case sensitivity preserved for custom field keys

This change correctly tests the new case-sensitive behavior of custom fields, aligning with the PR objective.


334-334: LGTM: Case-sensitive key preservation in name cohesion test

This change correctly updates the expected behavior to preserve the case of the custom field label when used as a key, which is in line with the PR objectives.


345-345: LGTM: Case sensitivity preserved in invalid entries filtering test

These changes correctly update the test case to include and expect a capitalized custom field key, ensuring that the case sensitivity is maintained when filtering invalid entries.

Also applies to: 350-350

Comment on lines 81 to 83
if (Object.keys(data).includes(value)) return 'Custom fields must be unique';
return true;
},
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Approve validation addition, but case sensitivity needs adjustment.

The new validation rule correctly implements a uniqueness check for custom fields, which aligns with the PR objective. However, the current implementation using Object.keys(data).includes(value) might not be case-sensitive.

To ensure case sensitivity, consider modifying the check as follows:

if (Object.keys(data).some(key => key.toLowerCase() === value.toLowerCase())) {
  return 'Custom fields must be unique (case-insensitive)';
}

This change will make the uniqueness check case-insensitive, preventing fields like "Field" and "field" from coexisting, which seems to be the intended behavior based on the PR objectives.

Comment on lines 313 to 328
const key = field.label;
if (key in newCustomFields) {
continue;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Consider case-insensitive uniqueness check.

While the current implementation allows for case-sensitive custom fields, it might lead to confusion if two fields differ only in case (e.g., "Name" and "name"). Consider implementing a case-insensitive uniqueness check to prevent this scenario.

Here's a suggested modification:

-    const key = field.label;
-    if (key in newCustomFields) {
+    const key = field.label;
+    if (Object.keys(newCustomFields).some(k => k.toLowerCase() === key.toLowerCase())) {
       continue;
     }

This change ensures that custom fields are unique regardless of case while still preserving the original case in the stored data.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const key = field.label;
if (key in newCustomFields) {
continue;
}
const key = field.label;
if (Object.keys(newCustomFields).some(k => k.toLowerCase() === key.toLowerCase())) {
continue;
}

@cpvalente
Copy link
Owner

Thank you for this, the code looks good.
@alex-Arc , could you please sanity check the implications for the APIs and integrations?

@alex-Arc alex-Arc force-pushed the custom-fields-formatting branch from e456883 to 983d89b Compare October 17, 2024 12:41
@alex-Arc alex-Arc force-pushed the custom-fields-formatting branch from 983d89b to 7e2e158 Compare October 17, 2024 13:44
@alex-Arc alex-Arc merged commit c587045 into master Oct 18, 2024
4 checks passed
@alex-Arc alex-Arc deleted the custom-fields-formatting branch October 18, 2024 16:53
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.

3 participants