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

toast being changed #1733

Merged
merged 2 commits into from
Nov 5, 2024
Merged

toast being changed #1733

merged 2 commits into from
Nov 5, 2024

Conversation

abishekTa-egov
Copy link
Contributor

@abishekTa-egov abishekTa-egov commented Nov 5, 2024

Toast for formula and assumptions kept different

Summary by CodeRabbit

  • New Features

    • Improved user interface for formula and assumption management.
    • Enhanced clarity in deletion confirmation messages with context-specific labeling.
  • Bug Fixes

    • Refined logic for tracking deleted formulas and maintaining order in the formula list.
    • Adjusted handling of checkbox states and dropdown options for accurate UI representation.

@abishekTa-egov abishekTa-egov requested a review from a team as a code owner November 5, 2024 05:09
Copy link
Contributor

coderabbitai bot commented Nov 5, 2024

📝 Walkthrough

Walkthrough

The changes in this pull request involve updates to the user interface and logic in the FormulaConfiguration.js and Hypothesis.js components. Key modifications include enhanced handling of formula deletions, improved confirmation messages, and refined logic for adding new formulas. The updates ensure that deleted formulas are tracked effectively, and the user interface reflects the current state of formulas and assumptions more accurately.

Changes

File Path Change Summary
health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/components/FormulaConfiguration.js Updated handleConfirmDelete for cascading effects on formula deletion, refined logic for managing deleted formulas, and improved dropdown rendering. Enhanced pop-up messages for clarity.
health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/components/Hypothesis.js Modified confirmation pop-up messages for deletion and addition of assumptions, maintaining existing logic for managing assumptions.

Possibly related PRs

Suggested reviewers

  • nipunarora-eGov
  • nabeelmd-eGov

🐰 In the meadow where formulas play,
New logic hops in, brightening the day.
With clearer messages, we now can see,
Deletions and additions, as smooth as can be!
So let’s celebrate, with a joyful cheer,
For our formulas dance, with no hint of fear! 🎉


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.

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: 0

🧹 Outside diff range comments (3)
health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/components/HypothesisWrapper.js (1)

Line range hint 233-233: Inconsistent error message label.

The error message label at line 233 still uses t("ERR_MANDATORY_FIELD") while the same validation at line 107 uses t("HYP_ERR_MANDATORY_FIELD"). This inconsistency should be fixed to maintain a uniform user experience.

Apply this diff to fix the inconsistency:

-                    label: t("ERR_MANDATORY_FIELD"),
+                    label: t("HYP_ERR_MANDATORY_FIELD"),
health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/components/FormulaConfigWrapper.js (2)

Line range hint 259-263: Update toast message for consistency.

The error message here still uses ERR_MANDATORY_FIELD while a similar validation in handleNext() uses FOR_ERR_MANDATORY_FIELD. This should be updated for consistency.

Apply this diff:

          setShowToast({
            key: "error",
-           label: t("ERR_MANDATORY_FIELD"),
+           label: t("FOR_ERR_MANDATORY_FIELD"),
            transitionTime: 3000,
          });

Line range hint 142-270: Consider extracting validation logic to reduce duplication.

The validation logic for mandatory fields is duplicated between handleNext() and handleStepClick(). Consider extracting this into a shared function to improve maintainability and ensure consistent validation.

Example refactor:

+ const validateMandatoryFields = (currentRuleConfigurations) => {
+   const existingFormulaOutputs = formulaConfigValues?.map((formula) => formula.output);
+   const visibleFormulas = currentRuleConfigurations.filter(
+     (item) => existingFormulaOutputs?.includes(item.output) && !deletedFormulas?.includes(item.output)
+   );
+   
+   return !visibleFormulas.some((item) => {
+     const formulaConfig = formulaConfigValues.find((formula) => formula.output === item.output);
+     return !formulaConfig || !formulaConfig.input || !formulaConfig.operatorName || !formulaConfig.assumptionValue;
+   });
+ };

  const handleNext = () => {
-   if (formulaConfigValues.filter(row => row.category === currentCategory).every(row => {
-     return row.assumptionValue && row.input && row.output && row.operatorName
-   })) {
+   if (validateMandatoryFields(currentCategoryRuleConfigurations)) {
      // ... rest of the code
    } else {
      setShowToast({
        key: "error",
        label: t("FOR_ERR_MANDATORY_FIELD"),
        transitionTime: 3000,
      });
      return;
    }
    // ... rest of the code
  };

  const handleStepClick = (step) => {
    const currentStepIndex = formulaInternalKey - 1;
    if (step === currentStepIndex + 1) {
      const currentRuleConfigurations = ruleConfigurationCategories[currentStepIndex]?.ruleConfigurations || [];
-     const existingFormulaOutputs = formulaConfigValues?.map((formula) => formula.output);
-     const visibleFormulas = currentRuleConfigurations?.filter(
-       (item) => existingFormulaOutputs?.includes(item.output) && !deletedFormulas?.includes(item.output)
-     );
-     const hasEmptyFields = visibleFormulas.some((item) => {
-       const formulaConfig = formulaConfigValues.find((formula) => formula.output === item.output);
-       return !formulaConfig || !formulaConfig.input || !formulaConfig.operatorName || !formulaConfig.assumptionValue;
-     });
-     if (hasEmptyFields) {
+     if (!validateMandatoryFields(currentRuleConfigurations)) {
        setShowToast({
          key: "error",
          label: t("FOR_ERR_MANDATORY_FIELD"),
          transitionTime: 3000,
        });
        return;
      }
      // ... rest of the code
    }
    // ... rest of the code
  };
📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE

📥 Commits

Reviewing files that changed from the base of the PR and between a527d4b and 2a469ca.

📒 Files selected for processing (2)
  • health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/components/FormulaConfigWrapper.js (1 hunks)
  • health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/components/HypothesisWrapper.js (1 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/components/FormulaConfigWrapper.js (1)

Pattern **/*.js: check

health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/components/HypothesisWrapper.js (1)

Pattern **/*.js: check

🔇 Additional comments (2)
health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/components/HypothesisWrapper.js (1)

107-107: LGTM: Toast message differentiation implemented.

The change aligns with the PR objective of differentiating toast notifications for hypotheses by using the "HYP_" prefix.

health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/components/FormulaConfigWrapper.js (1)

149-149: LGTM! Toast message differentiation implemented correctly.

The change from ERR_MANDATORY_FIELD to FOR_ERR_MANDATORY_FIELD aligns with the PR objective of differentiating toast notifications for formulas.

Let's verify the translation key exists and is consistent:

coderabbitai[bot]
coderabbitai bot previously approved these changes Nov 5, 2024
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 comments (4)
health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/components/Hypothesis.js (1)

Line range hint 47-55: Consider using a more specific error message for assumption deletion.

While the current error handling is good, the message "ERR_ATLEAST_ONE_MANDATORY_FIELD" could be more specific to the assumption context.

Consider creating a new translation key specific to assumptions:

 setShowToast({
   key: "error",
-  label: t("ERR_ATLEAST_ONE_MANDATORY_FIELD"),
+  label: t("ERR_ATLEAST_ONE_ASSUMPTION_REQUIRED"),
   transitionTime: 3000,
 });
🧰 Tools
🪛 Biome

[error] 173-208: JSX elements without children should be marked as self-closing. In JSX, it is valid for any element to be self-closing.

Unsafe fix: Use a SelfClosingElement instead

(lint/style/useSelfClosingElements)


[error] 178-178: Avoid passing children using a prop

The canonical way to pass children in React is to use JSX elements

(lint/correctness/noChildrenProp)


[error] 179-179: Missing key property for this element in iterable.

The order of the items may change, and having a key can help React identify which item was moved.
Check the React documentation.

(lint/correctness/useJsxKeyInIterable)

health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/components/FormulaConfiguration.js (3)

Line range hint 39-107: Consider improving state management in deletion logic

The current implementation of handleConfirmDelete has several areas that could be improved:

  1. Multiple state updates could lead to race conditions
  2. Complex nested state updates make the code harder to maintain
  3. Missing error handling for state updates

Consider refactoring the deletion logic using a more functional approach:

 const handleConfirmDelete = () => {
   if (formulaToDelete !== null) {
-    const deletedFormula = formulas.find(operation => operation.output === formulaToDelete.output)
+    try {
+      const deletedFormula = formulas.find(operation => operation.output === formulaToDelete.output);
+      
+      // Batch all state updates
+      const updatedState = {
+        formulas: formulas.filter(operation => operation.output !== formulaToDelete.output),
+        deletedCategories: {
+          ...deletedFormulaCategories.current,
+          [category]: [...(deletedFormulaCategories.current[category] || []), deletedFormula.output]
+        },
+        formulaConfigValues: formulaConfigValues.map(formula => ({
+          ...formula,
+          input: formula.input === deletedFormula.output ? "" : formula.input,
+          assumptionValue: formula.assumptionValue === deletedFormula.output ? "" : formula.assumptionValue
+        }))
+      };
 
-    //matching output for deleting a formula
-    const updatedFormulas = formulas.filter(operation => {
-      if (operation.output === formulaToDelete.output) {
-        return false
-      }
-      return true
-    })
+      // Update all states at once
+      setFormulas(updatedState.formulas);
+      deletedFormulaCategories.current = updatedState.deletedCategories;
+      setDeletedFormulas(prev => [...prev, deletedFormula.output]);
+      setFormulaConfigValues(updatedState.formulaConfigValues);
+    } catch (error) {
+      setShowToast({
+        key: "error",
+        label: t("ERR_FORMULA_DELETE_FAILED"),
+        transitionTime: 3000,
+      });
+    }
+    setFormulaToDelete(null);
+    setShowPopUp(false);
   }
 };
🧰 Tools
🪛 Biome

[error] 331-360: JSX elements without children should be marked as self-closing. In JSX, it is valid for any element to be self-closing.

Unsafe fix: Use a SelfClosingElement instead

(lint/style/useSelfClosingElements)


[error] 336-336: Avoid passing children using a prop

The canonical way to pass children in React is to use JSX elements

(lint/correctness/noChildrenProp)


[error] 337-337: Missing key property for this element in iterable.

The order of the items may change, and having a key can help React identify which item was moved.
Check the React documentation.

(lint/correctness/useJsxKeyInIterable)


Line range hint 108-196: Clean up commented code and improve formula addition logic

  1. Remove commented-out code blocks as they add noise
  2. The formula ordering logic is complex and could be simplified
  3. Consider adding validation for duplicate formulas

Consider this cleaner implementation:

 const addNewFormula = () => {
   if (!selectedDeletedFormula) return;
   
   const formulaToAdd = selectedDeletedFormula.code;
   
+  // Early validation
+  if (formulas.some(formula => formula.output === formulaToAdd)) {
+    setShowToast({
+      key: "error",
+      label: t("ERR_FORMULA_ALREADY_EXISTS"),
+      transitionTime: 3000,
+    });
+    return;
+  }
   
   const newFormula = {
     source: "MDMS",
     output: formulaToAdd,
     input: "",
     operatorName: "",
     assumptionValue: "",
     category,
     showOnEstimationDashboard: true
   };
   
+  // Find insertion index based on category grouping
+  const categoryFormulas = formulaConfigValues.filter(f => f.category === category);
+  const insertIndex = categoryFormulas.length ? 
+    formulaConfigValues.indexOf(categoryFormulas[categoryFormulas.length - 1]) + 1 : 
+    formulaConfigValues.length;
   
   setFormulas(prev => [...prev, newFormula]);
   setFormulaConfigValues(prev => [
     ...prev.slice(0, insertIndex),
     newFormula,
     ...prev.slice(insertIndex)
   ]);
   
   setSelectedDeletedFormula(null);
   setFormulasPopUp(false);
 };
🧰 Tools
🪛 Biome

[error] 331-360: JSX elements without children should be marked as self-closing. In JSX, it is valid for any element to be self-closing.

Unsafe fix: Use a SelfClosingElement instead

(lint/style/useSelfClosingElements)


[error] 336-336: Avoid passing children using a prop

The canonical way to pass children in React is to use JSX elements

(lint/correctness/noChildrenProp)


[error] 337-337: Missing key property for this element in iterable.

The order of the items may change, and having a key can help React identify which item was moved.
Check the React documentation.

(lint/correctness/useJsxKeyInIterable)


Line range hint 1-424: Consider implementing a Formula Management Hook

The component has grown complex with multiple state management responsibilities. Consider extracting the formula management logic into a custom hook (e.g., useFormulaManagement) to:

  1. Separate concerns between UI and business logic
  2. Make the state management more testable
  3. Reduce component complexity
  4. Enable reuse of formula management logic

Would you like assistance in creating this custom hook?

🧰 Tools
🪛 Biome

[error] 331-360: JSX elements without children should be marked as self-closing. In JSX, it is valid for any element to be self-closing.

Unsafe fix: Use a SelfClosingElement instead

(lint/style/useSelfClosingElements)


[error] 336-336: Avoid passing children using a prop

The canonical way to pass children in React is to use JSX elements

(lint/correctness/noChildrenProp)


[error] 337-337: Missing key property for this element in iterable.

The order of the items may change, and having a key can help React identify which item was moved.
Check the React documentation.

(lint/correctness/useJsxKeyInIterable)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE

📥 Commits

Reviewing files that changed from the base of the PR and between 2a469ca and d830b35.

📒 Files selected for processing (2)
  • health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/components/FormulaConfiguration.js (1 hunks)
  • health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/components/Hypothesis.js (1 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/components/FormulaConfiguration.js (1)

Pattern **/*.js: check

health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/components/Hypothesis.js (1)

Pattern **/*.js: check

🪛 Biome
health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/components/FormulaConfiguration.js

[error] 336-336: Avoid passing children using a prop

The canonical way to pass children in React is to use JSX elements

(lint/correctness/noChildrenProp)


[error] 337-337: Missing key property for this element in iterable.

The order of the items may change, and having a key can help React identify which item was moved.
Check the React documentation.

(lint/correctness/useJsxKeyInIterable)

health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/components/Hypothesis.js

[error] 178-178: Avoid passing children using a prop

The canonical way to pass children in React is to use JSX elements

(lint/correctness/noChildrenProp)


[error] 179-179: Missing key property for this element in iterable.

The order of the items may change, and having a key can help React identify which item was moved.
Check the React documentation.

(lint/correctness/useJsxKeyInIterable)

🔇 Additional comments (2)
health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/components/Hypothesis.js (1)

176-180: LGTM! Good differentiation of confirmation messages.

The addition of the "HYP_" prefix helps distinguish hypothesis-related messages from other confirmations, improving context clarity for users.

Let's verify the translation keys are properly defined:

🧰 Tools
🪛 Biome

[error] 178-178: Avoid passing children using a prop

The canonical way to pass children in React is to use JSX elements

(lint/correctness/noChildrenProp)


[error] 179-179: Missing key property for this element in iterable.

The order of the items may change, and having a key can help React identify which item was moved.
Check the React documentation.

(lint/correctness/useJsxKeyInIterable)

health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/components/FormulaConfiguration.js (1)

334-334: LGTM: Toast message prefixing aligns with PR objective

The addition of "FOR_" prefix to confirmation messages helps differentiate formula-related notifications from other types, which aligns well with the PR objective.

Also applies to: 338-338

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.

2 participants