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

Go Back button and microplan name quotes fix #1844

Merged
merged 1 commit into from
Nov 18, 2024
Merged

Conversation

ashish-egov
Copy link
Contributor

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

Summary by CodeRabbit

  • New Features
    • Enhanced user interface with a new action button for non-root approvers in the FacilityCatchmentMapping component.
  • Bug Fixes
    • Simplified string rendering by removing unnecessary quotation marks in multiple components, improving the display of labels and names.
  • Refactor
    • Streamlined handling of state and logic in the FacilityCatchmentMapping component.
  • Chores
    • Minor adjustments to rendering logic and state management across various components.

@ashish-egov ashish-egov requested a review from a team as a code owner November 17, 2024 11:55
Copy link
Contributor

coderabbitai bot commented Nov 17, 2024

📝 Walkthrough

Walkthrough

The pull request introduces several modifications across multiple components within the microplan module. Key changes include adjustments to string interpolation in the rendering of various labels, specifically removing unnecessary quotation marks. Additionally, the FacilityCatchmentMapping component has simplified the handling of the useSearchPlanConfig hook and expanded the conditional rendering logic for the ActionBar to include a new button for non-root approvers. Overall, these changes streamline component logic and improve user interaction without altering the underlying functionality.

Changes

File Change Summary
.../ActivityCard.js Adjusted string interpolation for summary sub-heading, removing extra quotation marks.
.../FacilityCatchmentMapping.js Simplified useSearchPlanConfig hook handling; expanded ActionBar rendering logic for non-root approvers.
.../PlanInbox.js Removed extra quotation marks in JSX rendering; refined visibility logic for tabs based on selected filters.
.../PopInbox.js Adjusted string interpolation for microplan name, removing extra quotation marks.
.../viewVillage.js Modified string interpolation for campaign name, removing extra quotation marks.

Possibly related PRs

Suggested reviewers

  • nipunarora-eGov

🐰 "In the code where the rabbits play,
Quotation marks have hopped away.
With simpler strings, we cheer and sing,
For clearer views that changes bring!
In every card and every plan,
A smoother path for every fan!" 🐇


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

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

Line range hint 23-35: Consider these improvements for better maintainability and accessibility.

  1. Move inline styles to CSS classes
  2. Extract click handler logic to a separate function
  3. Add ARIA attributes for better accessibility of disabled states

Example refactor:

-<Card
-  className={`activity-card ${i.disable ? "disabled-activity" : ""}`}
-  style={{ 
-    minWidth: "100px", 
-    cursor: i.disable ? "not-allowed" : "pointer", 
-    opacity: i.disable ? 0.8 : 1,
-    justifyContent: "center",
-    alignItems: "center",
-    height: "200px",
-  }}
-  onClick={() => {
-    if (!i.disable) {
-      onClickCard(i)
-      i.link ? history.push(i.link) : location.assign(i.locate);
-    }
-  }}
+<Card
+  className={`activity-card ${i.disable ? "disabled-activity" : ""}`}
+  aria-disabled={i.disable}
+  role="button"
+  onClick={handleCardClick(i)}

Add corresponding CSS:

.activity-card {
  min-width: 100px;
  height: 200px;
  display: flex;
  justify-content: center;
  align-items: center;
  cursor: pointer;
}

.activity-card.disabled-activity {
  cursor: not-allowed;
  opacity: 0.8;
}

And the click handler:

const handleCardClick = (item) => () => {
  if (item.disable) return;
  onClickCard(item);
  item.link ? history.push(item.link) : location.assign(item.locate);
};
health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/pages/employee/viewVillage.js (3)

Line range hint 23-35: Consider consolidating related state variables.

Multiple related state variables could be combined into a single state object for better state management:

-const [showAccessbilityPopup, setShowAccessbilityPopup] = useState(false);
-const [showSecurityPopup, setShowSecurityPopup] = useState(false);
-const [showToast, setShowToast] = useState(null);
-const [showEditVillagePopulationPopup, setShowEditVillagePopulationPopup] = useState(false);
-const [showCommentLogPopup, setShowCommentLogPopup] = useState(false);
-const [showComment, setShowComment] = useState(false);
+const [uiState, setUiState] = useState({
+  showAccessbilityPopup: false,
+  showSecurityPopup: false,
+  showToast: null,
+  showEditVillagePopulationPopup: false,
+  showCommentLogPopup: false,
+  showComment: false
+});

Line range hint 71-108: Consider improving error handling for API calls.

The component makes multiple API calls but doesn't handle error states comprehensively. Consider adding error boundaries or error states for better user experience.

 const { data: planEmployeeDetailsData, isLoading: isLoadingPlanEmployee } = Digit.Hooks.microplanv1.usePlanSearchEmployee({
     tenantId: tenantId,
     body: {
         PlanEmployeeAssignmentSearchCriteria: {
             tenantId: tenantId,
             planConfigurationId: microplanId,
             employeeId: [userInfo.info.uuid],
             role: ["POPULATION_DATA_APPROVER", "ROOT_POPULATION_DATA_APPROVER"]
         },
     },
     config: {
         enabled: true,
         select: (data) => {
             return data?.PlanEmployeeAssignment?.[0];
         },
+        onError: (error) => {
+            setUiState(prev => ({
+                ...prev,
+                showToast: {
+                    key: "error",
+                    label: t("HCM_MICROPLAN_ERROR_FETCHING_EMPLOYEE_DETAILS"),
+                    transitionTime: 5000
+                }
+            }));
+        }
     },
 });

Line range hint 1-400: Consider extracting string literals as constants.

There are several repeated string literals (especially translation keys) that could be extracted as constants at the top of the file for better maintainability.

+const TRANSLATION_KEYS = {
+  MICROPLAN_NAME: "HCM_MICROPLAN_MICROPLAN_NAME_LABEL",
+  NO_NAME: "NO_NAME_AVAILABLE",
+  SECURITY_HEADING: "HCM_MICROPLAN_SECURITY_AND_ACCESSIBILITY_HEADING",
+  // ... other translation keys
+};
+
+const API_ENDPOINTS = {
+  CENSUS_SEARCH: "/census-service/_search",
+  CENSUS_UPDATE: "/census-service/_update",
+  // ... other endpoints
+};
health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/pages/employee/PopInbox.js (1)

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

The component handles multiple responsibilities and could benefit from the following improvements:

  1. Break down into smaller components for better separation of concerns:
    • Workflow management
    • Data fetching logic
    • UI rendering
  2. Group related state variables using a reducer or custom hooks
  3. Extract complex conditions into helper functions for better readability

Example of extracting complex conditions:

+const shouldShowActionBar = (isRootApprover, totalStatusCount, planStatus) => {
+  return isRootApprover && 
+         isStatusConditionMet(totalStatusCount) && 
+         planStatus === "CENSUS_DATA_APPROVAL_IN_PROGRESS";
+};

 {/* Replace complex condition */}
-{isRootApprover && isStatusConditionMet(totalStatusCount) && planObject?.status === "CENSUS_DATA_APPROVAL_IN_PROGRESS" &&
+{shouldShowActionBar(isRootApprover, totalStatusCount, planObject?.status) &&
   <ActionBar
     actionFields={[
       <Button 
         icon="CheckCircle" 
         label={t(`HCM_MICROPLAN_FINALIZE_POPULATION_DATA`)} 
         onClick={handleActionBarClick} 
         type="button" 
         variation="primary" 
       />,
     ]}
     className=""
     maxActionFieldsAllowed={5}
     setactionFieldsToRight
     sortActionFields
     style={{}}
   />
 }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE

📥 Commits

Reviewing files that changed from the base of the PR and between c3a7bfc and 42c3b70.

📒 Files selected for processing (5)
  • health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/components/ActivityCard.js (1 hunks)
  • health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/pages/employee/FacilityCatchmentMapping.js (3 hunks)
  • health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/pages/employee/PlanInbox.js (1 hunks)
  • health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/pages/employee/PopInbox.js (1 hunks)
  • health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/pages/employee/viewVillage.js (1 hunks)
🧰 Additional context used
📓 Path-based instructions (5)
health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/components/ActivityCard.js (1)

Pattern **/*.js: check

health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/pages/employee/FacilityCatchmentMapping.js (1)

Pattern **/*.js: check

health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/pages/employee/PlanInbox.js (1)

Pattern **/*.js: check

health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/pages/employee/PopInbox.js (1)

Pattern **/*.js: check

health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/pages/employee/viewVillage.js (1)

Pattern **/*.js: check

📓 Learnings (1)
health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/pages/employee/PopInbox.js (2)
Learnt from: rachana-egov
PR: egovernments/DIGIT-Frontend#1832
File: health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/pages/employee/PopInbox.js:592-594
Timestamp: 2024-11-14T12:48:23.024Z
Learning: In `PopInbox.js`, when integrating the `ConfirmationPopUp` component, error handling for API failures is managed internally within the component, so explicitly passing an `onError` prop is not necessary.
Learnt from: rachana-egov
PR: egovernments/DIGIT-Frontend#1837
File: health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/pages/employee/PopInbox.js:559-561
Timestamp: 2024-11-15T10:15:57.370Z
Learning: In `PopInbox.js`, error handling for the `onError` callback in `WorkflowCommentPopUp` is handled within the component, so explicit error handling in the parent component is unnecessary.
🪛 Biome
health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/pages/employee/FacilityCatchmentMapping.js

[error] 187-187: 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 (5)
health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/components/ActivityCard.js (1)

16-16: LGTM! String interpolation change looks good.

The template literal correctly displays the microplan name with proper fallback handling for undefined values. This change aligns with the PR objective of fixing microplan name quotes.

health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/pages/employee/FacilityCatchmentMapping.js (1)

159-160: LGTM: Clean string interpolation implementation

The template literal implementation correctly displays the microplan name with fallback.

health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/pages/employee/viewVillage.js (1)

224-224: LGTM! String interpolation fix looks good.

The template literal syntax for displaying the campaign name is correct and includes proper fallback handling.

health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/pages/employee/PopInbox.js (1)

513-513: LGTM! Improved string interpolation.

The removal of unnecessary quotes around the microplan name display improves readability without affecting functionality.

health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/pages/employee/PlanInbox.js (1)

532-532: LGTM! String interpolation improvement.

The simplified string interpolation enhances code clarity by removing unnecessary quotation marks.

Let's verify similar string interpolations across the microplan module for consistency:

✅ Verification successful

Based on the search results, I can see that the string interpolation pattern HCM_MICROPLAN_MICROPLAN_NAME_LABEL is consistently used across multiple files in the microplan module, including:

  1. ActivityCard.js: ${t("HCM_MICROPLAN_MICROPLAN_NAME_LABEL")}: ${props.microplanName || t("NO_NAME_AVAILABLE")}
  2. viewVillage.js: ${t("HCM_MICROPLAN_MICROPLAN_NAME_LABEL")}: ${campaignObject?.campaignName || t("NO_NAME_AVAILABLE")}
  3. PopInbox.js: ${t("HCM_MICROPLAN_MICROPLAN_NAME_LABEL")}: ${planObject?.name || t("NO_NAME_AVAILABLE")}
  4. FacilityCatchmentMapping.js: ${t("HCM_MICROPLAN_MICROPLAN_NAME_LABEL")}: ${planObject?.name || t("NO_NAME_AVAILABLE")}

The string interpolation pattern in the review comment matches the consistent pattern used throughout the codebase. Therefore, I can conclude that this change aligns with the established conventions.

String interpolation follows codebase conventions

The template literal usage for displaying the microplan name is consistent with similar implementations across the microplan module.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for similar string interpolation patterns in microplan module
rg -U "{\`.*?MICROPLAN.*?LABEL.*?\`}" "health/micro-ui/web/micro-ui-internals/packages/modules/microplan/"

# Search for potential inconsistent string interpolations with quotes
rg -U "'{\`.*?MICROPLAN.*?LABEL.*?\`}'" "health/micro-ui/web/micro-ui-internals/packages/modules/microplan/"

Length of output: 434


Script:

#!/bin/bash
# Search for similar string interpolation patterns in microplan module with fixed regex
rg -U "\{`.*MICROPLAN.*LABEL.*`\}" "health/micro-ui/web/micro-ui-internals/packages/modules/microplan/"

# Search for potential inconsistent string interpolations with quotes (fixed regex)
rg -U "'\{`.*MICROPLAN.*LABEL.*`\}'" "health/micro-ui/web/micro-ui-internals/packages/modules/microplan/"

# Alternative search using plain text patterns
rg "HCM_MICROPLAN" "health/micro-ui/web/micro-ui-internals/packages/modules/microplan/" -A 1 -B 1

Length of output: 71050

@nipunarora-eGov nipunarora-eGov merged commit 36b17dc into console Nov 18, 2024
3 checks passed
@nipunarora-eGov nipunarora-eGov deleted the goBackFacility branch November 18, 2024 04:50
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