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

Info icon revert changes #1801

Open
wants to merge 4 commits into
base: console
Choose a base branch
from
Open

Info icon revert changes #1801

wants to merge 4 commits into from

Conversation

ashish-egov
Copy link
Contributor

@ashish-egov ashish-egov commented Nov 12, 2024

Summary by CodeRabbit

  • New Features

    • Updated CSS stylesheet version for improved styling.
    • Enhanced user interface for formula and assumption management, including tooltips and improved layout.
  • Bug Fixes

    • Resolved issues with formula and assumption deletion, ensuring at least one remains in each category.
  • Style

    • Comprehensive updates to the styling of various components, focusing on layout consistency and visual appeal, including new animations and improved spacing.

@ashish-egov ashish-egov requested a review from a team as a code owner November 12, 2024 06:14
Copy link
Contributor

coderabbitai bot commented Nov 12, 2024

📝 Walkthrough
📝 Walkthrough

Walkthrough

The pull request includes updates to several files primarily focused on modifying CSS stylesheet links and enhancing component styles and functionality. The CSS version has been incremented from 0.1.30 to 0.1.31 in multiple HTML files. Additionally, significant changes were made to SCSS files to improve layout properties, spacing, and visual appeal of various components. The JavaScript components have also been updated to refine user interactions, particularly in rendering formulas and assumptions, as well as handling deletions and additions more effectively.

Changes

File Change Summary
health/micro-ui/web/micro-ui-internals/example/public/index.html Updated CSS stylesheet version from 0.1.30 to 0.1.31.
health/micro-ui/web/public/index.html Updated CSS stylesheet version from 0.1.30 to 0.1.31.
health/micro-ui/web/micro-ui-internals/packages/css/src/components/microplanning.scss Extensive modifications to styles, including layout adjustments, margin and padding updates, and new styles for buttons and loaders.
health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/components/FormulaConfiguration.js Restructured rendering logic, refined formula deletion and addition processes, and improved state management.
health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/components/Hypothesis.js Enhanced rendering of assumptions, updated tooltip integration, and refined logic for adding and deleting assumptions.

Possibly related PRs

Suggested reviewers

  • nipunarora-eGov

🐰 In the garden, changes bloom,
A stylesheet update, making room.
With margins adjusted, colors bright,
Our UI dances, a lovely sight!
Formulas and hypotheses in line,
A hop, a skip, all is fine! 🌼✨


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

🧹 Outside diff range comments (4)
health/micro-ui/web/micro-ui-internals/example/public/index.html (1)

Line range hint 1-33: Consider performance optimizations for CSS loading.

The file loads multiple CSS files from unpkg.com CDN. Consider the following optimizations:

  1. Combine CSS files to reduce HTTP requests
  2. Use preload/prefetch hints for critical CSS
  3. Consider self-hosting these files for better control over caching and availability

Example implementation:

+ <link rel="preload" as="style" href="https://unpkg.com/@egovernments/[email protected]/dist/index.css" />

Would you like assistance in implementing these optimizations or creating a GitHub issue to track this improvement?

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

Line range hint 1-576: Consider component decomposition and state management improvements

The component handles multiple complex responsibilities which could benefit from better separation of concerns:

  1. Formula CRUD operations
  2. State management for formulas and deletions
  3. Multiple popup dialogs
  4. Complex UI rendering

Consider these improvements:

  1. Extract formula management logic into a custom hook (e.g., useFormulaManagement)
  2. Split the component into smaller, focused components:
    • FormulaList
    • FormulaItem
    • DeleteConfirmationDialog
    • AddFormulaDialog
  3. Replace ref-based deletion tracking with proper state management
  4. Consider using a reducer for complex state updates

Would you like assistance in implementing any of these architectural improvements?

🧰 Tools
🪛 Biome

[error] 307-307: 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)


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

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

(lint/correctness/noChildrenProp)

health/micro-ui/web/micro-ui-internals/packages/css/src/components/microplanning.scss (2)

Line range hint 1-2624: Consider improving SCSS structure and maintainability.

The SCSS file could benefit from the following improvements:

  1. Extract repeated color values and dimensions into variables
  2. Reduce nesting depth to improve maintainability
  3. Consolidate media queries for better responsive design management
  4. Split into smaller, focused files (e.g., _upload.scss, _hypothesis.scss, etc.)

Example of extracting variables:

- border: 0.063rem solid rgba(214, 213, 212, 1);
+ $border-width: 0.063rem;
+ $border-color-light: rgba(214, 213, 212, 1);
+ border: $border-width solid $border-color-light;

Line range hint 1-2624: Enhance accessibility through improved styles.

Consider the following accessibility improvements:

  1. Ensure color contrast ratios meet WCAG 2.1 Level AA standards (especially for text colors)
  2. Enhance focus states for better keyboard navigation
  3. Add styles for ARIA states (e.g., aria-selected, aria-expanded)

Example for focus states:

+ .interactive-element:focus-visible {
+   outline: 0.188rem solid $primary-theme-color;
+   outline-offset: 0.125rem;
+ }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE

📥 Commits

Reviewing files that changed from the base of the PR and between 4bf3640 and 4ad0afc.

⛔ Files ignored due to path filters (1)
  • health/micro-ui/web/micro-ui-internals/packages/css/package.json is excluded by !**/*.json
📒 Files selected for processing (5)
  • health/micro-ui/web/micro-ui-internals/example/public/index.html (1 hunks)
  • health/micro-ui/web/micro-ui-internals/packages/css/src/components/microplanning.scss (1 hunks)
  • 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)
  • health/micro-ui/web/public/index.html (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

📓 Learnings (1)
health/micro-ui/web/micro-ui-internals/packages/css/src/components/microplanning.scss (1)
Learnt from: siddhant-nawale-egov
PR: egovernments/DIGIT-Frontend#876
File: micro-ui/web/micro-ui-internals/packages/css/src/components/microplanning.scss:1940-2392
Timestamp: 2024-11-10T20:01:49.000Z
Learning: Classes related to interactive elements in the microplan preview section are mostly passed to Higher Order Components (HOCs), and ARIA attributes for non-HOC elements will be managed directly by adding them where necessary.
🪛 Biome
health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/components/FormulaConfiguration.js

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

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

(lint/correctness/noChildrenProp)

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

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

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

(lint/correctness/noChildrenProp)

🔇 Additional comments (2)
health/micro-ui/web/micro-ui-internals/example/public/index.html (1)

15-15: Verify the latest stable version of digit-ui-health-css.

While updating to version 0.1.31 is consistent with the PR objectives, let's verify if this is the latest stable version and check for any security advisories.

✅ Verification successful

Let me gather more information about the package versions in the repository to better understand the versioning pattern.


Version 0.1.31 is the correct version to use

The version update is verified to be correct based on the following findings:

  • The package.json in the repository defines version 0.1.31 as the current version
  • The same version is consistently used in multiple HTML files in the codebase
  • While npm shows 0.1.0 as latest, this appears to be a registry sync issue as the actual package in the codebase is at 0.1.31
  • No security vulnerabilities were found for this package
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check the latest version and security status of digit-ui-health-css package

# Check NPM for latest versions of the package
curl -s https://registry.npmjs.org/@egovernments/digit-ui-health-css | jq '.["dist-tags"].latest'

# Check for any security advisories
gh api graphql -f query='
{
  securityVulnerabilities(first: 5, ecosystem: NPM, package: "@egovernments/digit-ui-health-css") {
    nodes {
      advisory {
        summary
        severity
        publishedAt
      }
      vulnerableVersionRange
      firstPatchedVersion {
        identifier
      }
    }
  }
}'

Length of output: 474


Script:

#!/bin/bash
# Search for other occurrences of digit-ui-health-css version references
rg -i "digit-ui-health-css@" -A 1 -B 1

# Check package.json files for any references to this package
fd "package.json" --exec grep -l "digit-ui-health-css" {} \; --exec cat {}

Length of output: 2793

health/micro-ui/web/micro-ui-internals/packages/css/src/components/microplanning.scss (1)

2591-2591: LGTM: Icon spacing adjustment looks good.

The increased left margin (0.3rem) for the icon wrapper provides better visual spacing between the assumption label text and its associated icon.

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

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

Line range hint 191-193: Remove redundant isDisabled logic

The isAddNewDisabled calculation is being overridden with a hardcoded false. Either remove the unused logic or use the calculated value.

Apply one of these changes:

-        <Button
-          icon="Add"
-          label={category === "CAMPAIGN_VEHICLES" ? t(`ADD_ASSUMPTION_${category}`) : t("ADD_ASSUMPTION")}
-          onClick={() => setAssumptionsPopUp(true)}
-          variation="secondary"
-          // isDisabled={isAddNewDisabled}
-          isDisabled={false}
-        />

Option 1: Remove unused logic:

-  const isAddNewDisabled =
-    !deletedAssumptionCategories.current[category] ||
-    deletedAssumptionCategories.current[category].length === 0 ||
-    deletedAssumptionCategories.current[category].every((item) => !deletedAssumptions.includes(item));

   // In Button component
   <Button
     icon="Add"
     label={category === "CAMPAIGN_VEHICLES" ? t(`ADD_ASSUMPTION_${category}`) : t("ADD_ASSUMPTION")}
     onClick={() => setAssumptionsPopUp(true)}
     variation="secondary"
     isDisabled={false}
   />

Option 2: Use calculated value:

   <Button
     icon="Add"
     label={category === "CAMPAIGN_VEHICLES" ? t(`ADD_ASSUMPTION_${category}`) : t("ADD_ASSUMPTION")}
     onClick={() => setAssumptionsPopUp(true)}
     variation="secondary"
-    // isDisabled={isAddNewDisabled}
-    isDisabled={false}
+    isDisabled={isAddNewDisabled}
   />
🧰 Tools
🪛 Biome

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

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

(lint/correctness/noChildrenProp)


Line range hint 82-117: Refactor addNewAssumption for better maintainability

The addNewAssumption function contains duplicate logic patterns for different cases. Consider extracting common logic into helper functions.

Consider refactoring like this:

+ const addAssumptionToState = (key, source = "CUSTOM") => {
+   setAssumptions(prev => [...prev, key]);
+   if (!assumptionValues.some(assumption => assumption.key === key)) {
+     setAssumptionValues(prev => [...prev, { 
+       source, 
+       key, 
+       value: null, 
+       category 
+     }]);
+   }
+ };

  const addNewAssumption = () => {
    if (category === "CAMPAIGN_VEHICLES") {
-     const assumptionToAdd = {
-       ...selectedDeletedAssumption,
-       source: "CUSTOM",
-       category: category,
-       value: null,
-       key: selectedDeletedAssumption?.model,
-     };
-     setAssumptions([...assumptions, assumptionToAdd?.key]);
-     if (!assumptionValues.some((assumption) => assumption.key === assumptionToAdd)) {
-       setAssumptionValues((prevValues) => [
-         ...prevValues,
-         { source: "CUSTOM", key: selectedDeletedAssumption?.model, value: null, category: category },
-       ]);
-     }
+     addAssumptionToState(selectedDeletedAssumption?.model);
    } else if (selectedDeletedAssumption?.code === "NEW_ASSUMPTION") {
-     const assumptionToAdd = selectedDeletedAssumption;
-     setAssumptions([...assumptions, assumptionToAdd?.name]);
-     if (!assumptionValues.some((assumption) => assumption.key === assumptionToAdd)) {
-       setAssumptionValues((prevValues) => [
-         ...prevValues,
-         { source: "CUSTOM", key: assumptionToAdd?.name, value: null, category: category },
-       ]);
-     }
+     addAssumptionToState(selectedDeletedAssumption?.name);
    } else if (selectedDeletedAssumption) {
      const assumptionToAdd = deletedAssumptions.find(
        (assumption) => assumption === selectedDeletedAssumption.code
      );

      if (assumptionToAdd && !assumptions.includes(assumptionToAdd)) {
-       setAssumptions([...assumptions, assumptionToAdd]);
        setDeletedAssumptions(deletedAssumptions.filter(
          (assumption) => assumption !== selectedDeletedAssumption.code
        ));

        if (deletedAssumptionCategories.current[category]) {
          deletedAssumptionCategories.current[category] = 
            deletedAssumptionCategories.current[category].filter(
              (item) => item !== assumptionToAdd
            );
        }

-       if (!assumptionValues.some((assumption) => assumption.key === assumptionToAdd)) {
-         setAssumptionValues((prevValues) => [
-           ...prevValues,
-           { source: "MDMS", key: assumptionToAdd, value: null },
-         ]);
-       }
+       addAssumptionToState(assumptionToAdd, "MDMS");
      }
    }

    setSelectedDeletedAssumption(null);
    setAssumptionsPopUp(false);
  };
🧰 Tools
🪛 Biome

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

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

(lint/correctness/noChildrenProp)


Based on the codebase analysis, I can now provide the final response:

Add validation for assumption name using existing validation utilities

The codebase already has a robust validation pattern in utilities.js that can be leveraged:

  • Use validateFormData() for empty string checks
  • Implement a pattern validation similar to validateName() used for microplan names

Example locations that need validation:

  • Line 257: onChange={(e) => setSelectedDeletedAssumption(e.target.value)}
  • Line 281: onChange={(e) => setSelectedDeletedAssumption(e.target.value)}
🔗 Analysis chain

Line range hint 269-275: Add validation for assumption name

The assumption name input field lacks validation. Consider adding checks for empty strings, special characters, or duplicate names.

Let's verify if there are any validation patterns used elsewhere in the codebase:

Would you like me to help implement the validation logic for the assumption name?


Let me search for validation patterns specifically in the microplan module and related components.


Let me search for the validation patterns specifically used in the Hypothesis component and related files.


Let me try one final search to find any validation patterns in the microplan module's utilities or common functions.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for input validation patterns
rg -A 3 'TextInput.*name.*value.*onChange' 

Length of output: 4470


Script:

#!/bin/bash
# Search for validation patterns in microplan module
rg -A 3 'validation|validate|isValid' health/micro-ui/web/micro-ui-internals/packages/modules/microplan/

# Search for existing assumption name validations
ast-grep --pattern 'setSelectedDeletedAssumption($$$)'

Length of output: 46541


Script:

#!/bin/bash
# Search for validation patterns in Hypothesis.js and related files
rg -A 5 'validateName|validation|pattern' health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/components/Hypothesis.js

# Search for assumption-related validation patterns
ast-grep --pattern 'function validateAssumption($$$)'

Length of output: 194


Script:

#!/bin/bash
# Search for validation utilities in the microplan module
rg -A 5 'validate|pattern|isValid' health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/utils/

# Search for assumption validation in the entire codebase
ast-grep --pattern 'assumption.*validate'

Length of output: 8272

🧰 Tools
🪛 Biome

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

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

(lint/correctness/noChildrenProp)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE

📥 Commits

Reviewing files that changed from the base of the PR and between 4ad0afc and 8b05d47.

📒 Files selected for processing (1)
  • health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/components/Hypothesis.js (1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
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/Hypothesis.js

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

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

(lint/correctness/noChildrenProp)

coderabbitai[bot]
coderabbitai bot previously approved these changes Nov 12, 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: 0

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

Line range hint 1-200: Consider refactoring for improved maintainability.

While not directly related to the current changes, the fetchDataAndSetParams function could benefit from some architectural improvements:

  1. Consider breaking down the function into smaller, focused utilities:

    • Boundary data processing
    • File handling
    • Assumptions processing
    • Formula configuration
  2. Consider introducing explicit error handling instead of relying solely on optional chaining.

This would improve maintainability, testability, and make future changes easier to implement.

Would you like me to provide a detailed refactoring proposal?

📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE

📥 Commits

Reviewing files that changed from the base of the PR and between 8b05d47 and 07160a3.

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

Pattern **/*.js: check

🔇 Additional comments (1)
health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/utils/fetchDataAndSetParams.js (1)

58-58: LGTM! Verify locale utility availability.

The change improves i18n key handling by using the locale transformation utility. This is a good practice for consistent internationalization.

Let's verify the Digit.Utils.locale dependency and its usage:

✅ Verification successful

Based on the search results, I can see that:

  1. Digit.Utils.locale.getTransformedLocale is widely used across the codebase for i18n key transformations
  2. The utility is imported via various @egovernments/digit-ui-* packages
  3. The implementation exists in micro-ui/web/micro-ui-internals/packages/libraries/src/utils/locale.js

Let me check the actual implementation to verify if this is a safe change:


The locale transformation change is safe and consistent with codebase practices

The implementation of getTransformedLocale in the codebase shows that it's a standardized utility function that:

  1. Converts input to uppercase
  2. Replaces special characters (dots, colons, hyphens, spaces, slashes) with underscores
  3. Handles null safety and number inputs

The change in the review file follows the established pattern of using this utility for i18n key normalization, which is widely used across the codebase for consistent internationalization handling.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for Digit.Utils.locale usage and imports
# Test 1: Look for other usages of getTransformedLocale
rg "Digit\.Utils\.locale\.getTransformedLocale" -A 2

# Test 2: Check for Digit utils import or definition
rg "import.*Digit" -A 2

Length of output: 71001


Script:

#!/bin/bash
# Check the implementation of getTransformedLocale
cat micro-ui/web/micro-ui-internals/packages/libraries/src/utils/locale.js

Length of output: 3693

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.

1 participant