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

planInbox console #1614

Merged
merged 5 commits into from
Oct 22, 2024
Merged

planInbox console #1614

merged 5 commits into from
Oct 22, 2024

Conversation

nabeelmd-eGov
Copy link
Contributor

@nabeelmd-eGov nabeelmd-eGov commented Oct 22, 2024

  • added plan with census call hook
  • added page size change fix

Summary by CodeRabbit

Release Notes

  • New Features

    • Enhanced UI components with new styles for buttons, modals, and upload sections.
    • Introduced pagination controls allowing users to dynamically adjust the number of rows displayed in tables.
    • Added a new custom hook for searching plans related to census data.
  • Bug Fixes

    • Improved error handling for employee assignment operations.
  • Documentation

    • Updated documentation for new hooks and components to enhance user understanding.

Copy link
Contributor

coderabbitai bot commented Oct 22, 2024

📝 Walkthrough

Walkthrough

This pull request introduces significant updates to the styling and functionality of several components within the micro UI framework. Key changes include the addition of new CSS classes and styles in microplanning.scss, enhancements to pagination controls in RoleTableComposer and UserAccess components, and the introduction of new hooks and asynchronous functions to manage data fetching related to plans and census. These modifications aim to improve user interaction, layout consistency, and overall component responsiveness.

Changes

File Change Summary
health/micro-ui/web/micro-ui-internals/packages/css/src/components/microplanning.scss Extensive modifications to CSS styles, including new classes for buttons, modals, upload sections, and improved layout for existing components.
health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/components/RoleTableComposer.js Added state management for rows per page, new handler for pagination changes, and refined existing functions for better state management.
health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/components/UserAccess.js Introduced dynamic rows per page management, updated handler for pagination, and adjusted useEffect hooks for data synchronization.
health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/hooks/index.js Added new hook usePlanSearchWithCensus to the exports, integrating it into the existing hook structure.
health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/hooks/services/searchPlanWithCensus.js Introduced new asynchronous function searchPlanWithCensus for fetching plan and census data with error handling.
health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/hooks/usePlanSearchWithCensus.js Created custom hook usePlanSearchWithCensus utilizing useQuery for plan searches, integrating with the new service function.

Possibly related PRs

  • Sandbox UI fixes #1442: Modifications to sandbox.scss that may relate to overall UI enhancements in microplanning.scss.
  • Mp hypothesis #1501: Updates in microplanning.scss and Hypothesis.js that reflect changes in styling and functionality.
  • Mp hypothesis #1505: Relevant modifications in microplanning.scss and Hypothesis.js involving styling and structural changes.
  • Facility mapper #1590: Enhancements in microplanning.scss and FacilityPopup.js that align with UI objectives of the main PR.
  • Role access table #1593: Validation enhancements in AssumptionsList.js that relate to improvements in user interaction and data handling.
  • Formula Screen #1599: Changes in FormulaConfigWrapper.js and FormulaConfiguration.js that introduce new functionalities consistent with main PR enhancements.

Suggested reviewers

  • nipunarora-eGov
  • jagankumar-egov

Poem

🐇 In the meadow where styles bloom,
Buttons and modals find their room.
Rows dance freely, pagination's grace,
With hooks that fetch in a swift embrace.
Oh, what joy in this code we weave,
A UI bright, we all believe! 🌼


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.

@nipunarora-eGov nipunarora-eGov merged commit 569c551 into console Oct 22, 2024
3 checks passed
@nipunarora-eGov nipunarora-eGov deleted the planInbox-console branch October 22, 2024 09:54
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: 11

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

Line range hint 137-176: LGTM: Improved handleHierarchyChange implementation

The refactored handleHierarchyChange function now handles both existing and new rows more robustly. It correctly uses the functional update form of setRowData and maintains other properties of existing rows when updating.

Consider extracting the logic for creating a new row into a separate function to improve readability:

const createNewRow = (rowIndex, value, boundaryOptions) => ({
  rowIndex,
  selectedHierarchy: value,
  boundaryOptions,
  selectedBoundaries: [],
});

// Then in the else block:
return [...prev, createNewRow(row?.rowIndex, value, boundaryOptions)];

Line range hint 177-241: LGTM: Enhanced handleBoundaryChange implementation

The refactored handleBoundaryChange function now robustly handles both existing and new rows. It correctly uses the functional update form of setRowData and maintains other properties of existing rows when updating.

For consistency with the handleHierarchyChange function, consider extracting the logic for creating a new row into a separate function:

const createNewBoundaryRow = (rowIndex, boundariesInEvent) => ({
  rowIndex,
  selectedBoundaries: boundariesInEvent,
});

// Then in the else block:
return [...prev, createNewBoundaryRow(row?.rowIndex, boundariesInEvent)];
📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE

📥 Commits

Files that changed from the base of the PR and between e647694 and 36f2f67.

📒 Files selected for processing (6)
  • 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/RoleTableComposer.js (3 hunks)
  • health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/components/UserAccess.js (5 hunks)
  • health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/hooks/index.js (2 hunks)
  • health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/hooks/services/searchPlanWithCensus.js (1 hunks)
  • health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/hooks/usePlanSearchWithCensus.js (1 hunks)
🧰 Additional context used
📓 Path-based instructions (5)
health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/components/RoleTableComposer.js (1)

Pattern **/*.js: check

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

Pattern **/*.js: check

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

Pattern **/*.js: check

health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/hooks/services/searchPlanWithCensus.js (1)

Pattern **/*.js: check

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

Pattern **/*.js: check

📓 Learnings (1)
health/micro-ui/web/micro-ui-internals/packages/css/src/components/microplanning.scss (3)
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-06-14T14:10:38.086Z
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.
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-10-08T20:11:07.772Z
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.
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-10-08T20:11:12.539Z
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.
🔇 Additional comments (11)
health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/hooks/usePlanSearchWithCensus.js (2)

1-2: LGTM: Imports are appropriate and well-structured.

The imports are correct and necessary for the hook's functionality. Using react-query is a good practice for managing server state, and importing a local service function promotes separation of concerns.


13-13: LGTM: Appropriate export statement.

The default export is correct for a single hook in the file, allowing for easy import and potential renaming in other parts of the application.

health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/hooks/index.js (2)

20-20: LGTM: New hook import looks good.

The import statement for usePlanSearchWithCensus follows the established pattern and naming convention in this file.


40-40: LGTM: New hook correctly added to microplanv1 object.

The usePlanSearchWithCensus hook has been properly added to the microplanv1 object, maintaining consistency with the existing structure.

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

7-7: LGTM: Improved function signature formatting.

The removal of extra spaces between parameters enhances code readability and consistency.


98-98: Please clarify the removal of the "ROOT" category check.

The selector for the "ADMINISTRATIVE_HIERARCHY" column has been simplified by removing the condition that checks if the category starts with "ROOT".

Can you confirm if this change is intentional and if the "COUNTRY" hierarchy level is no longer needed? If it's still required, consider keeping the condition or explain why it's been removed.


148-148: LGTM: Added onChangeRowsPerPage prop to DataTable.

The addition of the onChangeRowsPerPage prop to the DataTable component correctly connects it to the handleRowsPerPageChange function, enabling user control over the number of rows displayed per page.


Line range hint 1-188: Overall assessment: Improved pagination and code quality.

The changes in this file significantly enhance the UserAccess component's pagination functionality and overall code quality. The introduction of the rowsPerPage state and associated handler function provides more flexible control over data display. The code formatting improvements contribute to better readability and maintainability.

However, there are a few minor suggestions for further improvement:

  1. Consider using a constant for the initial rowsPerPage value.
  2. Add a comment explaining the page reset in handleRowsPerPageChange.
  3. Clarify the removal of the "ROOT" category check in the "ADMINISTRATIVE_HIERARCHY" column selector.

These changes align well with the PR objectives of fixing issues related to page size changes and overall improvement of the planInbox console.

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

20-20: LGTM: State management improvement for pagination

The addition of the setRowsPerPage setter function enables dynamic updates to the number of rows per page, which is crucial for the new pagination functionality.


434-434: LGTM: DataTable pagination enhancement

The addition of the onChangeRowsPerPage prop to the DataTable component correctly integrates the new handleRowsPerPageChange function, enabling dynamic updates to the number of rows per page.


Line range hint 1-447: Overall assessment: Improved pagination and state management

The changes in this file significantly enhance the RoleTableComposer component's functionality, particularly in terms of pagination and state management. The refactored handleHierarchyChange and handleBoundaryChange functions now handle both existing and new rows more robustly, while the new handleRowsPerPageChange function and associated DataTable prop enable dynamic updates to the number of rows per page.

These improvements contribute to a more responsive and user-friendly interface, aligning well with the PR objectives of enhancing the planInbox console functionality.

@@ -0,0 +1,13 @@
import { useQuery } from "react-query";
import searchPlanWithCensus from "./services/searchPlanWithCensus";
const usePlanSearchWithCensus = ({ tenantId, microplanId, body, limit = 5, offset = 0, roles, config = {} }) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick (assertive)

LGTM: Well-structured hook definition with a minor suggestion.

The hook definition follows React conventions and uses object destructuring for better readability. The default values for limit and offset are sensible.

Consider adding input validation for limit and offset to ensure they are non-negative integers. This could prevent potential issues with invalid inputs.

Comment on lines +4 to +11
return useQuery(
["PLAN_SEARCH_EMPLOYEE_WITH_TAGGING", tenantId, microplanId, body, limit, offset, roles, config?.queryKey],
() => searchPlanWithCensus({ tenantId, microplanId, body, limit, offset, roles }),
{
...config,
}
);
};
Copy link
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick (assertive)

LGTM: Solid implementation of useQuery with a suggestion for improvement.

The useQuery implementation is well-structured, with a comprehensive query key for proper caching and correct parameter passing. The use of config spreading allows for flexible configuration.

Consider adding error handling within the query function or in the component using this hook. This could improve the user experience by providing meaningful error messages or fallback UI in case of API failures.

Example:

() => searchPlanWithCensus({ tenantId, microplanId, body, limit, offset, roles })
  .catch(error => {
    console.error('Error fetching plan with census:', error);
    throw error; // Re-throw to let react-query handle it
  })

const { t } = useTranslation();
const tenantId = Digit.ULBService.getCurrentTenantId();
const { campaignId, microplanId, key, ...queryParams } = Digit.Hooks.useQueryParams();
const [showPopUp, setShowPopUp] = useState(null);
const [showToast, setShowToast] = useState(null);
const [currentPage, setCurrentPage] = useState(1);
const [rowsPerPage] = useState(5);
const [rowsPerPage, setRowsPerPage] = useState(5);
Copy link
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick (assertive)

LGTM: Added state for rows per page.

The introduction of the rowsPerPage state variable enhances the component's flexibility by allowing dynamic control of the number of rows displayed per page.

Consider using a constant or configuration value for the initial rowsPerPage value (5) to improve maintainability.

Comment on lines +65 to +69
const handleRowsPerPageChange = (newPerPage, page) => {
setRowsPerPage(newPerPage); // Update the rows per page state
setCurrentPage(page); // Optionally reset the current page or maintain it
refetchPlanEmployee();
};
Copy link
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick (assertive)

LGTM: Added handler for rows per page change.

The handleRowsPerPageChange function properly updates the rowsPerPage state and triggers a data refetch, improving the component's responsiveness to user interactions.

Consider adding a comment explaining the purpose of resetting the current page when the rows per page changes, as it might not be immediately obvious to other developers.

Comment on lines +356 to +360
const handleRowsPerPageChange = (newPerPage, page) => {
setRowsPerPage(newPerPage); // Update the rows per page state
setCurrentPage(page); // Optionally reset the current page or maintain it
refetchHrms(); // Fetch the updated data with the new rows per page
};
Copy link
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick (assertive)

LGTM: New handleRowsPerPageChange function added

The new handleRowsPerPageChange function properly updates the rowsPerPage state and triggers a data refetch, which is crucial for the pagination functionality.

Consider making the page reset optional:

const handleRowsPerPageChange = (newPerPage, page) => {
  setRowsPerPage(newPerPage);
  if (page !== currentPage) {
    setCurrentPage(page);
  }
  refetchHrms();
};

This way, the current page is only updated if it has actually changed, potentially reducing unnecessary re-renders.

if (error?.response?.data?.Errors) {
throw new Error(error.response.data.Errors[0].message);
}
throw new Error("An unknown error occurred");
Copy link
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick (assertive)

Include original error message in unknown errors

When throwing the generic error, include the original error message to provide more context for debugging.

Apply this diff:

-      throw new Error("An unknown error occurred");
+      throw new Error(error.message || "An unknown error occurred");
📝 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
throw new Error("An unknown error occurred");
throw new Error(error.message || "An unknown error occurred");

Comment on lines +12 to +14
if (!response) {
throw new Error("Employee not found with the given role");
}
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

Correct the error message when plan data is not found

The error message "Employee not found with the given role" is misleading. Since this function searches for plan data, update the error message to accurately reflect the issue.

Apply this diff:

-if (!response) {
-  throw new Error("Employee not found with the given role");
+if (!response || !response.Plan || response.Plan.length === 0) {
+  throw new Error("Plan data not found");
📝 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
if (!response) {
throw new Error("Employee not found with the given role");
}
if (!response || !response.Plan || response.Plan.length === 0) {
throw new Error("Plan data not found");
}

throw new Error("Employee not found with the given role");
}

const localityArray = [...new Set(response?.Plan?.map((item) => item?.locality))];
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

Handle undefined locality values when mapping response.Plan

If item.locality is undefined, it will be included in localityArray as undefined. Filter out undefined localities to avoid potential issues in the subsequent API call.

Apply this diff:

-const localityArray = [...new Set(response?.Plan?.map((item) => item?.locality))];
+const localityArray = [...new Set(response?.Plan?.map((item) => item?.locality).filter(Boolean))];
📝 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 localityArray = [...new Set(response?.Plan?.map((item) => item?.locality))];
const localityArray = [...new Set(response?.Plan?.map((item) => item?.locality).filter(Boolean))];

Comment on lines +33 to +35
if (!fetchCensusData) {
throw new Error("Employee not found with the given role");
}
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

Correct the error message when census data is not found

The error message "Employee not found with the given role" is misleading. Since this function fetches census data, update the error message to accurately reflect the issue.

Apply this diff:

-if (!fetchCensusData) {
-  throw new Error("Employee not found with the given role");
+if (!fetchCensusData || !fetchCensusData.Census || fetchCensusData.Census.length === 0) {
+  throw new Error("Census data not found");
📝 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
if (!fetchCensusData) {
throw new Error("Employee not found with the given role");
}
if (!fetchCensusData || !fetchCensusData.Census || fetchCensusData.Census.length === 0) {
throw new Error("Census data not found");
}

Comment on lines +2637 to +2639
.digit-multiselectdropdown-wrap.nestedmultiselect{
min-width: 30rem;
}
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 using responsive units for min-width

The hard-coded min-width: 30rem; may not be optimal for all screen sizes. To enhance responsiveness, consider using relative units like percentages (%) or em, or apply media queries to adjust the min-width based on screen dimensions.

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