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

Added scroll and responsiveness to the plots page #9815

Conversation

Utkarsh-Anandani
Copy link

@Utkarsh-Anandani Utkarsh-Anandani commented Jan 7, 2025

Proposed Changes

image

@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

  • UI Improvements
    • Enhanced tab list with horizontal scrolling support
    • Implemented responsive grid layout that adjusts based on screen width
    • Improved layout adaptability for different device sizes

@Utkarsh-Anandani Utkarsh-Anandani requested a review from a team as a code owner January 7, 2025 07:12
Copy link
Contributor

coderabbitai bot commented Jan 7, 2025

Walkthrough

The pull request enhances the EncounterPlotsTab component's layout and responsiveness. It introduces a new import for useBreakpoints to dynamically set the gridCols property of the ObservationVisualizer component based on device size, replacing the previous hardcoded value. Additionally, a div wrapper is added around the TabsList component to enable horizontal scrolling, ensuring that tabs do not overflow on smaller screens.

Changes

File Change Summary
src/pages/Encounters/tabs/EncounterPlotsTab.tsx - Added useBreakpoints import and plotColumns constant
- Updated gridCols property in ObservationVisualizer based on plotColumns
- Added horizontal scrolling div wrapper for TabsList

Assessment against linked issues

Objective Addressed Explanation
Tabs horizontal scrolling
Responsive grid layout (1 column for small/medium, 2 for large)

Possibly related PRs

  • Horizontal scroll bar used #9692: The changes in this PR also involve adding a div wrapper to enhance horizontal scrolling, similar to the modifications made to the TabsList component in the main PR.

Suggested labels

question, needs-triage

Poem

🐰 Scrolling tabs, a rabbit's delight,
Responsive grid, now perfectly tight!
From mobile to desktop, no more strain,
CodeRabbit's magic breaks the layout's chain!
Hop, hop, hooray for UI's new might! 🌈


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8b30429 and 4bf98ec.

📒 Files selected for processing (1)
  • src/pages/Encounters/tabs/EncounterPlotsTab.tsx (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/pages/Encounters/tabs/EncounterPlotsTab.tsx

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 generate docstrings to generate docstrings for this PR. (Beta)
  • @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 Jan 7, 2025

Deploy Preview for care-ohc ready!

Name Link
🔨 Latest commit 4bf98ec
🔍 Latest deploy log https://app.netlify.com/sites/care-ohc/deploys/677cf475c0d8c800089a2ac1
😎 Deploy Preview https://deploy-preview-9815--care-ohc.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

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

🧹 Nitpick comments (1)
src/pages/Encounters/tabs/EncounterPlotsTab.tsx (1)

46-54: Enhance scroll implementation for better UX and accessibility

While the horizontal scroll implementation works, consider these improvements:

  1. Add role="tablist" and aria-orientation="horizontal" for better accessibility
  2. Use overflow-x-auto instead of overflow-x-scroll to hide scrollbar when unnecessary
  3. Consider adding scroll indicators or navigation buttons for better UX
-        <div className="overflow-x-scroll w-full">
+        <div 
+          className="overflow-x-auto w-full relative" 
+          role="tablist" 
+          aria-orientation="horizontal"
+        >
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e6b2596 and 1a6607d.

📒 Files selected for processing (1)
  • src/pages/Encounters/tabs/EncounterPlotsTab.tsx (1 hunks)


{data.map((tab) => (
<TabsContent key={tab.id} value={tab.id}>
<ObservationVisualizer
patientId={props.patient.id}
codeGroups={tab.groups}
gridCols={2}
gridCols={window.innerWidth >= 768 ? 2 : 1}
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 critical issues with window dimension handling

The direct usage of window.innerWidth can cause several issues:

  1. SSR hydration mismatches
  2. No handling of window resize events
  3. Potential performance impact from frequent re-renders

Consider using a proper window resize hook implementation:

// hooks/useWindowSize.ts
import { useState, useEffect } from 'react';
import debounce from 'lodash/debounce';

export function useWindowSize() {
  const [width, setWidth] = useState(0);

  useEffect(() => {
    // Initialize on client-side
    setWidth(window.innerWidth);

    const handleResize = debounce(() => {
      setWidth(window.innerWidth);
    }, 250);

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

  return width;
}

Then update the component:

+ import { useWindowSize } from '@/hooks/useWindowSize';

export const EncounterPlotsTab = (props: EncounterTabProps) => {
+  const windowWidth = useWindowSize();
   // ...
   <ObservationVisualizer
     patientId={props.patient.id}
     codeGroups={tab.groups}
-    gridCols={window.innerWidth >= 768 ? 2 : 1}
+    gridCols={windowWidth >= 768 ? 2 : 1}
   />

Alternatively, consider using CSS Grid with media queries if the grid layout doesn't need to be controlled programmatically.

@@ -21,6 +23,8 @@ export const EncounterPlotsTab = (props: EncounterTabProps) => {
const { t } = useTranslation();
const [qParams, setQParams] = useQueryParams<QueryParams>();

const { width } = useWindowDimensions();
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 instead for standard window sizes.

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

🧹 Nitpick comments (2)
src/pages/Encounters/tabs/EncounterPlotsTab.tsx (2)

50-58: Consider adding scroll affordance indicators

The horizontal scrolling implementation is clean and performant. However, users might not realize there are more tabs if they're hidden.

Consider adding visual indicators when tabs overflow:

-<div className="overflow-x-scroll w-full">
+<div className="relative w-full">
+  <div className="overflow-x-scroll w-full">
     <TabsList>
       {data.map((tab) => (
         <TabsTrigger key={tab.id} value={tab.id}>
           {tab.name}
         </TabsTrigger>
       ))}
     </TabsList>
+  </div>
+  <div className="absolute right-0 top-0 bottom-0 w-8 bg-gradient-to-l from-background to-transparent pointer-events-none" 
+       style={{ opacity: isScrollable ? 1 : 0 }} />
</div>

65-65: Consider using CSS Grid for responsive layout

While the current implementation works, consider using CSS Grid with media queries if the grid layout doesn't need to be controlled programmatically.

Example implementation:

-gridCols={width >= 768 ? 2 : 1}
+className="grid grid-cols-1 md:grid-cols-2 gap-4"

This would:

  1. Remove the dependency on JavaScript for layout
  2. Improve performance by handling responsiveness in CSS
  3. Work during SSR without hydration issues
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1a6607d and 623d7d1.

📒 Files selected for processing (1)
  • src/pages/Encounters/tabs/EncounterPlotsTab.tsx (3 hunks)
🔇 Additional comments (1)
src/pages/Encounters/tabs/EncounterPlotsTab.tsx (1)

26-26: Clean hook usage!

Good job avoiding direct window.innerWidth access and using a custom hook instead.

@@ -11,6 +11,8 @@ import {
} from "@/components/Common/Charts/ObservationChart";
import Loading from "@/components/Common/Loading";

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

Add SSR safety check and debounce resize events

The current implementation of useWindowDimensions has two issues:

  1. Potential SSR hydration mismatches due to direct window access during initialization
  2. Missing debouncing for resize events which can impact performance

Suggested improvements:

  • Add SSR safety check: Initialize state as undefined and update in useEffect
  • Add debouncing to resize handler using lodash.debounce or similar utility
🔗 Analysis chain

Verify the window dimensions hook implementation

The implementation of useWindowDimensions should properly handle:

  1. SSR hydration mismatches
  2. Window resize events with debouncing
  3. Cleanup of event listeners

Let's verify the hook implementation:

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for the useWindowDimensions hook implementation
ast-grep --pattern 'export $_ function useWindowDimensions() {
  $$$
}'

Length of output: 73


Script:

#!/bin/bash
# First, find the hook file
fd "useWindowDimensions" --type f

# Then try to find the implementation with different patterns
echo "=== Named export pattern ==="
ast-grep --pattern 'export const useWindowDimensions = $_'

echo "=== Default export pattern ==="
ast-grep --pattern 'export default function $_() {
  $$$
}'

echo "=== Alternative: Search with ripgrep for more context ==="
rg "useWindowDimensions" -A 10

Length of output: 66367


Script:

#!/bin/bash
# Get the complete implementation of useWindowDimensions hook
cat src/hooks/useWindowDimensions.ts

Length of output: 781

@@ -21,6 +23,8 @@ export const EncounterPlotsTab = (props: EncounterTabProps) => {
const { t } = useTranslation();
const [qParams, setQParams] = useQueryParams<QueryParams>();

const isSmallDevice = useBreakpoints({ default: true, md: false });
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
const isSmallDevice = useBreakpoints({ default: true, md: false });
const plotColumns = useBreakpoints({ default: 1, md: 2 });


{data.map((tab) => (
<TabsContent key={tab.id} value={tab.id}>
<ObservationVisualizer
patientId={props.patient.id}
encounterId={props.encounter.id}
codeGroups={tab.groups}
gridCols={2}
gridCols={isSmallDevice ? 1 : 2}
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
gridCols={isSmallDevice ? 1 : 2}
gridCols={plotColumns}

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

🧹 Nitpick comments (1)
src/pages/Encounters/tabs/EncounterPlotsTab.tsx (1)

50-58: Consider enhancing the scroll UX

While the horizontal scrolling implementation works, consider these UX improvements:

  1. Add smooth scrolling behavior
  2. Add visual indicators for overflow
  3. Enhance keyboard navigation accessibility
-        <div className="overflow-x-scroll w-full">
+        <div className="overflow-x-auto w-full scroll-smooth relative">
+          <div className="absolute right-0 top-0 bottom-0 w-8 bg-gradient-to-l from-background to-transparent pointer-events-none" aria-hidden="true" />
           <TabsList>
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 623d7d1 and 8b30429.

📒 Files selected for processing (1)
  • src/pages/Encounters/tabs/EncounterPlotsTab.tsx (3 hunks)
🔇 Additional comments (2)
src/pages/Encounters/tabs/EncounterPlotsTab.tsx (2)

14-15: LGTM! Good choice using useBreakpoints

The implementation correctly uses the useBreakpoints hook for responsive behavior, which is a better approach than direct window dimension handling. This addresses the previous review comments and provides a more maintainable solution.

Also applies to: 26-27


66-66: LGTM! Clean responsive implementation

The grid columns implementation effectively handles responsiveness using the isSmallDevice breakpoint. This is a clean and maintainable approach that aligns well with the PR objectives.

Comment on lines 48 to 49
onValueChange={(value) => setQParams({ plot: value })}
>
Copy link
Member

Choose a reason for hiding this comment

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

instead of adding a div with className, we can simply add className to the parent Tabs component ryt?

Copy link
Author

Choose a reason for hiding this comment

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

Yeah, I tried that but it gives scroll to the whole component including the plots idk if that behavior was wanted, looks weird to me...
image

Copy link
Member

Choose a reason for hiding this comment

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

oh my bad. Tried on TabsList? lots of other usages seems to be working fine with TabsList

Copy link
Author

Choose a reason for hiding this comment

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

Yeah, it gives a vertical scroll but not a horizontal scroll

Copy link
Member

Choose a reason for hiding this comment

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

are you sure? it's working fine for me

Copy link
Author

@Utkarsh-Anandani Utkarsh-Anandani Jan 7, 2025

Choose a reason for hiding this comment

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

<TabsList className="overflow-x-scroll">
You're using this className?

<TabsList className="overflow-auto w-full">
using this it cuts out at left

Copy link
Member

Choose a reason for hiding this comment

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

why does it cut out?

Copy link
Author

Choose a reason for hiding this comment

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

like cuts out means it just overflows at left side
image

are you sure? it's working fine for me

what classes are you using for it to work??

@Utkarsh-Anandani
Copy link
Author

Combined with PR #9782

@Utkarsh-Anandani
Copy link
Author

closed

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.

Overflowing at encounter/plots page and plots lack responsiveness
2 participants