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

card order and link order #1443

Merged
merged 8 commits into from
Oct 1, 2024
Merged

card order and link order #1443

merged 8 commits into from
Oct 1, 2024

Conversation

mithunhegde-egov
Copy link

@mithunhegde-egov mithunhegde-egov commented Sep 30, 2024

sorting the card and links based on the local config

Summary by CodeRabbit

  • New Features

    • Introduced a configurable ordering system for employee sidebar cards and links, enhancing navigation and usability.
    • Implemented sorting functionality to display modules and links in a predefined order based on user roles.
    • Added a new configuration file to specify the display order of cards and links for HRMS and PGR modules.
  • Bug Fixes

    • Added safety checks to prevent errors during the sorting process for undefined labels.

@mithunhegde-egov mithunhegde-egov requested a review from a team as a code owner September 30, 2024 08:16
Copy link
Contributor

coderabbitai bot commented Sep 30, 2024

📝 Walkthrough
📝 Walkthrough

Walkthrough

The changes introduce a new configuration for sorting employee sidebar cards and links in the RoleBasedEmployeeHome.js component. A new file, card-link-order.js, defines the order of display for modules and their associated links. The sorting functionality is implemented to ensure that the sidebar reflects the specified order, enhancing the organization of the user interface.

Changes

File Change Summary
micro-ui/web/micro-ui-internals/packages/modules/core/src/components/RoleBasedEmployeeHome.js, micro-ui/web/micro-ui-internals/packages/modules/core/src/config/card-link-order.js Introduced orderConfig for sorting sidebar cards and links; added sortCardAndLink function to handle sorting based on the new configuration.

Possibly related PRs

  • side bar with correct order  #1394: The changes in the EmployeeSideBar component involve sorting sidebar items by their orderNumber, which is conceptually similar to the sorting introduced in the RoleBasedEmployeeHome.js file using orderConfig.

Suggested reviewers

  • jagankumar-egov

Poem

🐰 In the land of code where rabbits play,
Order and structure brighten the day.
With cards and links all lined in a row,
Sorting them nicely, watch the flow!
Hops of joy in the UI's new dance,
Thanks to the changes, give it a chance! 🌟


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

📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE

📥 Commits

Files that changed from the base of the PR and between 2f29dec and 33e609d.

📒 Files selected for processing (2)
  • micro-ui/web/micro-ui-internals/packages/modules/core/src/components/RoleBasedEmployeeHome.js (2 hunks)
  • micro-ui/web/micro-ui-internals/packages/modules/core/src/config/card-link-order.js (1 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
micro-ui/web/micro-ui-internals/packages/modules/core/src/components/RoleBasedEmployeeHome.js (1)

Pattern **/*.js: check

micro-ui/web/micro-ui-internals/packages/modules/core/src/config/card-link-order.js (1)

Pattern **/*.js: check

🔇 Additional comments (1)
micro-ui/web/micro-ui-internals/packages/modules/core/src/config/card-link-order.js (1)

1-20: LGTM: Well-structured configuration object

The orderConfig object is well-structured, allowing for easy management of card and link orders. The use of a constant export ensures the configuration remains immutable during runtime.

Comment on lines 3 to 6
"cardorder": {
"HRMS": 2,
"PGR": 1
},
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)

Consider including all relevant modules in cardorder

The cardorder property currently only defines the order for "HRMS" and "PGR" modules. If there are more modules in the system, consider including them here to ensure a comprehensive ordering configuration.

Comment on lines 1 to 20
export const orderConfig={
"order": {
"cardorder": {
"HRMS": 2,
"PGR": 1
},
"linkorder": {
"HRMS": {
"Create Employee": 1,
"Search Employee": 2,
"Configure Masters": 3
},
"PGR": {
"New Complaint": 1,
"Inbox": 2,
"Configure Masters": 3
}
}
}
}
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)

Consider enhancing configuration flexibility

While the current structure works well, consider the following improvements for better flexibility and maintainability:

  1. Implement a mechanism to load this configuration from an external source (e.g., a JSON file or environment variables). This would allow for easier updates without code changes.
  2. Consider adding support for environment-specific configurations, allowing different orderings for development, staging, and production environments.

These enhancements would make the system more adaptable to changing requirements without necessitating code modifications.

Comment on lines 95 to 99
const orderA = (orderConfig?.order?.linkorder?.[module]?.[labelA]) || null;
const orderB = (orderConfig?.order?.linkorder?.[module]?.[labelB]) || null;


return orderA - orderB;
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 null values in link sorting to ensure consistent ordering.

When orderA or orderB are null, subtracting them can lead to unintended sorting behavior. Consider defaulting these values to Number.MAX_SAFE_INTEGER, similar to how it's handled in module sorting. This ensures that links without a specified order are placed at the end.

Apply this diff to adjust the handling of null values:

-          const orderA = (orderConfig?.order?.linkorder?.[module]?.[labelA]) || null;
-          const orderB = (orderConfig?.order?.linkorder?.[module]?.[labelB]) || null;
+          const orderA = (orderConfig?.order?.linkorder?.[module]?.[labelA]) || Number.MAX_SAFE_INTEGER;
+          const orderB = (orderConfig?.order?.linkorder?.[module]?.[labelB]) || Number.MAX_SAFE_INTEGER;
📝 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 orderA = (orderConfig?.order?.linkorder?.[module]?.[labelA]) || null;
const orderB = (orderConfig?.order?.linkorder?.[module]?.[labelB]) || null;
return orderA - orderB;
const orderA = (orderConfig?.order?.linkorder?.[module]?.[labelA]) || Number.MAX_SAFE_INTEGER;
const orderB = (orderConfig?.order?.linkorder?.[module]?.[labelB]) || Number.MAX_SAFE_INTEGER;
return orderA - orderB;

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 33e609d and 27deece.

📒 Files selected for processing (2)
  • micro-ui/web/micro-ui-internals/packages/modules/core/src/components/RoleBasedEmployeeHome.js (4 hunks)
  • micro-ui/web/micro-ui-internals/packages/modules/core/src/config/card-link-order.js (1 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
micro-ui/web/micro-ui-internals/packages/modules/core/src/components/RoleBasedEmployeeHome.js (1)

Pattern **/*.js: check

micro-ui/web/micro-ui-internals/packages/modules/core/src/config/card-link-order.js (1)

Pattern **/*.js: check

🔇 Additional comments (6)
micro-ui/web/micro-ui-internals/packages/modules/core/src/config/card-link-order.js (2)

1-20: LGTM: Well-structured configuration object

The orderConfig object is well-organized with a clear separation of concerns between card and link orders. The use of a constant for configuration is a good practice for maintainability.


3-6: Consider including all relevant modules in cardorder

The cardorder property currently only defines the order for "HRMS" and "PGR" modules. If there are more modules in the system, consider including them here to ensure a comprehensive ordering configuration.

micro-ui/web/micro-ui-internals/packages/modules/core/src/components/RoleBasedEmployeeHome.js (4)

6-6: Import orderConfig correctly for sorting functionality

The import statement correctly includes orderConfig from the configuration file, enabling the sorting of cards and links based on local settings.


16-16: Initialize sortedConfigEmployeesSidebar appropriately

Initializing sortedConfigEmployeesSidebar to null before assigning it ensures clarity in variable usage and prevents potential reference errors.


66-66: Ensure displayName is defined for link items

Adding displayName: item.displayName to the link object allows the sorting function to access the display names of links accurately. Ensure that item.displayName is always defined to prevent any undefined value issues during sorting.


79-112: Efficient implementation of sortCardAndLink function

The sortCardAndLink function effectively sorts modules and their corresponding links based on the orderConfig. The use of default values like Number.MAX_SAFE_INTEGER and safety checks for undefined labels enhances the robustness of the sorting mechanism.

Comment on lines 7 to 18
"linkorder": {
"HRMS": {
"HRMS_Create_Employee": 1,
"HRMSInbox": 2,
"Configure_master": 3
},
"PGR": {
"Create_Complaints": 1,
"ComplaintsInbox": 2,
"Configure_master": 3
}
}
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

Well-organized linkorder structure with room for improvement

The linkorder property effectively organizes links for each module with sequential numbering, allowing for easy insertion of new links if needed.

Consider the following improvements:

  1. Extract common links like "Configure Masters" into a separate configuration object for reusability and consistency across modules.
  2. Implement a mechanism to load this configuration from an external source (e.g., a JSON file or environment variables) for easier updates without code changes.
  3. Add support for environment-specific configurations, allowing different orderings for development, staging, and production environments.

These enhancements would make the system more adaptable to changing requirements without necessitating code modifications.

};

if(isMultiRootTenant){
console.log("module data is",configEmployeeSideBar);
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)

Remove debugging console.log statement

Consider removing the console.log statement used for debugging:

-    console.log("module data is",configEmployeeSideBar);

Removing it will clean up the console output in production environments.

📝 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("module data is",configEmployeeSideBar);

nabeelmd-eGov
nabeelmd-eGov previously approved these changes Sep 30, 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 aafe8d7 and 9c183a5.

📒 Files selected for processing (1)
  • micro-ui/web/micro-ui-internals/packages/modules/core/src/components/RoleBasedEmployeeHome.js (4 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
micro-ui/web/micro-ui-internals/packages/modules/core/src/components/RoleBasedEmployeeHome.js (1)

Pattern **/*.js: check

🔇 Additional comments (3)
micro-ui/web/micro-ui-internals/packages/modules/core/src/components/RoleBasedEmployeeHome.js (3)

141-144: Use module-specific icons instead of hardcoded "SupervisorAccount"

Currently, the icon property is hardcoded to "SupervisorAccount" for all modules. To enhance the user experience and accurately represent each module, consider using the moduleData.icon property, which holds the specific icon for each module.

Apply this diff to use dynamic icons:

-      // Icon: moduleData?.icon,
-      icon: "SupervisorAccount",
+      icon: moduleData.icon,

105-107: Handle null values in module sorting to ensure consistent ordering

When cardOrderA or cardOrderB are null, subtracting them can lead to unintended sorting behavior. Consider defaulting these values to Number.MAX_SAFE_INTEGER to ensure that modules without a specified order are placed at the end.

Apply this diff to adjust the handling of null values:

-        const cardOrderA = mdmsOrderData?.find(item => item.moduleType === "card" && item.name === a)?.order || null;
-        const cardOrderB = mdmsOrderData?.find(item => item.moduleType === "card" && item.name === b)?.order || null;
+        const cardOrderA = mdmsOrderData?.find(item => item.moduleType === "card" && item.name === a)?.order || Number.MAX_SAFE_INTEGER;
+        const cardOrderB = mdmsOrderData?.find(item => item.moduleType === "card" && item.name === b)?.order || Number.MAX_SAFE_INTEGER;

116-117: Handle null values in link sorting to ensure consistent ordering

When orderA or orderB are null, subtracting them can lead to unintended sorting behavior. Consider defaulting these values to Number.MAX_SAFE_INTEGER to ensure that links without a specified order are placed at the end.

Apply this diff to adjust the handling of null values:

-          const orderA = mdmsOrderData?.find(item => item.moduleType === "link" && item.name === `${module}.${labelA.replace(/\s+/g, '_')}`)?.order || null;
-          const orderB = mdmsOrderData?.find(item => item.moduleType === "link" && item.name === `${module}.${labelB.replace(/\s+/g, '_')}`)?.order || null;
+          const orderA = mdmsOrderData?.find(item => item.moduleType === "link" && item.name === `${module}.${labelA.replace(/\s+/g, '_')}`)?.order || Number.MAX_SAFE_INTEGER;
+          const orderB = mdmsOrderData?.find(item => item.moduleType === "link" && item.name === `${module}.${labelB.replace(/\s+/g, '_')}`)?.order || Number.MAX_SAFE_INTEGER;

@jagankumar-egov jagankumar-egov merged commit e07ca0c into develop Oct 1, 2024
2 checks passed
@jagankumar-egov jagankumar-egov deleted the cards-order branch October 1, 2024 08:20
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