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

Rolebasedlanding updated #1577

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from
Open

Conversation

mithunhegde-egov
Copy link

@mithunhegde-egov mithunhegde-egov commented Oct 19, 2024

role based landing page decouple from modules

Summary by CodeRabbit

  • New Features

    • Introduced dynamic module-specific links for PGR and HRMS, including "how it works" and user manuals.
    • Enhanced sidebar configuration to display filtered links based on module settings.
  • Bug Fixes

    • Updated rendering logic to correctly reference the new configuration for sidebar items.

@mithunhegde-egov mithunhegde-egov requested a review from a team as a code owner October 19, 2024 06:20
Copy link
Contributor

coderabbitai bot commented Oct 19, 2024

📝 Walkthrough

Walkthrough

The changes in this pull request primarily focus on the RoleBasedEmployeeHome component within the specified file. A new constant MODULE_CONFIG has been introduced to hold configuration details for different modules, and a new data fetching hook, useCustomMDMS, retrieves module configuration data. Additionally, two utility functions, getLinkByType and getFilteredLinks, have been added to manage link retrieval and filtering. The rendering logic for the sidebar and module card props has been updated to utilize these new functionalities, enhancing the component's dynamic link management.

Changes

File Change Summary
micro-ui/web/micro-ui-internals/packages/modules/core/src/components/RoleBasedEmployeeHome.js - Added constant MODULE_CONFIG for module configuration details.
- Introduced useCustomMDMS for data fetching.
- Added utility functions getLinkByType and getFilteredLinks.
- Updated rendering logic for sidebar and module card props to use filtered links.

Possibly related PRs

Suggested reviewers

  • nabeelmd-eGov
  • jagankumar-egov

🐰 In the meadow, hopping free,
New links added, oh what glee!
Configuration now in sight,
Dynamic changes, pure delight!
With buttons bright and functions new,
Role-based magic, just for you! 🌼


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 4

📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE

📥 Commits

Files that changed from the base of the PR and between a26c1b6 and 991df36.

📒 Files selected for processing (1)
  • micro-ui/web/micro-ui-internals/packages/modules/core/src/components/RoleBasedEmployeeHome.js (5 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

🪛 Biome
micro-ui/web/micro-ui-internals/packages/modules/core/src/components/RoleBasedEmployeeHome.js

[error] 229-229: 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] 188-188: 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 +9 to +20
const MODULE_CONFIG = {
PGR: {
howItWorksLink: "HOW_IT_WORKS_PGR",
userManualLink: "PGR_INFO_LINK",
},
HRMS: {
howItWorksLink: "HOW_IT_WORKS_HRMS",
userManualLink: "HRMS_INFO_LINK",
},
// Add more modules as needed here
};

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 the unused MODULE_CONFIG constant

The MODULE_CONFIG constant declared here is not being used anywhere in the code. Removing unused variables helps keep the codebase clean and maintainable.

Apply this diff to remove the unused constant:

-const MODULE_CONFIG = {
-  PGR: {
-    howItWorksLink: "HOW_IT_WORKS_PGR",
-    userManualLink: "PGR_INFO_LINK",
-  },
-  HRMS: {
-    howItWorksLink: "HOW_IT_WORKS_HRMS",
-    userManualLink: "HRMS_INFO_LINK",
-  },
-  // Add more modules as needed here
-};
📝 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 MODULE_CONFIG = {
PGR: {
howItWorksLink: "HOW_IT_WORKS_PGR",
userManualLink: "PGR_INFO_LINK",
},
HRMS: {
howItWorksLink: "HOW_IT_WORKS_HRMS",
userManualLink: "HRMS_INFO_LINK",
},
// Add more modules as needed here
};

]
: null,
};

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

Include a key prop in the mapped component

When rendering a list of components using map, each root element should have a unique key prop.

Apply this diff to add the key prop to LandingPageCard:

-    return <LandingPageCard buttonSize={"medium"} {...propsForModuleCard} />;
+    return <LandingPageCard key={current} buttonSize={"medium"} {...propsForModuleCard} />;

Committable suggestion was skipped due to low confidence.

Comment on lines +188 to +199
<div>{t(Digit.Utils.locale.getTransformedLocale(`MODULE_CARD_DESC_${current}`))}</div>,
userManual && (
<Button
variation="teritiary"
label={userManual?.label}
icon={userManual?.icon}
type="button"
size={"medium"}
onClick={() => window.open(userManual?.link, "_blank")}
style={{ padding: "0px" }}
/>
),
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

Add key props to elements in arrays

When rendering arrays of React elements, each element should have a unique key prop to help React identify which items have changed, are added, or are removed.

Apply this diff to add key props to the elements in centreChildren:

       centreChildren: [
-        <div>{t(Digit.Utils.locale.getTransformedLocale(`MODULE_CARD_DESC_${current}`))}</div>,
+        <div key="module-description">{t(Digit.Utils.locale.getTransformedLocale(`MODULE_CARD_DESC_${current}`))}</div>,
         userManual && (
+          <Button
+            key="user-manual-button"
             variation="teritiary"
             label={userManual?.label}
             icon={userManual?.icon}
             type="button"
             size={"medium"}
             onClick={() => window.open(userManual?.link, "_blank")}
             style={{ padding: "0px" }}
-          />
+          />,
         ),
       ],
📝 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
<div>{t(Digit.Utils.locale.getTransformedLocale(`MODULE_CARD_DESC_${current}`))}</div>,
userManual && (
<Button
variation="teritiary"
label={userManual?.label}
icon={userManual?.icon}
type="button"
size={"medium"}
onClick={() => window.open(userManual?.link, "_blank")}
style={{ padding: "0px" }}
/>
),
<div key="module-description">{t(Digit.Utils.locale.getTransformedLocale(`MODULE_CARD_DESC_${current}`))}</div>,
userManual && (
<Button
key="user-manual-button"
variation="teritiary"
label={userManual?.label}
icon={userManual?.icon}
type="button"
size={"medium"}
onClick={() => window.open(userManual?.link, "_blank")}
style={{ padding: "0px" }}
/>,
),
🧰 Tools
🪛 Biome

[error] 188-188: 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 +85 to +106
// Function to get links by type from the module configuration
const getLinkByType = (moduleData, type) => {
const moduleConfig = moduleConfigData.find((config) => config.moduleName === moduleData.module);
if (!moduleConfig) return null;

const linkKey = moduleConfig[type];
return moduleData?.links?.find((item) => item?.displayName === linkKey);
};

// Function to filter links dynamically based on module config
const getFilteredLinks = (moduleData) => {
const moduleConfig = moduleConfigData.find((config) => config.moduleName === moduleData.module);
return moduleData.links?.filter((item) => {
const displayName = item.displayName;
const isNotConfigureMaster = displayName !== "Configure_master";
const isNotHowItWorks = displayName !== moduleConfig?.howItWorksLink;
const isNotUserManual = displayName !== moduleConfig?.userManualLink;

return isNotConfigureMaster && isNotHowItWorks && isNotUserManual;
});
};

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

Ensure moduleConfigData is defined before usage

In the functions getLinkByType and getFilteredLinks, moduleConfigData is used without checking if it's defined. If moduleConfigData is undefined (e.g., before the data is loaded), this could lead to a runtime error.

Consider defaulting moduleConfigData to an empty array if it's undefined:

+  const safeModuleConfigData = moduleConfigData || [];

  // Function to get links by type from the module configuration
  const getLinkByType = (moduleData, type) => {
-   const moduleConfig = moduleConfigData.find((config) => config.moduleName === moduleData.module);
+   const moduleConfig = safeModuleConfigData.find((config) => config.moduleName === moduleData.module);
    if (!moduleConfig) return null;

    const linkKey = moduleConfig[type];
    return moduleData?.links?.find((item) => item?.displayName === linkKey);
  };

  // Function to filter links dynamically based on module config
  const getFilteredLinks = (moduleData) => {
-   const moduleConfig = moduleConfigData.find((config) => config.moduleName === moduleData.module);
+   const moduleConfig = safeModuleConfigData.find((config) => config.moduleName === moduleData.module);
    return moduleData.links?.filter((item) => {
      const displayName = item.displayName;
      const isNotConfigureMaster = displayName !== "Configure_master";
      const isNotHowItWorks = displayName !== moduleConfig?.howItWorksLink;
      const isNotUserManual = displayName !== moduleConfig?.userManualLink;

      return isNotConfigureMaster && isNotHowItWorks && isNotUserManual;
    });
  };
📝 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
// Function to get links by type from the module configuration
const getLinkByType = (moduleData, type) => {
const moduleConfig = moduleConfigData.find((config) => config.moduleName === moduleData.module);
if (!moduleConfig) return null;
const linkKey = moduleConfig[type];
return moduleData?.links?.find((item) => item?.displayName === linkKey);
};
// Function to filter links dynamically based on module config
const getFilteredLinks = (moduleData) => {
const moduleConfig = moduleConfigData.find((config) => config.moduleName === moduleData.module);
return moduleData.links?.filter((item) => {
const displayName = item.displayName;
const isNotConfigureMaster = displayName !== "Configure_master";
const isNotHowItWorks = displayName !== moduleConfig?.howItWorksLink;
const isNotUserManual = displayName !== moduleConfig?.userManualLink;
return isNotConfigureMaster && isNotHowItWorks && isNotUserManual;
});
};
const safeModuleConfigData = moduleConfigData || [];
// Function to get links by type from the module configuration
const getLinkByType = (moduleData, type) => {
const moduleConfig = safeModuleConfigData.find((config) => config.moduleName === moduleData.module);
if (!moduleConfig) return null;
const linkKey = moduleConfig[type];
return moduleData?.links?.find((item) => item?.displayName === linkKey);
};
// Function to filter links dynamically based on module config
const getFilteredLinks = (moduleData) => {
const moduleConfig = safeModuleConfigData.find((config) => config.moduleName === moduleData.module);
return moduleData.links?.filter((item) => {
const displayName = item.displayName;
const isNotConfigureMaster = displayName !== "Configure_master";
const isNotHowItWorks = displayName !== moduleConfig?.howItWorksLink;
const isNotUserManual = displayName !== moduleConfig?.userManualLink;
return isNotConfigureMaster && isNotHowItWorks && isNotUserManual;
});
};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant