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

Fixed:Show more monitors in CNS on very large displays #9028

Closed

Conversation

i0am0arunava
Copy link
Contributor

@i0am0arunava i0am0arunava commented Nov 6, 2024

Proposed Changes

@ohcnetwork/care-fe-code-reviewers

Merge Checklist

  • Add specs that demonstrate bug / test a new feature.
  • Update product documentation.
  • Ensure that UI text is kept in I18n files.
  • Prep screenshot or demo video for changelog entry, and attach it to issue.
  • Request for Peer Reviews
  • Completion of QA

Summary by CodeRabbit

  • New Features

    • Introduced responsive pagination that adjusts the number of items displayed per page based on window width.
    • Added a new hook to dynamically determine the pagination limit.
  • Improvements

    • Enhanced layout responsiveness for better user experience on larger screens.

@i0am0arunava i0am0arunava requested a review from a team as a code owner November 6, 2024 14:30
Copy link
Contributor

coderabbitai bot commented Nov 6, 2024

Walkthrough

The changes in CentralNursingStation.tsx introduce a new hook, useWindowDimensions, to dynamically set the PER_PAGE_LIMIT variable based on the window width. This variable is now a local variable and adjusts to 9 for widths exceeding 2080 pixels, otherwise defaulting to 6. The Pagination component's defaultPerPage prop is updated accordingly. Additionally, the grid layout is modified to be responsive based on window size, enhancing the display on larger screens while keeping the existing error handling and data fetching logic unchanged.

Changes

File Change Summary
src/components/Facility/CentralNursingStation.tsx Introduced useWindowDimensions hook; updated PER_PAGE_LIMIT to be dynamic based on window width; modified Pagination component's defaultPerPage prop; adjusted grid layout for responsiveness.

Assessment against linked issues

Objective Addressed Explanation
Show more monitors in CNS on very large displays (#6503)

🐇 In a world where screens are wide,
More monitors now can abide!
With dimensions that shift and sway,
We fill the space in a clever way.
So hop along, and take a glance,
At the changes that make us dance! 🎉


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

netlify bot commented Nov 6, 2024

Deploy Preview for care-ohc failed.

Name Link
🔨 Latest commit 68f31d6
🔍 Latest deploy log https://app.netlify.com/sites/care-ohc/deploys/672b7e62b1f91c000892ccf8

@github-actions github-actions bot added the Deploy-Failed Deplyment is not showing preview label Nov 6, 2024
Comment on lines +49 to +55
const getDimension = useWindowDimensions();

if (getDimension.width > 2080) {
PER_PAGE_LIMIT = 9;
} else {
PER_PAGE_LIMIT = 6;
}
Copy link
Member

Choose a reason for hiding this comment

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

use useBreakpoints hook instead.

@@ -41,11 +40,19 @@ interface Props {
}

export default function CentralNursingStation({ facilityId }: Props) {
let PER_PAGE_LIMIT;
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
let PER_PAGE_LIMIT;

@@ -216,7 +223,7 @@ export default function CentralNursingStation({ facilityId }: Props) {
{t("no_vitals_present")}
</div>
) : (
<div className="3xl:grid-cols-3 mt-1 grid grid-cols-1 gap-1 lg:grid-cols-2">
<div className="mt-1 grid grid-cols-1 gap-1 lg:grid-cols-2 min-[2080px]:grid-cols-3">
Copy link
Member

Choose a reason for hiding this comment

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

avoid hardcoding abritrary pixel values. prefer rem values over pixel values as pixel values may behave differently for different zoom settings.

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

🧹 Outside diff range and nitpick comments (1)
src/components/Facility/CentralNursingStation.tsx (1)

226-226: Enhance grid layout for better responsiveness.

The current implementation uses a fixed breakpoint for 3 columns. Consider using CSS Grid's auto-fit/auto-fill for more flexible layouts that automatically adjust based on available space.

Consider this alternative approach:

-  <div className="mt-1 grid grid-cols-1 gap-1 lg:grid-cols-2 min-[2080px]:grid-cols-3">
+  <div className="mt-1 grid gap-1 grid-cols-[repeat(auto-fit,minmax(min(100%,400px),1fr))]">

This approach:

  • Automatically adjusts columns based on container width
  • Ensures monitors maintain readable dimensions
  • Eliminates the need for fixed breakpoints
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 0f9cc52 and 68f31d6.

📒 Files selected for processing (1)
  • src/components/Facility/CentralNursingStation.tsx (3 hunks)

Comment on lines +49 to +55
const getDimension = useWindowDimensions();

if (getDimension.width > 2080) {
PER_PAGE_LIMIT = 9;
} else {
PER_PAGE_LIMIT = 6;
}
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

Improve window dimension check implementation.

Several improvements can be made to the window dimension check:

  1. Extract the magic number 2080 as a named constant
  2. Consider DPI scaling for more accurate breakpoints
  3. Simplify the implementation

Apply these improvements:

+const LARGE_SCREEN_BREAKPOINT = 2080; // Consider moving to a constants file
+
-  if (getDimension.width > 2080) {
-    PER_PAGE_LIMIT = 9;
-  } else {
-    PER_PAGE_LIMIT = 6;
-  }
+  // Consider using window.devicePixelRatio for DPI-aware breakpoints
+  const effectiveWidth = getDimension.width * window.devicePixelRatio;
+  const PER_PAGE_LIMIT = effectiveWidth > LARGE_SCREEN_BREAKPOINT ? 9 : 6;
📝 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 getDimension = useWindowDimensions();
if (getDimension.width > 2080) {
PER_PAGE_LIMIT = 9;
} else {
PER_PAGE_LIMIT = 6;
}
const LARGE_SCREEN_BREAKPOINT = 2080; // Consider moving to a constants file
const getDimension = useWindowDimensions();
// Consider using window.devicePixelRatio for DPI-aware breakpoints
const effectiveWidth = getDimension.width * window.devicePixelRatio;
const PER_PAGE_LIMIT = effectiveWidth > LARGE_SCREEN_BREAKPOINT ? 9 : 6;

Comment on lines +43 to 48
let PER_PAGE_LIMIT;
const { t } = useTranslation();
const [isFullscreen, setFullscreen] = useFullscreen();
const { qParams, updateQuery, removeFilter, updatePage } = useFilters({
limit: PER_PAGE_LIMIT,
});
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

Fix variable initialization order issue.

The PER_PAGE_LIMIT is used in useFilters hook before being initialized. This could lead to undefined behavior as the value will be undefined during the first render.

Move the initialization before the hook usage:

-  let PER_PAGE_LIMIT;
-  const { t } = useTranslation();
-  const [isFullscreen, setFullscreen] = useFullscreen();
-  const { qParams, updateQuery, removeFilter, updatePage } = useFilters({
-    limit: PER_PAGE_LIMIT,
-  });
-  const getDimension = useWindowDimensions();
+  const { t } = useTranslation();
+  const [isFullscreen, setFullscreen] = useFullscreen();
+  const getDimension = useWindowDimensions();
+  const PER_PAGE_LIMIT = getDimension.width > 2080 ? 9 : 6;
+  const { qParams, updateQuery, removeFilter, updatePage } = useFilters({
+    limit: PER_PAGE_LIMIT,
+  });
📝 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
let PER_PAGE_LIMIT;
const { t } = useTranslation();
const [isFullscreen, setFullscreen] = useFullscreen();
const { qParams, updateQuery, removeFilter, updatePage } = useFilters({
limit: PER_PAGE_LIMIT,
});
const { t } = useTranslation();
const [isFullscreen, setFullscreen] = useFullscreen();
const getDimension = useWindowDimensions();
const PER_PAGE_LIMIT = getDimension.width > 2080 ? 9 : 6;
const { qParams, updateQuery, removeFilter, updatePage } = useFilters({
limit: PER_PAGE_LIMIT,
});

@@ -23,12 +23,11 @@ import { getVitalsMonitorSocketUrl } from "@/components/VitalsMonitor/utils";

import useFilters from "@/hooks/useFilters";
import useFullscreen from "@/hooks/useFullscreen";
import useWindowDimensions from "@/hooks/useWindowDimensions";
Copy link
Contributor

Choose a reason for hiding this comment

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

💡 Codebase verification

Window dimension hook needs throttling for performance optimization

The current implementation of useWindowDimensions directly attaches to the window resize event without any throttling mechanism, which can lead to excessive re-renders during window resizing. Add throttling to the resize event handler:

// Example modification
import { useEffect, useState } from "react";
import { throttle } from "lodash"; // or implement your own throttle

export default function useWindowDimensions() {
  const [windowDimensions, setWindowDimensions] = useState(getWindowDimensions());

  useEffect(() => {
    const handleResize = throttle(() => {
      setWindowDimensions(getWindowDimensions());
    }, 200); // throttle to 200ms

    window.addEventListener("resize", handleResize);
    return () => window.removeEventListener("resize", handleResize);
  }, []);

  return windowDimensions;
}
🔗 Analysis chain

Verify window dimension hook implementation.

The useWindowDimensions hook should implement proper event throttling to avoid performance issues during window resizing.

Let's verify the hook implementation:


Let me check the implementation of the getWindowDimensions function since it's used in the hook.


Let me try a different approach to find the complete implementation of the hook and any related functions.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check the useWindowDimensions hook implementation
rg -A 10 "useWindowDimensions" --type ts

Length of output: 8535


Script:

#!/bin/bash
# Check the getWindowDimensions function implementation
rg -A 5 "function getWindowDimensions" --type ts

Length of output: 50


Script:

#!/bin/bash
# Get the complete content of useWindowDimensions.ts
fd useWindowDimensions.ts --exec cat {}

Length of output: 786

@rithviknishad
Copy link
Member

Closing as duplicate of #9013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Deploy-Failed Deplyment is not showing preview
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Show more monitors in CNS on very large displays
2 participants