Skip to content

Derik/b/2321 #2984

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

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

Derik/b/2321 #2984

wants to merge 3 commits into from

Conversation

HackGenesis
Copy link
Contributor

@HackGenesis HackGenesis commented Mar 20, 2025

update the default time to use machine time if defaultToMidnight has been set to false

Summary by CodeRabbit

  • New Features
    • Enhanced the date picker to provide dynamic default time selection, automatically resetting to either midnight or the current time based on configuration.
  • Refactor
    • Improved responsiveness of the date picker’s time display, ensuring that any changes or interactions promptly update the displayed time.

Copy link
Contributor

coderabbitai bot commented Mar 20, 2025

Walkthrough

The changes update the DatePickerWrapper component by replacing the static MIDNIGHT_MOMENT constant with a state variable and adding two additional state variables (momentValue and rangeMomentValue). The component now uses useState and useEffect to manage time-related values dynamically. A new function, getCurrentTime, resets the states and conditionally sets MIDNIGHT_MOMENT based on the defaultToMidnight prop. Additionally, the showTime prop is adjusted to use defaultOpenValue, and the onClick events trigger the new time update functionality.

Changes

File Summary of Changes
shesha-reactjs/.../dateField/datePickerWrapper.tsx - Replaced constant MIDNIGHT_MOMENT with a state variable
- Added state variables: momentValue and rangeMomentValue
- Introduced getCurrentTime to update/reset states based on defaultToMidnight
- Implemented useEffect to update states based on props changes
- Updated showTime prop to use defaultOpenValue and set onClick event to trigger getCurrentTime

Sequence Diagram(s)

sequenceDiagram
    participant U as User
    participant DP as DatePicker/RangePicker
    participant Wrapper as DatePickerWrapper
    participant State as Component State

    U->>DP: Click event
    DP->>Wrapper: Trigger onClick (getCurrentTime)
    Wrapper->>State: Reset momentValue & rangeMomentValue (to null)
    alt defaultToMidnight is true
        Wrapper->>State: Set MIDNIGHT_MOMENT to midnight
    else defaultToMidnight is false
        Wrapper->>State: Set MIDNIGHT_MOMENT to current time ('HH:mm:ss')
    end
Loading
sequenceDiagram
    participant Props as Props (value, pickerFormat)
    participant Wrapper as DatePickerWrapper
    participant State as Component State

    Props->>Wrapper: Trigger useEffect on props change
    Wrapper->>State: Update momentValue and rangeMomentValue based on new props
Loading

Poem

I'm a rabbit with a coder's flair,
Hopping through states with careful care.
Midnight turns and clicks take flight,
Updating hours in the soft twilight.
With every change, I hop with cheer,
Celebrating code that's bright and clear!
🐇💻✨

✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 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.
  • @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
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)
shesha-reactjs/src/designer-components/dateField/datePickerWrapper.tsx (1)

92-109: Optimize the getCurrentTime implementation

The function successfully implements the requirement to use machine time when defaultToMidnight is false. However, the implementation could be simplified.

  const getCurrentTime = () => {
    // Reset the state to null
    setMomentValue(null);
    setRangeMomentValue(null);

    if (defaultToMidnight) {
      setMIDNIGHT_MOMENT(moment('00:00:00', 'HH:mm:ss'));
    } else {
-      // Get the current system time as a Moment object and format it to 'HH:mm:ss'
-      const MIDNIGHT = moment().set({
-        hour: moment().hour(),
-        minute: moment().minute(),
-        second: moment().second(),
-        millisecond: 0,
-      });
-      setMIDNIGHT_MOMENT(moment(MIDNIGHT.format('HH:mm:ss')));
+      // Get the current system time
+      const currentTime = moment();
+      // Set milliseconds to 0 for consistency
+      currentTime.millisecond(0);
+      setMIDNIGHT_MOMENT(currentTime);
    }
  };
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 3825323 and 2a0e490.

📒 Files selected for processing (1)
  • shesha-reactjs/src/designer-components/dateField/datePickerWrapper.tsx (5 hunks)
🔇 Additional comments (7)
shesha-reactjs/src/designer-components/dateField/datePickerWrapper.tsx (7)

3-3: Clean import updates for new hooks

The import has been properly updated to include the new React hooks that are used in this component.


18-20: Good conversion from static to state variables

Converting the static MIDNIGHT_MOMENT to a state variable and adding additional state variables for tracking moment values improves the component's reactivity to changes.


114-122: Good use of useEffect for prop synchronization

Using useEffect to synchronize component state with props is a good practice. This ensures the component updates correctly when either the value or pickerFormat props change.


136-136: Proper update to showTime configuration

Using defaultOpenValue instead of defaultValue for the time picker is more appropriate for this use case.


141-141: Effective event handler addition

Adding the onClick handler ensures that time values are properly updated before the picker opens.


159-159: Consistent showTime implementation

The change to use defaultOpenValue here matches the implementation for the RangePicker component, ensuring consistent behavior.


167-167: Consistent onClick handling

Adding the onClick handler here ensures the same behavior as the RangePicker component.

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 (2)
shesha-reactjs/src/designer-components/dateField/datePickerWrapper.tsx (2)

92-109: Simplify current time setting logic

The function correctly implements the requirement to use machine time when defaultToMidnight is false, but the current time setting logic could be simplified.

const getCurrentTime = () => {
  // Reset the state to null
  setMomentValue(null);
  setRangeMomentValue(null);

  if (defaultToMidnight) {
    SET_MIDNIGHT_MOMENT(moment('00:00:00', 'HH:mm:ss'));
  } else {
-    // Get the current system time as a Moment object and format it to 'HH:mm:ss'
-    const MIDNIGHT = moment().set({
-      hour: moment().hour(),
-      minute: moment().minute(),
-      second: moment().second(),
-      millisecond: 0,
-    });
-    SET_MIDNIGHT_MOMENT(moment(MIDNIGHT.format('HH:mm:ss')));
+    // Get the current system time as a Moment object
+    const now = moment();
+    SET_MIDNIGHT_MOMENT(now.clone().millisecond(0));
  }
};

92-109: Consider optimizing onClick performance

The getCurrentTime function is called on every click of the date picker, which could lead to unnecessary state updates if the picker is clicked multiple times.

Consider using the onOpenChange prop instead of onClick to only update the time when the picker is actually opened:

// For RangePicker
-onClick={getCurrentTime}
+onOpenChange={(open) => open && getCurrentTime()}

// For DatePicker
-onClick={getCurrentTime}
+onOpenChange={(open) => open && getCurrentTime()}

This would only update the time when the picker is actually opened, rather than on every click.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 2a0e490 and 7d835f6.

📒 Files selected for processing (1)
  • shesha-reactjs/src/designer-components/dateField/datePickerWrapper.tsx (5 hunks)
🔇 Additional comments (7)
shesha-reactjs/src/designer-components/dateField/datePickerWrapper.tsx (7)

3-3: Import statement updated correctly

Added imports for useEffect and useState hooks which are necessary for the state management changes implemented in this component.


18-20: State management implementation looks good

Converting MIDNIGHT_MOMENT from a constant to a state variable allows for dynamic updates based on the defaultToMidnight prop. Adding momentValue and rangeMomentValue state variables provides proper reactivity for the component.


114-122: Good use of useEffect for reactive state updates

The useEffect hook properly updates momentValue and rangeMomentValue when value or pickerFormat changes, ensuring state remains in sync with props.


136-136: Correct implementation for RangePicker showTime prop

Changed to use defaultOpenValue instead of defaultValue for the time picker, which is the proper approach for setting the initial time shown when the time picker is opened.


141-141: Good addition of onClick handler for RangePicker

Adding the onClick handler ensures that the default time is updated when the picker is clicked, which is necessary for implementing the requirement to use machine time when defaultToMidnight is false.


159-159: Correct implementation for DatePicker showTime prop

Similar to the RangePicker change, this properly uses defaultOpenValue for setting the initial time shown when the time picker is opened.


167-167: Good addition of onClick handler for DatePicker

Adding the onClick handler ensures that the default time is updated when the picker is clicked, maintaining consistency with the RangePicker implementation.

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.

1 participant