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

Fix DailyDataGoal not updating when date changes #318

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

reneefromhold
Copy link
Collaborator

@reneefromhold reneefromhold commented Sep 27, 2024

Overview

When using the DailyDataGoal within a DateRangeCoordinator (already supported), when the user navigates to a new day

Current Behavior:
The data does not update
The data is searched for across a span of 3 days

Expected Behavior:
The data should reflect the current date
The data is searched for should be limited to one day

Security

REMINDER: All file contents are public.

  • I have ensured no secure credentials or sensitive information remain in code, metadata, comments, etc.
    • Please verify that you double checked that .storybook/preview.js does not contain your participant access key details.
    • There are no temporary testing changes committed such as API base URLs, access tokens, print/log statements, etc.
  • These changes do not introduce any security risks, or any such risks have been properly mitigated.

Describe briefly what security risks you considered, why they don't apply, or how they've been mitigated.

Checklist

Testing

Documentation

  • I have added relevant Storybook updates to this PR as well.
  • If this feature requires a developer doc update, tag @CareEvolution/api-docs.

Consider "Squash and merge" as needed to keep the commit history reasonable on main.

Reviewers

Assign to the appropriate reviewer(s). Minimally, a second set of eyes is needed ensure no non-public information is published. Consider also including:

  • Subject-matter experts
  • Style/editing reviewers
  • Others requested by the content owner

Summary by CodeRabbit

  • New Features

    • Introduced a new story for LiveGarminSleepScore with updated goal settings and messages.
  • Improvements

    • Enhanced date handling logic for better accuracy in daily data queries.
  • Refactor

    • Renamed existing story from SleepGoalLive to FitbitSleepMinutesGoalLive and updated rendering method for consistency.

Copy link
Contributor

coderabbitai bot commented Sep 27, 2024

Walkthrough

The pull request introduces changes to the DailyDataGoal component's story and implementation files. The story file has undergone renaming of exports, removal of an existing export, and addition of a new story with updated rendering logic. In the implementation file, date handling logic has been revised to set specific start and end dates, and the dependency array for a hook has been updated to reflect changes in date range context.

Changes

Files Change Summary
src/components/container/DailyDataGoal/DailyDataGoal.stories.tsx - Renamed export: SleepGoalLive to FitbitSleepMinutesGoalLive
- Removed export: WearTimeGoalLive
- Added new export: LiveGarminSleepScore
- Updated render method to use renderWithDRC for LiveGarminSleepScore
src/components/container/DailyDataGoal/DailyDataGoal.tsx - Modified date handling logic in useInitializeView hook: startDate now set to the start of the day and endDate to the end of the day for the provided date.
- Updated dependency array to include dateRangeContext?.intervalStart

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 or @coderabbitai title 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: 1

🧹 Outside diff range and nitpick comments (3)
src/components/container/DailyDataGoal/DailyDataGoal.stories.tsx (3)

Line range hint 98-117: LGTM: Story renamed for clarity

The renaming of the story from SleepGoalLive to FitbitSleepMinutesGoalLive improves specificity and clarity. This is a good change.

Consider updating the title prop in the story args to reflect the new name, e.g., change "Worn to Sleep" to "Fitbit Sleep Minutes Goal" for consistency.


118-122: LGTM: New renderWithDRC function added

The addition of the renderWithDRC function is a good solution to address the issue of DailyDataGoal not updating when the date changes. Wrapping the component with DateRangeCoordinator should allow it to react to date changes properly.

Consider making the interval type configurable by passing it as an argument to the function. This would allow for more flexibility in testing different interval types:

const renderWithDRC = (args: DailyDataGoalProps, intervalType: "Day" | "Week" | "Month" = "Day") => (
  <Layout colorScheme='auto'>
    <DateRangeCoordinator intervalType={intervalType}>
      <DailyDataGoal {...args} />
    </DateRangeCoordinator>
  </Layout>
);

124-153: LGTM: New LiveGarminSleepScore story added

The addition of the LiveGarminSleepScore story is a good demonstration of using the DailyDataGoal component with the new renderWithDRC function. It provides a clear example of how the component works with a different type of sleep data (Garmin Sleep Score).

For consistency with the FitbitSleepMinutesGoalLive story, consider adding a subtitle prop to the args object. For example:

subtitle: "Track your sleep quality",

This would make the story structure more consistent across different data types.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between e64a7ae and 5e0878a.

📒 Files selected for processing (2)
  • src/components/container/DailyDataGoal/DailyDataGoal.stories.tsx (3 hunks)
  • src/components/container/DailyDataGoal/DailyDataGoal.tsx (2 hunks)
🔇 Additional comments (5)
src/components/container/DailyDataGoal/DailyDataGoal.stories.tsx (2)

7-7: LGTM: DateRangeCoordinator import added

The addition of the DateRangeCoordinator import is appropriate and aligns with the PR objective of fixing the issue with DailyDataGoal not updating when the date changes.


Line range hint 1-153: Overall assessment: Changes effectively address the PR objectives

The modifications to this file successfully address the issue of DailyDataGoal not updating when the date changes. The introduction of the renderWithDRC function and its use in the new LiveGarminSleepScore story demonstrate how the DateRangeCoordinator can be used to manage date changes.

Key improvements:

  1. Addition of DateRangeCoordinator import
  2. Renaming of the FitbitSleepMinutesGoalLive story for clarity
  3. Introduction of the renderWithDRC function
  4. Addition of a new LiveGarminSleepScore story

These changes not only fix the reported issue but also improve the overall structure and clarity of the Storybook stories for the DailyDataGoal component. The minor suggestions provided in the review comments can further enhance consistency and flexibility.

src/components/container/DailyDataGoal/DailyDataGoal.tsx (3)

8-8: Import changes align with PR objectives

The addition of endOfDay and startOfDay imports from 'date-fns' is consistent with the PR's goal of limiting the data search to a single day. The removal of the add function import (not visible in the provided code) further supports this change in date handling logic.


36-37: Date handling logic now correctly limits data to a single day

The updated logic for calculating startDate and endDate using startOfDay and endOfDay functions effectively addresses the PR objective. This change ensures that:

  1. The data is queried only for the current day, from the start to the end of the day.
  2. The previous issue of searching for data across three days is resolved.

This implementation provides a more precise and standardized way of defining day boundaries, improving the accuracy of the daily data goal display.


Line range hint 1-99: Overall assessment: Changes effectively address PR objectives

The modifications made to the DailyDataGoal component successfully address the main objectives of the PR:

  1. The date handling logic now correctly limits data queries to a single day, resolving the issue of searching across three days.
  2. The component now updates properly when the date changes, thanks to the updated dependency array in the useInitializeView hook.

These changes improve the accuracy and responsiveness of the daily data goal display, enhancing the user experience as intended. The code maintains good style and structure, and no security issues are apparent in the changes.

To further improve the implementation, consider addressing the potential issue with the dependency array as mentioned in the previous comment.


queryDailyData(props.dailyDataType, startDate, endDate, props.previewState === "Default").then((results) => {
setDailyValue(results[getDayKey(date)] || 0);
});
}, ["externalAccountSyncComplete"], []);
}, ["externalAccountSyncComplete"], [dateRangeContext?.intervalStart]);
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

Dependency array update improves date change responsiveness, but needs refinement

The addition of dateRangeContext?.intervalStart to the dependency array is a positive change that addresses the PR objective. It ensures that the useInitializeView hook re-runs when the date range changes, fixing the issue of the DailyDataGoal not updating on date changes.

However, there's a potential issue with the current implementation:

The dependency array still includes the string "externalAccountSyncComplete". This is likely a mistake, as strings in dependency arrays are treated as static values and won't trigger re-runs of the effect.

To fix this, consider the following change:

-    }, ["externalAccountSyncComplete"], [dateRangeContext?.intervalStart]);
+    }, [dateRangeContext?.intervalStart]);

If "externalAccountSyncComplete" is meant to be a variable or prop, make sure it's properly referenced:

-    }, ["externalAccountSyncComplete"], [dateRangeContext?.intervalStart]);
+    }, [externalAccountSyncComplete, dateRangeContext?.intervalStart]);

This will ensure that the effect runs correctly based on both the date range changes and any external account sync status updates.

📝 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
}, ["externalAccountSyncComplete"], [dateRangeContext?.intervalStart]);
}, [dateRangeContext?.intervalStart]);

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