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

side bar with correct order #1394

Merged
merged 4 commits into from
Sep 18, 2024
Merged

side bar with correct order #1394

merged 4 commits into from
Sep 18, 2024

Conversation

mithunhegde-egov
Copy link

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

side bar url redirection

@mithunhegde-egov mithunhegde-egov requested a review from a team as a code owner September 17, 2024 11:22
Copy link
Contributor

coderabbitai bot commented Sep 17, 2024

Walkthrough

Walkthrough

The changes in the EmployeeSideBar component involve a significant refactor aimed at improving its logic and structure. A sorting mechanism for sidebar items based on orderNumber has been implemented, along with the introduction of a MediaQuery component for responsive design. The rendering conditions have been updated to check for keys in the configEmployeeSideBar object, and the logic for constructing URLs has been simplified. These updates enhance the overall functionality and maintainability of the component.

Changes

File Change Summary
micro-ui/web/micro-ui-internals/packages/modules/core/src/components/TopBarSideBar/SideBar/EmployeeSideBar.js Refactored to include sorting of sidebar items by orderNumber, introduced transformData adjustments, updated rendering conditions, optimized icon extraction, and added MediaQuery for responsiveness.

Possibly related PRs

  • side bar #1384: This PR modifies the EmployeeSideBar.js file to enhance navigation logic for multi-root tenant scenarios, which is directly related to the changes made in the main PR that also focuses on the EmployeeSideBar component and its handling of multi-tenant logic.

Suggested reviewers

  • jagankumar-egov

🐰 In the meadow of code where bunnies hop free,
A sidebar transformed, oh what joy to see!
With items now sorted, and views that adapt,
Multi-tenants cheer, their needs all unwrapped!
Hopping through changes, so tidy and bright,
Our EmployeeSideBar shines with delight! 🐇✨


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 generate interesting stats about this repository and render them as a table.
    -- @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.

Tip

Early access features: enabled

We are currently testing the following features in early access:

  • OpenAI o1 for code reviews: OpenAI's new o1 model is being tested for code reviews. This model has advanced reasoning capabilities and can provide more nuanced feedback on your code.

Note:

  • You can enable or disable early access features from the CodeRabbit UI or by updating the CodeRabbit configuration 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: 0

Outside diff range and nitpick comments (1)
micro-ui/web/micro-ui-internals/packages/modules/core/src/components/TopBarSideBar/SideBar/EmployeeSideBar.js (1)

93-94: Consider moving the hostUrl declaration inside the else block

Since hostUrl is not used within the if (isMultiRootTenant) block, you can improve clarity by declaring it only where it's needed.

Apply this diff to adjust the hostUrl declaration:

     let updatedUrl = null;
     if(isMultiRootTenant){
       url = url.replace("/sandbox-ui/employee", `/sandbox-ui/${tenantId}/employee`);
       updatedUrl = url;
     }
     else{
+      const hostUrl = window.location.origin;
       updatedUrl = DIGIT_UI_CONTEXTS?.every((e) => url?.indexOf(`/${e}`) === -1) ? hostUrl + "/employee/" + url : hostUrl + url;
     }
Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 49481a4 and 50c9cf5.

Files selected for processing (1)
  • micro-ui/web/micro-ui-internals/packages/modules/core/src/components/TopBarSideBar/SideBar/EmployeeSideBar.js (1 hunks)
Additional context used
Path-based instructions (1)
micro-ui/web/micro-ui-internals/packages/modules/core/src/components/TopBarSideBar/SideBar/EmployeeSideBar.js (1)

Pattern **/*.js: check

Additional comments not posted (1)
micro-ui/web/micro-ui-internals/packages/modules/core/src/components/TopBarSideBar/SideBar/EmployeeSideBar.js (1)

94-94: LGTM

The assignment updatedUrl = url; correctly adjusts the URL for multi-root tenant scenarios. This ensures that the navigation URL reflects the tenant-specific path without adding unnecessary prefixes.

coderabbitai[bot]
coderabbitai bot previously approved these changes Sep 17, 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

Outside diff range and nitpick comments (1)
micro-ui/web/micro-ui-internals/packages/modules/core/src/components/TopBarSideBar/SideBar/EmployeeSideBar.js (1)

12-12: Unused mobileView Prop

The mobileView prop is destructured from props but is not used anywhere in the component. Consider removing it if it's unnecessary or implement its intended functionality.

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 50c9cf5 and 6927ee9.

Files selected for processing (1)
  • micro-ui/web/micro-ui-internals/packages/modules/core/src/components/TopBarSideBar/SideBar/EmployeeSideBar.js (2 hunks)
Additional context used
Path-based instructions (1)
micro-ui/web/micro-ui-internals/packages/modules/core/src/components/TopBarSideBar/SideBar/EmployeeSideBar.js (1)

Pattern **/*.js: check

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

Outside diff range and nitpick comments (2)
micro-ui/web/micro-ui-internals/packages/modules/core/src/components/TopBarSideBar/SideBar/EmployeeSideBar.js (2)

75-76: Use a More Robust Check for leftIcon

Currently, the condition checks if item?.leftIcon is not an empty string. This might overlook cases where leftIcon is null or undefined. To ensure all falsy values are handled, consider modifying the condition to check for the existence of leftIcon.

Apply this diff to make the check more robust:

-  if (key === "item" && item?.leftIcon !== "") {
+  if (key === "item" && item?.leftIcon) {

Line range hint 126-140: Ensure Consistent Indentation and Formatting

There are inconsistencies in the indentation within the JSX returned by the component. Consistent formatting improves readability and maintainability. Consider using a formatter like Prettier to automatically format the code.

Example of formatted code:

return (
  <MediaQuery minWidth={768}>
    <Sidebar
      items={transformedData}
      hideAccessbilityTools={true}
      onSelect={({ item, index, parentIndex }) => onItemSelect({ item, index, parentIndex })}
      theme={"dark"}
      variant={"primary"}
      transitionDuration={""}
      className=""
      styles={{}}
      expandedWidth=""
      collapsedWidth=""
      onBottomItemClick={() => {}}
    />
  </MediaQuery>
);
Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 6927ee9 and 597e9ec.

Files selected for processing (1)
  • micro-ui/web/micro-ui-internals/packages/modules/core/src/components/TopBarSideBar/SideBar/EmployeeSideBar.js (2 hunks)
Additional context used
Path-based instructions (1)
micro-ui/web/micro-ui-internals/packages/modules/core/src/components/TopBarSideBar/SideBar/EmployeeSideBar.js (1)

Pattern **/*.js: check

coderabbitai[bot]
coderabbitai bot previously approved these changes Sep 18, 2024
Swathi-eGov
Swathi-eGov previously approved these changes Sep 18, 2024
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

@nabeelmd-eGov nabeelmd-eGov changed the title side bar bug side bar with correct order Sep 18, 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: 3

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 597e9ec and 28a517c.

Files selected for processing (1)
  • micro-ui/web/micro-ui-internals/packages/modules/core/src/components/TopBarSideBar/SideBar/EmployeeSideBar.js (5 hunks)
Additional context used
Path-based instructions (1)
micro-ui/web/micro-ui-internals/packages/modules/core/src/components/TopBarSideBar/SideBar/EmployeeSideBar.js (1)

Pattern **/*.js: check

Additional comments not posted (1)
micro-ui/web/micro-ui-internals/packages/modules/core/src/components/TopBarSideBar/SideBar/EmployeeSideBar.js (1)

5-6: Good use of MediaQuery for responsive design

Wrapping the Sidebar component with MediaQuery enhances the user experience by rendering it only on screens wider than 768 pixels.

<MediaQuery minWidth={768}>
<Sidebar
items={sortedTransformedData}
hideAccessbilityTools={true}
Copy link
Contributor

Choose a reason for hiding this comment

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

Typo in prop name: hideAccessbilityTools should be hideAccessibilityTools

The prop name hideAccessbilityTools is misspelled, which may cause the prop to be ineffective.

Apply this diff to correct the typo:

-           hideAccessbilityTools={true}
+           hideAccessibilityTools={true}
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
hideAccessbilityTools={true}
hideAccessibilityTools={true}

@@ -117,6 +119,7 @@ const EmployeeSideBar = () => {
label: value.item.displayName,
icon: { icon: value.item.leftIcon, width: "1.5rem", height: "1.5rem" },
navigationUrl: value.item.navigationURL,
orderNumber:value.item.orderNumber,
Copy link
Contributor

Choose a reason for hiding this comment

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

Handle undefined orderNumber in transformed items

When adding orderNumber to each item in transformData, ensure that value.item.orderNumber is defined. If it's undefined, the sorting function may not behave as expected.

Apply this diff to provide a default value:

              navigationUrl: value.item.navigationURL,
-             orderNumber: value.item.orderNumber,
+             orderNumber: value.item.orderNumber || 0,
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
orderNumber:value.item.orderNumber,
navigationUrl: value.item.navigationURL,
orderNumber: value.item.orderNumber || 0,

Comment on lines +136 to +150
const sortDataByOrderNumber = (data) => {
// Sort the current level of data by orderNumber
data.sort((a, b) => {
return a.orderNumber - b.orderNumber;
});

// Recursively sort the children if they exist
data.forEach((item) => {
if (item.children && item.children.length > 0) {
sortDataByOrderNumber(item.children);
}
});

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.

Ensure robust sorting in sortDataByOrderNumber function

To prevent potential issues when orderNumber is undefined or not a number, consider handling these cases to ensure the sort operation functions correctly.

Apply this diff to handle undefined or non-numeric orderNumber values:

        data.sort((a, b) => {
-         return a.orderNumber - b.orderNumber;
+         return (a.orderNumber || 0) - (b.orderNumber || 0);
        });
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 sortDataByOrderNumber = (data) => {
// Sort the current level of data by orderNumber
data.sort((a, b) => {
return a.orderNumber - b.orderNumber;
});
// Recursively sort the children if they exist
data.forEach((item) => {
if (item.children && item.children.length > 0) {
sortDataByOrderNumber(item.children);
}
});
return data;
};
const sortDataByOrderNumber = (data) => {
// Sort the current level of data by orderNumber
data.sort((a, b) => {
return (a.orderNumber || 0) - (b.orderNumber || 0);
});
// Recursively sort the children if they exist
data.forEach((item) => {
if (item.children && item.children.length > 0) {
sortDataByOrderNumber(item.children);
}
});
return data;
};

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.

4 participants