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

enhanced Date Time component #9379

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

Conversation

saikiranpatil
Copy link

@saikiranpatil saikiranpatil commented Dec 11, 2024

Proposed Changes

  • Closes Improve the Date and Time component in the CARE #8994

  • Change 1: The text area and selection component for date and time should align with the user’s system time preference.

  • Change 2: Users should be allowed to enter "01" in the minutes part of the component. Similarly, this behavior should be allowed for all other date and hour parts as well

    • this error was causing because when we finished writing minutes, cursor was pointing back to minutes. I made changes such that after typing minutes, cursor loops back to day, making it easier to change date completely if needed without changing cursor position with mouse.

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

  • New Features

    • Enhanced hour input functionality now supports a 12-hour format.
    • Improved navigation logic between input fields for a smoother user experience.
    • Streamlined input change handling for easier transitions between fields.
  • Bug Fixes

    • Resolved issues with input navigation that previously restricted field transitions based on index.

@saikiranpatil saikiranpatil requested a review from a team as a code owner December 11, 2024 12:43
Copy link
Contributor

coderabbitai bot commented Dec 11, 2024

Walkthrough

The changes made to the DateTextInput component focus on improving the handling of hour input by switching from a 24-hour format to a 12-hour format. Additionally, the logic for navigating between input fields has been simplified to allow for circular navigation. The conditions for transitioning between fields based on input patterns have been streamlined, while the formatting logic during the blur event remains unchanged.

Changes

File Change Summary
src/components/Common/DateTextInput.tsx - Modified hour calculation to use 12-hour format.
- Simplified input navigation logic.
- Streamlined input change handling for field transitions.
- Retained formatting logic on blur.

Assessment against linked issues

Objective Addressed Explanation
The text area and selection component for date and time should align with the user’s system time preference. (#8994)
Users should be allowed to enter "01" in the minutes part of the component. (#8994) The issue regarding leading zeros in minutes input is not addressed.

Possibly related PRs

Suggested labels

needs review, tested, P1

Suggested reviewers

  • rithviknishad
  • shivankacker

🐰 In the fields where time does flow,
A 12-hour clock now steals the show.
With inputs smooth, we hop and glide,
Navigating time with joyful pride.
Let "01" shine bright, no more to hide! 🌼


📜 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 4226cf2 and c2981c0.

📒 Files selected for processing (1)
  • src/components/Common/DateTextInput.tsx (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/components/Common/DateTextInput.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. (Experiment)
  • @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 Dec 11, 2024

Deploy Preview for care-ohc ready!

Name Link
🔨 Latest commit c2981c0
🔍 Latest deploy log https://app.netlify.com/sites/care-ohc/deploys/675b40223c79b2000887ada7
😎 Deploy Preview https://deploy-preview-9379--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: 2

🧹 Outside diff range and nitpick comments (1)
src/components/Common/DateTextInput.tsx (1)

Line range hint 1-201: Consider enhancing component accessibility and type safety

The component could benefit from several improvements:

  1. Add proper ARIA labels for screen readers
  2. Leverage dayjs for comprehensive date validation
  3. Define proper TypeScript types for the component's state

Consider these enhancements:

// Define proper types
type DateInputField = 'date' | 'month' | 'year' | 'hour' | 'minute';
type EditingText = Record<DateInputField, string>;

// Add aria labels
<input
  aria-label={`Enter ${key}`}
  role="spinbutton"
  aria-valuemin={key === "date" ? 1 : key === "month" ? 1 : 0}
  aria-valuemax={key === "date" ? 31 : key === "month" ? 12 : 
                 key === "year" ? 2999 : key === "hour" ? 23 : 59}
  // ... other props
/>

// Use dayjs for validation
const isValidDate = (date: EditingText) => {
  return dayjs(`${date.year}-${date.month}-${date.date} ${date.hour}:${date.minute}`).isValid();
};
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between e89530d and 70ef917.

📒 Files selected for processing (1)
  • src/components/Common/DateTextInput.tsx (2 hunks)

@@ -116,7 +116,7 @@ export default function DateTextInput(props: {
date: `${value ? formatUnfocused(value.getDate(), 0) : ""}`,
month: `${value ? formatUnfocused(value.getMonth() + 1, 1) : ""}`,
year: `${value ? formatUnfocused(value.getFullYear(), 2, 4) : ""}`,
hour: `${value ? formatUnfocused(value.getHours(), 3) : ""}`,
hour: `${value ? formatUnfocused(value.getHours() % 12, 3) : ""}`,
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

Hour format implementation needs revision

The current implementation has several issues:

  1. It forces 12-hour format instead of respecting system preferences as intended
  2. The modulo operation incorrectly handles midnight (0) and noon (12), both becoming "0"
  3. Missing AM/PM indicator makes 12-hour format ambiguous

Consider this implementation:

-hour: `${value ? formatUnfocused(value.getHours() % 12, 3) : ""}`,
+const is24Hour = Intl.DateTimeFormat(undefined, { hour: 'numeric' }).resolvedOptions().hour12 === false;
+hour: `${value ? formatUnfocused(is24Hour ? value.getHours() : (value.getHours() % 12 || 12), 3) : ""}`,

Also, consider adding an AM/PM indicator if using 12-hour format:

const period = value?.getHours() >= 12 ? 'PM' : 'AM';

Comment on lines +159 to +164
value.endsWith("/") ||
value.endsWith(" ") ||
value.endsWith(":") ||
value.length > (key === "year" ? 3 : 1)
) {
goToInput(i + 1);
goToInput((i + 1) % 5);
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

Field navigation logic needs improvement

The current implementation has several issues:

  1. The modulo operation (i + 1) % 5 assumes all fields are present, but breaks when allowTime is false
  2. Missing validation before transitioning could lead to invalid dates
  3. Automatic transition on delimiters might interfere with manual editing

Consider this implementation:

-                    value.endsWith("/") ||
-                    value.endsWith(" ") ||
-                    value.endsWith(":") ||
-                    value.length > (key === "year" ? 3 : 1)
-                  ) {
-                    goToInput((i + 1) % 5);
+                    (value.endsWith("/") && ["date", "month"].includes(key)) ||
+                    (value.endsWith(":") && key === "hour") ||
+                    value.length > (key === "year" ? 3 : 1)
+                  ) {
+                    const maxFields = allowTime ? 5 : 3;
+                    const nextIndex = (i + 1) % maxFields;
+                    // Validate current field before moving
+                    const currentValue = parseInt(value);
+                    const isValid = !isNaN(currentValue) && 
+                      currentValue <= (key === "date" ? 31 : 
+                                     key === "month" ? 12 : 
+                                     key === "year" ? 2999 :
+                                     key === "hour" ? 23 : 59);
+                    if (isValid) {
+                      goToInput(nextIndex);
+                    }
📝 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
value.endsWith("/") ||
value.endsWith(" ") ||
value.endsWith(":") ||
value.length > (key === "year" ? 3 : 1)
) {
goToInput(i + 1);
goToInput((i + 1) % 5);
(value.endsWith("/") && ["date", "month"].includes(key)) ||
(value.endsWith(":") && key === "hour") ||
value.length > (key === "year" ? 3 : 1)
) {
const maxFields = allowTime ? 5 : 3;
const nextIndex = (i + 1) % maxFields;
// Validate current field before moving
const currentValue = parseInt(value);
const isValid = !isNaN(currentValue) &&
currentValue <= (key === "date" ? 31 :
key === "month" ? 12 :
key === "year" ? 2999 :
key === "hour" ? 23 : 59);
if (isValid) {
goToInput(nextIndex);
}

@saikiranpatil
Copy link
Author

@ohcnetwork/care-fe-code-reviewers

I had made commit with time taking hour as 12 for 12 am or pm, it failed 1 test, but when i reverted it back to 00 it passed all the test cases.

I tried to run cypress tests locally, but, in all tests, page was loading till timeout

Please guide me on how to proceed further

@github-actions github-actions bot added needs-triage question Further information is requested labels Dec 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changes required needs-triage question Further information is requested
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Improve the Date and Time component in the CARE
2 participants