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

Remove Manual keyboard-shortcut handle #9816

Conversation

JavidSumra
Copy link
Contributor

@JavidSumra JavidSumra commented Jan 7, 2025

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

Release Notes

  • Localization

    • Added new translations for patient record management and verification.
    • Enhanced user feedback messages for patient search and identity verification.
  • User Interface

    • Improved internationalization support across multiple components.
    • Added dynamic translations for button texts, placeholders, and error messages.
  • Keyboard Shortcuts

    • Implemented a new keyboard shortcut handling mechanism using useKeyboardShortcut.
    • Simplified keyboard event management in various components.
  • Usability

    • Added clearer instructions for patient record search and identity verification.
    • Improved error messaging and user guidance.

Copy link
Contributor

coderabbitai bot commented Jan 7, 2025

Walkthrough

This pull request focuses on improving keyboard shortcut implementations and internationalization across multiple components. The changes introduce the useKeyboardShortcut hook to replace manual event listeners in components like FilePreviewDialog, PatientIndex, and sidebar. Additionally, the English localization file (en.json) has been updated with new translation entries to enhance user feedback and guidance in patient record management and identity verification processes.

Changes

File Change Summary
public/locale/en.json Added 6 new localization entries for patient record management and identity verification
src/components/Common/FilePreviewDialog.tsx Replaced keyboard event handling with useKeyboardShortcut hook, added translatable tooltip text
src/components/Patient/PatientIndex.tsx Integrated useTranslation for localization, replaced hardcoded strings with translation function
src/components/ui/sidebar.tsx Implemented useKeyboardShortcut for sidebar toggle, added isAppleDevice import

Assessment against linked issues

Objective Addressed Explanation
Cleanup Keyboard Shortcut implementation [#9641]

Possibly related PRs

Suggested labels

tested, changes required

Suggested reviewers

  • rithviknishad
  • Jacobjeevan

Poem

🐰 Keyboard shortcuts dance with grace,
Translations bloom in every space,
Hooks replace the old event's might,
Code now sings with pure delight,
A rabbit's code, both swift and bright! 🌈

Finishing Touches

  • 📝 Generate Docstrings

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 29927d4
🔍 Latest deploy log https://app.netlify.com/sites/care-ohc/deploys/677f7cc7e6e92800088bb507
😎 Deploy Preview https://deploy-preview-9816--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.

@JavidSumra
Copy link
Contributor Author

Could you please let me know if any components are missing, @rithviknishad?

@github-actions github-actions bot added needs-triage question Further information is requested labels Jan 7, 2025
Copy link
Member

@rithviknishad rithviknishad left a comment

Choose a reason for hiding this comment

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

image

src/components/ui/sidebar.tsx Outdated Show resolved Hide resolved
@rithviknishad rithviknishad removed question Further information is requested needs-triage labels Jan 7, 2025
@JavidSumra
Copy link
Contributor Author

JavidSumra commented Jan 7, 2025

@rithviknishad in some components it's not possible to implement due to the dynamic nature of keys.

@JavidSumra
Copy link
Contributor Author

image

Tried this 😃

@rithviknishad
Copy link
Member

Yup, just checked the implementation of SearchByMultipleFields. Let's leave that out then.

@rithviknishad
Copy link
Member

LGTM, add i18n for all texts in these files and should be good to merge

@JavidSumra JavidSumra marked this pull request as ready for review January 7, 2025 10:35
@JavidSumra JavidSumra requested a review from a team as a code owner January 7, 2025 10:35
…f github.com:JavidSumra/care_fe into issues/9641/cleanup-keyboard-shortcut-implementation
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 (3)
src/components/Patient/PatientIndex.tsx (1)

Line range hint 56-66: Consider extracting keyboard shortcut configuration.

The keyboard shortcut implementation is good, but consider extracting the shortcut key "shift+p" into a constant for better maintainability.

+const CREATE_PATIENT_SHORTCUT = ["shift", "p"] as const;
 
-  useKeyboardShortcut(["shift", "p"], handleCreatePatient);
+  useKeyboardShortcut(CREATE_PATIENT_SHORTCUT, handleCreatePatient);
src/components/Common/FilePreviewDialog.tsx (1)

156-160: Consider consolidating keyboard shortcuts into a single hook call.

The current implementation uses two separate hook calls for left and right navigation. Consider consolidating them into a single hook call for better maintainability.

-  useKeyboardShortcut(["ArrowLeft"], () => index > 0 && handleNext(index - 1));
-  useKeyboardShortcut(
-    ["ArrowRight"],
-    () => index < (uploadedFiles?.length || 0) - 1 && handleNext(index + 1),
-  );
+  useKeyboardShortcut({
+    "ArrowLeft": () => index > 0 && handleNext(index - 1),
+    "ArrowRight": () => index < (uploadedFiles?.length || 0) - 1 && handleNext(index + 1)
+  });
src/components/ui/sidebar.tsx (1)

103-106: Consider extracting keyboard shortcut configuration.

The keyboard shortcut implementation is good, but consider extracting the platform-specific modifier key logic into a constant for better maintainability.

+const SIDEBAR_MODIFIER_KEY = isAppleDevice ? "Meta" : "Control";
+const SIDEBAR_TOGGLE_SHORTCUT = [SIDEBAR_MODIFIER_KEY, SIDEBAR_KEYBOARD_SHORTCUT] as const;

-    useKeyboardShortcut(
-      [isAppleDevice ? "Meta" : "Control", SIDEBAR_KEYBOARD_SHORTCUT],
-      toggleSidebar,
-    );
+    useKeyboardShortcut(SIDEBAR_TOGGLE_SHORTCUT, toggleSidebar);
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 9b33e90 and a6fe8df.

📒 Files selected for processing (4)
  • public/locale/en.json (5 hunks)
  • src/components/Common/FilePreviewDialog.tsx (3 hunks)
  • src/components/Patient/PatientIndex.tsx (11 hunks)
  • src/components/ui/sidebar.tsx (3 hunks)
🧰 Additional context used
📓 Learnings (1)
src/components/Common/FilePreviewDialog.tsx (2)
Learnt from: Jacobjeevan
PR: ohcnetwork/care_fe#9196
File: src/components/Common/FilePreviewDialog.tsx:193-200
Timestamp: 2024-11-26T09:46:12.574Z
Learning: When adding navigation buttons, include aria labels and handle arrow keys (ArrowLeft and ArrowRight) in onKeyDown events to enhance accessibility.
Learnt from: Jacobjeevan
PR: ohcnetwork/care_fe#9196
File: src/components/Common/FilePreviewDialog.tsx:193-200
Timestamp: 2024-11-26T09:48:54.707Z
Learning: In navigation buttons, handle only the 'ArrowLeft' and 'ArrowRight' keys in onKeyDown events; handling the 'Enter' key is not necessary.
🔇 Additional comments (7)
src/components/Patient/PatientIndex.tsx (2)

4-7: LGTM! Clean import organization.

The imports are well organized, with related imports grouped together.


76-76: LGTM! Comprehensive internationalization implementation.

All user-facing strings have been properly internationalized using the translation function. The translation keys are descriptive and follow a consistent naming pattern.

Also applies to: 95-95, 130-130, 158-158, 161-161, 185-185, 188-188, 199-199, 201-202, 240-240, 242-242, 248-248, 263-263, 265-265

src/components/Common/FilePreviewDialog.tsx (2)

14-14: LGTM! Clean import.

The useKeyboardShortcut hook is properly imported.


194-194: LGTM! Proper internationalization.

The "created_on" string has been properly internationalized.

src/components/ui/sidebar.tsx (1)

5-5: LGTM! Clean imports.

The imports are well organized and properly placed.

Also applies to: 23-23

public/locale/en.json (2)

1258-1259: LGTM! Clear and user-friendly messages.

The translation strings for patient record management are clear and provide good user guidance.


1358-1358: LGTM! Consistent patient verification messages.

The translation strings for patient verification maintain consistency in terminology and provide clear instructions.

Also applies to: 1870-1870, 1888-1888

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)
public/locale/en.json (1)

1363-1363: Verify consistent terminology usage across patient identity verification messages.

The messages related to patient identity verification are clear but could be more consistent:

  • "patient's year of birth" vs "year of birth"
  • "verify" vs "verify patient identity"

Consider standardizing the terminology:

-  "patient_birth_year_for_identity": "Please enter the patient's year of birth to verify their identity",
+  "patient_birth_year_for_identity": "Please enter year of birth to verify patient identity",

Also applies to: 1876-1876, 1886-1886, 1894-1894

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between a6fe8df and 29927d4.

📒 Files selected for processing (1)
  • public/locale/en.json (5 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: Test
  • GitHub Check: CodeQL-Build
  • GitHub Check: cypress-run (1)
  • GitHub Check: OSSAR-Scan
🔇 Additional comments (3)
public/locale/en.json (3)

1263-1264: LGTM! Clear and actionable messages for patient record search.

The messages are user-friendly and provide clear next steps when no records are found.


1629-1629: LGTM! Clear search page instruction.

The message clearly explains both available actions (search and create) to the user.


Line range hint 1263-1894: Verify completeness of patient verification related translations.

Let's ensure all related translation keys are present for a complete user experience.

✅ Verification successful

Patient verification translations are complete and comprehensive

The translations cover all necessary aspects of the patient verification flow including main actions, validation, error handling, and user guidance. The TODO comments found are unrelated to translations and are in configuration files.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for missing related translations in the patient verification flow

# Common prefixes for patient verification
echo "Checking for patient verification related keys..."
rg -U 'patient.*identity|patient.*verify|verify.*patient|birth.*year' --type json

# Check for any TODO/FIXME comments that might indicate missing translations
echo "Checking for TODO/FIXME comments..."
rg -U 'TODO|FIXME' --type json

Length of output: 1335

@nihal467
Copy link
Member

nihal467 commented Jan 9, 2025

LGTM

@rithviknishad rithviknishad merged commit a70f26e into ohcnetwork:develop Jan 9, 2025
19 checks passed
Copy link

github-actions bot commented Jan 9, 2025

@JavidSumra Your efforts have helped advance digital healthcare and TeleICU systems. 🚀 Thank you for taking the time out to make CARE better. We hope you continue to innovate and contribute; your impact is immense! 🙌

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

Successfully merging this pull request may close these issues.

Cleanup Keyboard Shortcut implementation
4 participants