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

Role access table #1593

Merged
merged 25 commits into from
Oct 21, 2024
Merged

Role access table #1593

merged 25 commits into from
Oct 21, 2024

Conversation

abishekTa-egov
Copy link
Collaborator

@abishekTa-egov abishekTa-egov commented Oct 21, 2024

Validations on Employee-tagging to microplan

Summary by CodeRabbit

Release Notes

  • New Features

    • Enhanced AssumptionsList component for improved error handling and rendering.
    • Added navigation flexibility in the Response component with dynamic labels and paths.
    • Introduced new props in RoleTableComposer and UserAccess for better data management.
    • Expanded user feedback mechanisms in UserUpload and UserAccessWrapper components.
    • New routes added for better navigation in the UserDownload and index.js components.
    • Updated SetupMicroplan component for improved redirection logic based on response conditions.
  • Bug Fixes

    • Improved error handling and state updates across various components to ensure smoother user experience.

Copy link
Contributor

coderabbitai bot commented Oct 21, 2024

Caution

Review failed

The pull request is closed.

📝 Walkthrough
📝 Walkthrough

Walkthrough

The pull request introduces several modifications across multiple components within the microplan module. Key changes include enhancements to error handling, state management, and rendering logic. Components such as AssumptionsList, Response, RoleTableComposer, UserAccess, and UserUpload have been updated to improve their robustness and flexibility. New props have been added to several components, and new routes have been introduced in the main application file to support additional functionality. These changes collectively aim to enhance user interaction and data management within the application.

Changes

File Change Summary
.../AssumptionsList.js Added optional chaining and fallback values for assumptionValues. Refactored rendering logic using arrow functions, improved destructuring, and added semicolons for consistency.
.../Response.js Added import for Button, updated internal state management with new variables, modified PanelCard description prop, and adjusted the Link component's to prop. Changed Button label to use the back variable and adjusted its styling.
.../RoleTableComposer.js Modified to accept a new nationalRoles prop, updated dropdown rendering logic, and refactored event handling functions for clarity. Enhanced data fetching logic with a new topBoundary variable.
.../UserAccess.js Updated to accept new props setData and nationalRoles, modified the columns array, and passed the category prop to the DataTable. Updated RoleTableComposer to include new props.
.../UserAccessWrapper.js Added state variable data, defined nationalRoles, updated handleNext function for error handling, and modified the invocation of UserAccess to pass new props. Introduced new toast notifications for error handling.
.../UserUpload.js Enhanced onSubmit function to include additional properties in the state object, updated fetchData function for error handling, and modified downloadTemplate for better user feedback.
.../UserDownload.js Updated useFileDownload hook's select function to include an explicit return statement and improved state management for file IDs.
.../index.js Added new routes for Response and FacilityCatchmentMapping components within the PrivateRoute.

Possibly related PRs

Suggested reviewers

  • nipunarora-eGov

Poem

🐇 In the garden of code, we hop and play,
With changes so bright, they light up the way.
From lists of assumptions to routes that we weave,
Each line a new tale, in which we believe.
So let’s toast to the updates, both big and small,
For in our microplan, we’re improving it all! 🎉


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

🧹 Outside diff range comments (2)
health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/pages/employee/UserDownload.js (1)

Line range hint 30-36: Approved with a suggestion for error handling.

The useEffect hook effectively updates the Files state when data changes, ensuring that the component reflects the latest file IDs. This is a good practice for keeping the component's state in sync with the fetched data.

Consider adding a check for data["ResourceDetails"] being an array before calling map to improve robustness:

useEffect(() => {
    if (data && Array.isArray(data["ResourceDetails"])) {
        const newFiles = data["ResourceDetails"].map(ob => ob["processedFilestoreId"]);
        setFile(newFiles);
    }
}, [data]);

This change would prevent potential errors if data["ResourceDetails"] is unexpectedly not an array.

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

Line range hint 20-20: Summary: New routes and imports enhance microplan module functionality.

The changes in this file successfully add new routes for setup-completed-response and assign-facilities-to-villages, along with the necessary import for the FacilityCatchmentMapping component. These additions align with the PR objectives of implementing validations on Employee-tagging to microplan.

A few minor suggestions have been made for improved consistency and code organization. Overall, the changes are well-implemented and integrate smoothly with the existing code structure.

If you need any clarification on the suggestions or assistance with implementing them, please let me know.

Also applies to: 193-198

📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE

📥 Commits

Files that changed from the base of the PR and between a2735bf and 0de3e8c.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json, !**/*.json
📒 Files selected for processing (8)
  • health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/components/AssumptionsList.js (1 hunks)
  • health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/components/Response.js (4 hunks)
  • health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/components/RoleTableComposer.js (10 hunks)
  • health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/components/UserAccess.js (7 hunks)
  • health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/components/UserAccessWrapper.js (5 hunks)
  • health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/components/UserUpload.js (1 hunks)
  • health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/pages/employee/UserDownload.js (1 hunks)
  • health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/pages/employee/index.js (1 hunks)
🧰 Additional context used
📓 Path-based instructions (8)
health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/components/AssumptionsList.js (1)

Pattern **/*.js: check

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

Pattern **/*.js: check

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/components/UserAccessWrapper.js (1)

Pattern **/*.js: check

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

Pattern **/*.js: check

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

Pattern **/*.js: check

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

Pattern **/*.js: check

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

[error] 12-12: This let declares a variable that is only assigned once.

'dic' is never reassigned.

Safe fix: Use const instead.

(lint/style/useConst)

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

[error] 44-44: This let declares a variable that is only assigned once.

'selectedHierarchy' is never reassigned.

Safe fix: Use const instead.

(lint/style/useConst)

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

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

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

(lint/correctness/noChildrenProp)


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

7-10: LGTM: Improved error handling for assumptionValues access

The use of optional chaining and providing a default empty array enhances the robustness of the code. This change prevents potential runtime errors when accessing nested properties.


14-24: LGTM: Enhanced error handling in assumption processing

The addition of default values for category, key, and value improves the robustness of the code by handling potential undefined values gracefully.


29-31: LGTM: Improved code readability in rendering logic

The use of arrow functions and implicit returns simplifies the code structure, making it more concise and easier to read. This change aligns well with modern JavaScript practices.


33-47: LGTM: Enhanced error handling and readability in rendering logic

The changes in this section significantly improve both error handling and code readability:

  1. The use of arrow functions simplifies the code structure.
  2. Destructuring with fallback values (['NA', 'NA']) ensures that the code doesn't break if item1 is undefined.
  3. The overall structure is more concise and easier to follow.

These improvements make the component more robust and maintainable.


1-55: Overall improvements in AssumptionsList component

The changes made to this component have significantly enhanced its robustness and readability:

  1. Improved error handling through optional chaining and default values.
  2. Enhanced code readability with modern JavaScript practices (arrow functions, destructuring).
  3. Better handling of potential undefined values throughout the component.

These improvements align well with the PR objectives of implementing validations in the microplan module. The component is now more resilient to potential errors and easier to maintain.

🧰 Tools
🪛 Biome

[error] 12-12: This let declares a variable that is only assigned once.

'dic' is never reassigned.

Safe fix: Use const instead.

(lint/style/useConst)

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

30-30: Approve dynamic description for PanelCard.

The change to use state.description for the PanelCard component's description prop improves the component's flexibility. This allows for dynamic descriptions based on the component's state.

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

7-7: LGTM: Function signature updated appropriately.

The addition of setData and nationalRoles props aligns with the component's enhanced functionality for data management and role handling.


36-36: LGTM: Data management enhancement.

The addition of setData(data); allows the component to update external state with the fetched data, improving data flow and management.


137-137: LGTM: DataTable component updated with category prop.

The addition of the category prop to the DataTable component enhances its flexibility, allowing for category-specific handling within the table.


88-93: Verify the impact of simplified hierarchy level logic.

The removal of commented-out code improves readability. However, please confirm that directly returning row?.hierarchyLevel doesn't negatively impact the functionality, especially for cases where the category starts with "ROOT".

✅ Verification successful

Verified the impact of the simplified hierarchy level logic.
The removal of the commented-out code in UserAccess.js does not affect other parts of the codebase and maintains the intended functionality.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for any other occurrences of ROOT category handling in the codebase

# Test: Search for ROOT category handling
rg -i 'ROOT.*hierarchy' --type js

Length of output: 236

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

Line range hint 20-20: LGTM: New component import added correctly.

The import statement for the FacilityCatchmentMapping component is properly placed and follows React naming conventions.

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

10-10: Updated function signature to include 'nationalRoles' prop

The RoleTableComposer component now accepts nationalRoles as a prop. Ensure that this prop is being passed correctly from the parent component and is utilized appropriately within this component.


31-31: Retrieving 'topBoundary' correctly

The topBoundary is obtained by finding the boundary where parentBoundaryType is null. This logic appears correct and should effectively retrieve the top-level boundary.


57-60: Mapping 'selectedHierarchy' correctly in employee data

The code correctly assigns selectedHierarchy by finding the matching hierarchy level for each employee based on their employeeId. This ensures that the hierarchy information is accurately reflected in the row data.


131-135: Updating 'rowData' state in 'handleHierarchyChange'

The changes in the handleHierarchyChange function update the rowData state correctly. The code handles both updating existing rows and adding new ones as needed.


189-191: Clearing selected boundaries when none are selected

In handleBoundaryChange, the code correctly clears the selectedBoundaries for the row when no boundaries are selected.


220-222: Updating selected boundaries based on user selection

The logic properly updates the selectedBoundaries in the rowData state with the boundaries selected by the user.

Comment on lines 5 to 8
import { Button } from "@egovernments/digit-ui-components";
import { PanelCard } from "@egovernments/digit-ui-components";
import { Button } from "@egovernments/digit-ui-react-components";
const Response = () => {
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

Remove duplicate Button import and clarify component usage.

There are two imports for the Button component from different packages:

  1. @egovernments/digit-ui-components
  2. @egovernments/digit-ui-react-components

This could lead to confusion and potential bugs. Please remove one of the imports and ensure that the correct Button component is used throughout the file.

Apply this diff to resolve the issue:

import { ActionBar, SubmitBar, ArrowLeft, ArrowForward } from "@egovernments/digit-ui-react-components";
-import { Button } from "@egovernments/digit-ui-components";
import { PanelCard } from "@egovernments/digit-ui-components";
-import { Button } from "@egovernments/digit-ui-react-components";

Choose the appropriate import based on which Button component you intend to use in the component.

📝 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
import { Button } from "@egovernments/digit-ui-components";
import { PanelCard } from "@egovernments/digit-ui-components";
import { Button } from "@egovernments/digit-ui-react-components";
const Response = () => {
import { ActionBar, SubmitBar, ArrowLeft, ArrowForward } from "@egovernments/digit-ui-react-components";
import { PanelCard } from "@egovernments/digit-ui-components";
const Response = () => {
🧰 Tools
🪛 Biome

[error] 7-7: Shouldn't redeclare 'Button'. Consider to delete it or rename it.

'Button' is defined here:

(lint/suspicious/noRedeclare)

Comment on lines +21 to 23
select: data => {
return data;
}
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)

Approved with a minor suggestion.

The explicit return statement improves code clarity. However, since the function is a single expression, you could use an arrow function with implicit return for more concise code:

select: data => data

This achieves the same result with less verbosity.

@@ -149,7 +156,7 @@ function UserAccess({ category }) {
className={"roleComposer"}
type={"default"}
heading={t(`${category}`)}
children={[<RoleTableComposer />]}
children={[<RoleTableComposer category={category} nationalRoles={nationalRoles} />]}
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

Update PopUp children to address React best practices.

The addition of category and nationalRoles props to RoleTableComposer enhances its functionality. However, there are two React-related issues to address:

  1. Use JSX elements instead of passing children as a prop.
  2. Add a key prop to the element in the array.

Please update the PopUp component as follows:

- children={[<RoleTableComposer category={category} nationalRoles={nationalRoles} />]}
+ children={<RoleTableComposer key="roleComposer" category={category} nationalRoles={nationalRoles} />}

This change resolves both the children prop issue and the missing key warning.

📝 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
children={[<RoleTableComposer category={category} nationalRoles={nationalRoles} />]}
children={<RoleTableComposer key="roleComposer" category={category} nationalRoles={nationalRoles} />}
🧰 Tools
🪛 Biome

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

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

(lint/correctness/noChildrenProp)


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

Comment on lines 304 to 315
return (category in nationalRoles) ? (
<Dropdown
className="form-field"
selected={{ code: topBoundary?.boundaryType }}
disable={true}
isMandatory={true}
option={[{ key: 1, code: topBoundary?.boundaryType }]}
select={{ code:topBoundary?.boundaryType }}
optionKey="code"
t={t}
/>
) : (
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

Incorrect usage of the 'select' prop in 'Dropdown' component

In the Dropdown component within the Hierarchy column, the select prop is expected to be a function that handles selection changes. However, it is currently being assigned an object, which may cause unexpected behavior.

Apply this diff to correct the usage:

<Dropdown
  className="form-field"
  selected={{ code: topBoundary?.boundaryType }}
  disable={true}
  isMandatory={true}
  option={[{ key: 1, code: topBoundary?.boundaryType }]}
-  select={{ code: topBoundary?.boundaryType }}
+  select={() => {}}
  optionKey="code"
  t={t}
/>

Since the dropdown is disabled (disable={true}), the select prop may not be necessary and can be omitted.

📝 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
return (category in nationalRoles) ? (
<Dropdown
className="form-field"
selected={{ code: topBoundary?.boundaryType }}
disable={true}
isMandatory={true}
option={[{ key: 1, code: topBoundary?.boundaryType }]}
select={{ code:topBoundary?.boundaryType }}
optionKey="code"
t={t}
/>
) : (
return (category in nationalRoles) ? (
<Dropdown
className="form-field"
selected={{ code: topBoundary?.boundaryType }}
disable={true}
isMandatory={true}
option={[{ key: 1, code: topBoundary?.boundaryType }]}
select={() => {}}
optionKey="code"
t={t}
/>
) : (

@@ -331,7 +352,7 @@ function RoleTableComposer() {
const isUserAlreadyAssigned = HrmsData?.planSearchData?.filter((i) => i.employeeId === row.employeeId)?.length > 0 ? true : false;
const isUserAlreadyAssignedActive =
HrmsData?.planSearchData?.filter((i) => i.employeeId === row.employeeId)?.length > 0 &&
HrmsData?.planSearchData?.filter((i) => i.employeeId === row.employeeId)?.[0]?.active
HrmsData?.planSearchData?.filter((i) => i.employeeId === row.employeeId)?.[0]?.active
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

Use 'find' instead of 'filter' when checking for a single item

When determining if a user is already assigned, using find is more efficient than filter when you only need to locate a single item.

Apply this diff to optimize the code:

-const isUserAlreadyAssigned = HrmsData?.planSearchData?.filter((i) => i.employeeId === row.employeeId)?.length > 0 ? true : false;
-const isUserAlreadyAssignedActive =
-  HrmsData?.planSearchData?.filter((i) => i.employeeId === row.employeeId)?.length > 0 &&
-    HrmsData?.planSearchData?.filter((i) => i.employeeId === row.employeeId)?.[0]?.active
-    ? true
-    : false;

+const userPlanData = HrmsData?.planSearchData?.find((i) => i.employeeId === row.employeeId);
+const isUserAlreadyAssigned = !!userPlanData;
+const isUserAlreadyAssignedActive = userPlanData?.active === true;

This change simplifies the logic and improves performance by avoiding unnecessary iterations.

Committable suggestion was skipped due to low confidence.

@@ -411,7 +411,8 @@ const UserUpload = React.memo(() => {
setDownloadTemplateLoader(false);
return;
}
history.push(`/${window.contextPath}/employee/microplan/upload-user-success`, { fileName: fileName,message:"USER_DATA_UPLOAD_SUCCESSFUL" });
console.log("history",`/${window.contextPath}/employee/microplan/upload-user-success`)
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

Remove unnecessary console.log statement

The console.log statement appears to be left over from debugging and should be removed to clean up the code.

Apply this diff to remove the console.log statement:

-          console.log("history",`/${window.contextPath}/employee/microplan/upload-user-success`)
📝 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
console.log("history",`/${window.contextPath}/employee/microplan/upload-user-success`)

@@ -411,7 +411,8 @@ const UserUpload = React.memo(() => {
setDownloadTemplateLoader(false);
return;
}
history.push(`/${window.contextPath}/employee/microplan/upload-user-success`, { fileName: fileName,message:"USER_DATA_UPLOAD_SUCCESSFUL" });
console.log("history",`/${window.contextPath}/employee/microplan/upload-user-success`)
history.push(`/${window.contextPath}/employee/microplan/upload-user-success`, { fileName: fileName,message:"USER_DATA_UPLOAD_SUCCESSFUL",description:"The user data uploaded will be available in your microplan user assignment",back:"GO_BACK_TO_USER_MANAGEMENT",backlink:"/employee/microplan/user-management" });
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

Wrap static strings with the translation function t()

To support internationalization, wrap the static strings passed to message, description, and back with the t() function.

Apply this diff to internationalize the strings:

-          history.push(`/${window.contextPath}/employee/microplan/upload-user-success`, { fileName: fileName, message:"USER_DATA_UPLOAD_SUCCESSFUL", description:"The user data uploaded will be available in your microplan user assignment", back:"GO_BACK_TO_USER_MANAGEMENT", backlink:"/employee/microplan/user-management" });
+          history.push(`/${window.contextPath}/employee/microplan/upload-user-success`, { fileName: fileName, message: t("USER_DATA_UPLOAD_SUCCESSFUL"), description: t("The user data uploaded will be available in your microplan user assignment"), back: t("GO_BACK_TO_USER_MANAGEMENT"), backlink:"/employee/microplan/user-management" });
📝 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
history.push(`/${window.contextPath}/employee/microplan/upload-user-success`, { fileName: fileName,message:"USER_DATA_UPLOAD_SUCCESSFUL",description:"The user data uploaded will be available in your microplan user assignment",back:"GO_BACK_TO_USER_MANAGEMENT",backlink:"/employee/microplan/user-management" });
history.push(`/${window.contextPath}/employee/microplan/upload-user-success`, { fileName: fileName, message: t("USER_DATA_UPLOAD_SUCCESSFUL"), description: t("The user data uploaded will be available in your microplan user assignment"), back: t("GO_BACK_TO_USER_MANAGEMENT"), backlink:"/employee/microplan/user-management" });

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

📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE

📥 Commits

Files that changed from the base of the PR and between 0de3e8c and df75d96.

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

Pattern **/*.js: check

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

Pattern **/*.js: check

🪛 Biome
health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/components/UserAccess.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)


[error] 160-160: 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/Response.js (1)

29-29: LGTM: Approve dynamic description for PanelCard

The change to use state.description for the PanelCard's description prop is a good improvement. It allows for dynamic content based on the component's state, enhancing flexibility and reusability.

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

88-93: Approve simplification of hierarchy level logic with request for clarification.

The removal of commented-out code simplifies the logic and improves readability. Directly returning row?.hierarchyLevel is more straightforward.

Could you please clarify why the previous logic for determining the hierarchy level based on the category prop was implemented and then commented out? This information would be helpful for understanding the reasoning behind this change and ensuring that no important functionality has been lost.


Line range hint 1-183: Summary of UserAccess.js changes

The modifications to the UserAccess component align well with the PR objectives, enhancing employee-tagging validations and improving data management. Key improvements include:

  1. Addition of setData and nationalRoles props for better data handling and role-based access control.
  2. Enhanced data management in the usePlanSearchEmployeeWithTagging hook.
  3. Simplified logic for determining hierarchy levels.
  4. Improved flexibility of the DataTable component with the addition of the category prop.
  5. Enhanced functionality of the RoleTableComposer within the PopUp component.

These changes collectively improve the component's robustness and flexibility. Minor suggestions have been made for documentation improvements and addressing React best practices. Overall, the changes represent a significant enhancement to the microplan module's user access functionality.


160-160: ⚠️ Potential issue

Update PopUp children to address React best practices.

The addition of category and nationalRoles props to RoleTableComposer enhances its functionality. However, there are two React-related issues to address:

  1. Use JSX elements instead of passing children as a prop.
  2. Add a key prop to the element in the array.

Please update the PopUp component as follows:

- children={[<RoleTableComposer category={category} nationalRoles={nationalRoles} />]}
+ children={<RoleTableComposer key="roleComposer" category={category} nationalRoles={nationalRoles} />}

This change resolves both the children prop issue and the missing key warning.

Likely invalid or redundant comment.

🧰 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)


[error] 160-160: 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/UserUpload.js (1)

414-414: 🛠️ Refactor suggestion

Internationalize static strings for better localization support

While the addition of new properties in the history.push call improves the user experience, the static strings should be wrapped with the translation function t() to support internationalization.

Apply this diff to internationalize the strings:

-      history.push(`/${window.contextPath}/employee/microplan/upload-user-success`, { fileName: fileName,message:"USER_DATA_UPLOAD_SUCCESSFUL",description:"The user data uploaded will be available in your microplan user assignment",back:"GO_BACK_TO_USER_MANAGEMENT",backlink:"/employee/microplan/user-management" });
+      history.push(`/${window.contextPath}/employee/microplan/upload-user-success`, { fileName: fileName, message: t("USER_DATA_UPLOAD_SUCCESSFUL"), description: t("The user data uploaded will be available in your microplan user assignment"), back: t("GO_BACK_TO_USER_MANAGEMENT"), backlink: "/employee/microplan/user-management" });

Likely invalid or redundant comment.

@@ -4,7 +4,7 @@ import { useTranslation } from "react-i18next";
import RoleTableComposer from "./RoleTableComposer";
import DataTable from "react-data-table-component";

function UserAccess({ category }) {
function UserAccess({ category,setData,nationalRoles }) {
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)

Approve function signature update with documentation suggestion.

The addition of setData and nationalRoles props enhances the component's functionality, aligning with the PR objectives. This change improves data management and potentially supports role-based access control.

Consider adding JSDoc comments to document these new props, their types, and their purpose. For example:

/**
 * @param {Object} props
 * @param {string} props.category - The category of user access
 * @param {Function} props.setData - Function to set data externally
 * @param {Array} props.nationalRoles - Array of national roles
 */
function UserAccess({ category, setData, nationalRoles }) {
  // ...
}

@@ -33,6 +33,7 @@ function UserAccess({ category }) {
config: {
enabled: true,
select: (data) => {
setData(data);
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)

Approve data management enhancement with suggestion.

The addition of setData(data); improves data management by allowing external storage of fetched data. This change aligns well with the new setData prop and enhances the component's flexibility.

Consider adding a null check before calling setData to prevent potential errors:

if (setData && typeof setData === 'function') {
  setData(data);
}

This ensures that setData is defined and is a function before calling it, making the code more robust.

@@ -127,6 +134,7 @@ function UserAccess({ category }) {
<Button variation="secondary" label={t(`ASSIGN`)} icon={"AddIcon"} onClick={() => setShowPopUp(true)} />
</div>
<DataTable
category={category}
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)

Approve addition of category prop with documentation suggestion.

The addition of the category prop to the DataTable component enhances its flexibility and aligns with the role-based functionality improvements.

To improve maintainability, consider adding a comment or updating the component's documentation to explain how the category prop affects the DataTable's behavior or appearance. This will help future developers understand the purpose and impact of this prop.

@@ -27,6 +29,8 @@ const UserAccessWrapper = ({ onSelect, props: customProps }) => {
});

const [showToast, setShowToast] = useState(null);
const [showErrorToast, setShowErrorToast] = useState(null);
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)

Initialize showErrorToast to false instead of null

For boolean state variables, it's clearer and more conventional to initialize them to false rather than null to represent their inactive state.

Apply this diff:

-const [showErrorToast, setShowErrorToast] = useState(null);
+const [showErrorToast, setShowErrorToast] = useState(false);
📝 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 [showErrorToast, setShowErrorToast] = useState(null);
const [showErrorToast, setShowErrorToast] = useState(false);

@@ -25,7 +26,7 @@ const Response = () => {
cardStyles={{}}
className=""
customIcon=""
description="The user data uploaded will be available in your microplan user assignment section"
description={state.description}
Copy link
Contributor

Choose a reason for hiding this comment

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

add t

@@ -411,7 +411,7 @@ const UserUpload = React.memo(() => {
setDownloadTemplateLoader(false);
return;
}
history.push(`/${window.contextPath}/employee/microplan/upload-user-success`, { fileName: fileName,message:"USER_DATA_UPLOAD_SUCCESSFUL" });
history.push(`/${window.contextPath}/employee/microplan/upload-user-success`, { fileName: fileName,message:"USER_DATA_UPLOAD_SUCCESSFUL",description:"The user data uploaded will be available in your microplan user assignment",back:"GO_BACK_TO_USER_MANAGEMENT",backlink:"/employee/microplan/user-management" });
Copy link
Contributor

Choose a reason for hiding this comment

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

add localisation code

Copy link
Contributor

Choose a reason for hiding this comment

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

delete this file

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 (1)
health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/components/UserAccess.js (1)

Line range hint 103-115: Add a unique 'key' prop to list items rendered by the map function

When rendering lists using map, each item should have a unique key prop to help React identify which items have changed or moved.

Apply the following diff to add the key prop:

            {row?.jurisdiction?.map((item) => (
-              <div className="digit-tag-container userAccessCell">
+              <div key={item} className="digit-tag-container userAccessCell">
🧰 Tools
🪛 Biome

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

Files that changed from the base of the PR and between df75d96 and 413baf0.

📒 Files selected for processing (5)
  • health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/components/Response.js (4 hunks)
  • health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/components/RoleTableComposer.js (10 hunks)
  • health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/components/UserAccess.js (7 hunks)
  • health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/components/UserAccessWrapper.js (5 hunks)
  • health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/pages/employee/index.js (1 hunks)
🧰 Additional context used
📓 Path-based instructions (5)
health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/components/Response.js (1)

Pattern **/*.js: check

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/components/UserAccessWrapper.js (1)

Pattern **/*.js: check

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

Pattern **/*.js: check

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

[error] 300-300: Unnecessary use of boolean literals in conditional expression.

Simplify your code by directly assigning the result without using a ternary operator.
If your goal is negation, you may use the logical NOT (!) or double NOT (!!) operator for clearer and concise code.
Check for more details about NOT operator.
Unsafe fix: Remove the conditional expression with

(lint/complexity/noUselessTernary)


[error] 332-332: Unnecessary use of boolean literals in conditional expression.

Simplify your code by directly assigning the result without using a ternary operator.
If your goal is negation, you may use the logical NOT (!) or double NOT (!!) operator for clearer and concise code.
Check for more details about NOT operator.
Unsafe fix: Remove the conditional expression with

(lint/complexity/noUselessTernary)

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

[error] 103-103: 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] 160-160: Avoid passing children using a prop

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

(lint/correctness/noChildrenProp)


[error] 160-160: 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/UserAccessWrapper.js

[error] 20-20: This let declares a variable that is only assigned once.

'mpRolesArray' is never reassigned.

Safe fix: Use const instead.

(lint/style/useConst)

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

Line range hint 1-62: Overall assessment: Improved component with minor suggestions.

The changes to the Response component significantly enhance its flexibility and adaptability. Key improvements include:

  • Dynamic state management for navigation and content
  • Improved visual consistency in the UI elements
  • More flexible routing using state variables

While these changes are positive, there are a few minor suggestions to consider:

  1. Resolve the duplicate Button import issue
  2. Simplify the backlink assignment using the nullish coalescing operator
  3. Add translation support for the description
  4. Use camelCase for the icon prop in the Button component

Implementing these suggestions will further improve the component's consistency and maintainability.


5-5: ⚠️ Potential issue

Resolve duplicate Button import.

The addition of this import doesn't address the duplicate import issue mentioned in a previous review. There are still two Button imports from different packages:

  1. @egovernments/digit-ui-components (newly added)
  2. @egovernments/digit-ui-react-components (existing, not shown in this diff)

This could lead to confusion and potential bugs.

Please remove one of the Button imports and ensure that the correct Button component is used throughout the file. Apply this diff to resolve the issue:

import { ActionBar, SubmitBar, ArrowLeft, ArrowForward } from "@egovernments/digit-ui-react-components";
-import { Button } from "@egovernments/digit-ui-components";
import { PanelCard } from "@egovernments/digit-ui-components";
-import { Button } from "@egovernments/digit-ui-react-components";

Choose the appropriate import based on which Button component you intend to use in the component.

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

67-67: Approved: Using translation function for column names enhances internationalization

The changes to use t() for column names like "NAME", "EMAIL", and "CONTACT_NUMBER" improve the application's support for multiple languages.

Also applies to: 74-74, 79-79


86-86: Approved: Translating additional column names for better localization

Applying the t() function to "ADMINISTRATIVE-HIERARCHY" and "ADMINISTRATIVE-BOUNDARY" ensures these column headers are localized, enhancing the user experience for non-English speakers.

Also applies to: 98-98

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

17-17: Initialization of 'data' state variable is appropriate

The data state variable is correctly initialized to null.


63-71: Logic in 'handleNext' function is correct

The updated handleNext function correctly checks if data is null and whether the current role is a national role before incrementing internalKey.


133-133: 'Stepper' component is correctly configured

The Stepper component uses the appropriate props and is set up correctly.


138-142: 'UserAccess' component is correctly utilized

Props passed to the UserAccess component are appropriate and align with its expected interface.


179-179: Default export of 'UserAccessWrapper' is correct

The UserAccessWrapper component is properly exported as the default export.

Copy link
Contributor

@nabeelmd-eGov nabeelmd-eGov left a comment

Choose a reason for hiding this comment

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

looks fine to me

coderabbitai[bot]
coderabbitai bot previously requested changes Oct 21, 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

📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE

📥 Commits

Files that changed from the base of the PR and between 413baf0 and 741342e.

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

Pattern **/*.js: check

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

[error] 300-300: Unnecessary use of boolean literals in conditional expression.

Simplify your code by directly assigning the result without using a ternary operator.
If your goal is negation, you may use the logical NOT (!) or double NOT (!!) operator for clearer and concise code.
Check for more details about NOT operator.
Unsafe fix: Remove the conditional expression with

(lint/complexity/noUselessTernary)


[error] 332-332: Unnecessary use of boolean literals in conditional expression.

Simplify your code by directly assigning the result without using a ternary operator.
If your goal is negation, you may use the logical NOT (!) or double NOT (!!) operator for clearer and concise code.
Check for more details about NOT operator.
Unsafe fix: Remove the conditional expression with

(lint/complexity/noUselessTernary)

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

[error] 103-103: 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] 160-160: Avoid passing children using a prop

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

(lint/correctness/noChildrenProp)


[error] 160-160: 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/UserAccessWrapper.js

[error] 20-20: This let declares a variable that is only assigned once.

'mpRolesArray' is never reassigned.

Safe fix: Use const instead.

(lint/style/useConst)

🔇 Additional comments (12)
health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/components/UserAccessWrapper.js (4)

17-17: Initialization of 'data' state variable is appropriate

The data state is correctly initialized using useState(null), which allows for handling cases where no data is present.


63-71: Logical flow in 'handleNext' function is correctly implemented

The handleNext function appropriately checks if data is null and if the current role is a national role before deciding whether to proceed to the next step or show an error toast. This ensures that users cannot proceed without providing necessary data for certain roles.


133-133: Usage of 'Stepper' component is correct

The Stepper component is properly configured with the custom steps, current step, click handler, and direction. This will render the vertical stepper as intended.


138-142: Props passed to 'UserAccess' component are appropriate

The UserAccess component receives the necessary props: category, setData, and nationalRoles, ensuring it has all required data for proper functionality.

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

10-10: Function signature updated appropriately.

The addition of the nationalRoles prop to RoleTableComposer aligns with its usage within the component.


15-15: Initialization of selectedData is correct.

The selectedData variable is correctly initialized from session storage or set to an empty array.


30-30: Top boundary identification logic is appropriate.

Fetching the topBoundary where parentBoundaryType is null is correctly implemented.


50-53: Conditional assignment of selectedHierarchy is correct.

The logic for setting selectedHierarchy based on whether nationalRoles includes the category is sound.


83-83: Filtering selectedBoundaries aligns with requirements.

The code properly filters filteredBoundary to obtain selectedBoundaries.


124-128: State update in handleHierarchyChange is correctly handled.

The function correctly updates the state immutably, ensuring consistent data updates.


182-184: Clearing selectedBoundaries when no boundaries are selected.

The logic effectively resets selectedBoundaries to an empty array when the selection is cleared.


213-215: Updating selectedBoundaries with selected events.

The code accurately updates selectedBoundaries with the new selections from the event.

Copy link
Contributor

@nabeelmd-eGov nabeelmd-eGov left a comment

Choose a reason for hiding this comment

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

looks fine to me

Copy link
Contributor

@nipunarora-eGov nipunarora-eGov left a comment

Choose a reason for hiding this comment

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

Approving since critical comments are taken care of

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