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

[Nu-1889] provide an unique validation message to the scenario labels #7182

Conversation

Dzuming
Copy link
Contributor

@Dzuming Dzuming commented Nov 20, 2024

Describe your changes

image

Checklist before merge

  • Related issue ID is placed at the beginning of PR title in [brackets] (can be GH issue or Nu Jira issue)
  • Code is cleaned from temporary changes and commented out lines
  • Parts of the code that are not easy to understand are documented in the code
  • Changes are covered by automated tests
  • Showcase in dev-application.conf added to demonstrate the feature
  • Documentation added or updated
  • Added entry in Changelog.md describing the change from the perspective of a public distribution user
  • Added MigrationGuide.md entry in the appropriate subcategory if introducing a breaking change
  • Verify that PR will be squashed during merge

Summary by CodeRabbit

Release Notes

  • New Features

    • Enhanced validation for scenario labels, ensuring uniqueness and appropriate error messaging for duplicate or excessively long labels.
    • Introduction of a new Activities panel for better organization of scenario activities.
    • New scenario labels feature to improve scenario management and retrieval.
  • Bug Fixes

    • Improved error handling and user feedback for label input validation.
  • Documentation

    • Updated changelog to reflect new features, improvements, and breaking changes in version 1.18.

Copy link

coderabbitai bot commented Nov 20, 2024

📝 Walkthrough
📝 Walkthrough

Walkthrough

This pull request introduces enhancements to the label input validation in the Cypress end-to-end tests and the ScenarioLabels component. It includes new validation checks for duplicate and excessively long labels, improving user feedback in the testing framework. Additionally, the ScenarioLabels component has been updated with new functions for label uniqueness validation and performance optimizations. The changelog has also been updated to document these changes and other enhancements in version 1.18.

Changes

File Path Change Summary
designer/client/cypress/e2e/labels.cy.ts Added validation checks for duplicate and long labels in Cypress tests; verified error messages.
designer/client/src/components/toolbars/scenarioDetails/ScenarioLabels.tsx Introduced labelUniqueValidation function; refactored isInputInSelectedOptions for performance; updated validateInput for label uniqueness validation.
docs/Changelog.md Updated to reflect new features, improvements, and breaking changes in version 1.18, including new methods and enhancements.

Possibly related PRs

  • Assign user friendly editor fix #7166: The changes in this PR enhance the validation logic for label inputs, which is closely related to the validation checks introduced in the main PR for ensuring label uniqueness and handling errors in the ScenarioLabels component.

Suggested reviewers

  • arkadius

🐰 In the meadow where we play,
New labels bloom, bright as the day.
Unique and long, they must be right,
With tests that catch them in their flight.
Hooray for changes, let’s all cheer,
For better labels, bring us near! 🌼


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.

@github-actions github-actions bot added client client main fe ui labels Nov 20, 2024
@Dzuming Dzuming changed the title [Nu-1889] provide an unique validation message to the scenario label [Nu-1889] provide an unique validation message to the scenario labels Nov 20, 2024
@github-actions github-actions bot added the docs label Nov 20, 2024
Copy link

@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 and nitpick comments (4)
designer/client/cypress/e2e/labels.cy.ts (3)

36-42: LGTM! Consider adding a wait after clearing input

The test correctly validates the duplicate label error scenario. However, for improved test reliability, consider adding a small wait after clearing the input field to ensure the UI has fully updated before proceeding with the next action.

 cy.get("@labelInput").find("input").clear();
+cy.wait(100); // Add a small wait to ensure UI update

Line range hint 1-1: Consider adding tests for additional validation scenarios

The test suite could be enhanced by adding the following test cases:

  1. Maximum allowed label length validation
  2. Special characters in labels validation
  3. Empty label validation

This would provide more comprehensive coverage of the validation logic.


40-40: Consider extracting error messages as constants

For better maintainability and consistency, consider extracting the error message strings into constants at the top of the file:

const ERROR_MESSAGES = {
  DUPLICATE_LABEL: "This label already exists. Please enter a unique value.",
  INVALID_LABEL: "Incorrect value 'very long tag'"
};
designer/client/src/components/toolbars/scenarioDetails/ScenarioLabels.tsx (1)

29-30: Consider using i18n for the error message

The error message should be internationalized using i18next to maintain consistency with other messages in the codebase.

-const labelUniqueValidation = (label: string) => ({ label, messages: ["This label already exists. Please enter a unique value."] });
+const labelUniqueValidation = (label: string) => ({ 
+    label, 
+    messages: [i18next.t("panels.scenarioDetails.labels.duplicateLabel", "This label already exists. Please enter a unique value.")] 
+});
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 3aa124d and c4419e7.

📒 Files selected for processing (3)
  • designer/client/cypress/e2e/labels.cy.ts (1 hunks)
  • designer/client/src/components/toolbars/scenarioDetails/ScenarioLabels.tsx (3 hunks)
  • docs/Changelog.md (1 hunks)
🔇 Additional comments (4)
designer/client/src/components/toolbars/scenarioDetails/ScenarioLabels.tsx (2)

130-135: LGTM! Good performance optimization

The useCallback implementation is correct and will prevent unnecessary re-renders by memoizing the function. The dependency array is properly configured with scenarioLabelOptions.


159-162: Consider handling potential race condition in validation

There's a potential race condition between the HTTP validation and uniqueness check. The uniqueness validation could overwrite error states from the HTTP validation that arrives later due to the async nature of the calls.

Consider this approach to preserve both validation results:

-if (isInputInSelectedOptions(newInput)) {
-    setInputErrors((prevState) => [...prevState, labelUniqueValidation(newInput)]);
-}
+if (isInputInSelectedOptions(newInput)) {
+    setInputErrors((prevState) => {
+        const uniqueError = labelUniqueValidation(newInput);
+        return prevState.some(error => error.label === uniqueError.label) 
+            ? prevState 
+            : [...prevState, uniqueError];
+    });
+}
docs/Changelog.md (2)

103-103: LGTM! The changelog entry is well-formatted and clear.

The entry follows the established changelog conventions and accurately describes the PR's purpose of providing unique validation messages for scenario labels.


103-103: Entry is consistent with PR objectives.

The changelog entry accurately reflects the PR's goal of implementing unique validation messages for scenario labels, and is placed in the correct version section.

@Dzuming Dzuming requested a review from mateuszkp96 November 20, 2024 14:02
…-validation-message-to-the-scenario-label

# Conflicts:
#	docs/Changelog.md
Copy link

@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 and nitpick comments (1)
designer/client/src/components/toolbars/scenarioDetails/ScenarioLabels.tsx (1)

29-34: LGTM! Consider adding type safety.

The validation message implementation looks good and correctly uses i18next for translations as requested.

Consider adding type safety by explicitly declaring the return type:

-const labelUniqueValidation = (label: string) => ({
+const labelUniqueValidation = (label: string): ScenarioLabelValidationError => ({
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between c4419e7 and c774966.

📒 Files selected for processing (2)
  • designer/client/src/components/toolbars/scenarioDetails/ScenarioLabels.tsx (3 hunks)
  • docs/Changelog.md (1 hunks)
🔇 Additional comments (3)
designer/client/src/components/toolbars/scenarioDetails/ScenarioLabels.tsx (2)

135-140: LGTM! Good performance optimization.

The refactoring to useCallback is appropriate here since this function is used in other hooks' dependencies. The implementation correctly checks for duplicate labels.


164-167: 🛠️ Refactor suggestion

Consider handling potential race condition in validation.

While the duplicate check implementation is correct, there's a potential race condition between the HTTP validation response and the duplicate check. The duplicate validation might overwrite validation errors from the HTTP response if they arrive in a different order.

Consider this sequence:

  1. User types "label1"
  2. HTTP validation starts
  3. Duplicate check runs and sets errors
  4. HTTP validation completes and overwrites errors

To verify this behavior, we can check for similar patterns in the codebase:

Consider combining all validations:

 return debounce(async (newInput: string) => {
     if (newInput !== "") {
         const response = await HttpService.validateScenarioLabels([newInput]);
+        const validationErrors = [...response.data.validationErrors];
+        
+        if (isInputInSelectedOptions(newInput)) {
+            validationErrors.push(labelUniqueValidation(newInput));
+        }
 
-        if (response.status === 200) {
-            setInputErrors(response.data.validationErrors);
-        }
+        setInputErrors(validationErrors);
     }
-
-    if (isInputInSelectedOptions(newInput)) {
-        setInputErrors((prevState) => [...prevState, labelUniqueValidation(newInput)]);
-    }

     setInputTyping(false);
 }, 500);
docs/Changelog.md (1)

103-103: LGTM! Changelog entry is properly formatted and consistent with PR objectives.

The changelog entry accurately describes the PR's purpose of providing unique validation messages for scenario labels, and is correctly placed in the unreleased 1.18 section.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
client client main fe docs ui
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants