[codex] Show no-data sleep states - #1222
Conversation
📝 WalkthroughWalkthroughThe PR makes sleepNeed nullable at the server API level when no baseline sleep data exists, and refactors the mobile dashboard UI to display "No sleep data" fallback messages instead of default values. Backend and frontend tests validate the updated contract and rendering behavior. ChangesMissing sleep data handling
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Suggested labels
🚥 Pre-merge checks | ✅ 2✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Qodo reviews are paused for this user.Troubleshooting steps vary by plan Learn more → On a Teams plan? Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center? |
Automated Checks (advisory, non-blocking)✅ All checks passed. Surmado Code Review — Free tier limit reachedYou've used all 10 free reviews this month. Deterministic checks (secrets, model strings) still ran above. Upgrade to the Paid plan for 100 reviews/month + $15 per additional 100: https://app.surmado.com/checkout?plan=pr_review_starter Or wait until your next monthly window for 10 more free reviews. Surmado Code Review (v1.2-mt) |
|
Storybook previews for This comment updates automatically on each PR push. |
Mobile PreviewScan to open on device:
To test on device:
|
There was a problem hiding this comment.
Actionable comments posted: 2
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
packages/server/src/routers/mobile-dashboard.test.ts (1)
405-422:⚠️ Potential issue | 🟡 Minor | ⚡ Quick winIsolate the no-sleep-row contract in this case.
This setup also removes metrics and load data, so the
sleepNeed === nullassertion can pass as part of a broader empty-dashboard state. Keep at least one metric row present and only drop sleep rows here so the test proves the new server contract instead of unrelated null/zero fallbacks.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/server/src/routers/mobile-dashboard.test.ts` around lines 405 - 422, The test "does not return default sleep coach numbers when no sleep rows exist" currently mocks execute to return three empty arrays which removes metrics and load data too; instead mock execute so only sleep-related queries return empty arrays while ensuring at least one metric row is returned (e.g., make one execute.mockResolvedValueOnce([...metricRow...]) for the metrics query) so that createCaller/caller.dashboard still has metrics but no sleep rows; update the sequence of execute.mockResolvedValueOnce calls in the test to return a metric row for the metrics query and empty arrays only for sleep queries so the assertion about sleepNeed === null isolates the no-sleep-row contract.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@packages/mobile/app/`(tabs)/index.test.tsx:
- Around line 193-217: Update the test to exercise the new no-data branch by
setting mockDashboardData.sleepNeed = null (instead of a populated object) so
the TodayScreen import in index.test.tsx renders the fallback state; then
replace the negative assertions for removed UI ("Baseline need", "8h 0m") with
positive assertions that verify the new fallback messaging (e.g., the no-data
text already asserted like "Need last night's sleep for recommendation" or any
explicit fallback element). Ensure you modify the mockDashboardData object used
by the test and keep the TodayScreen render/assert flow intact.
In `@packages/server/src/routers/mobile-dashboard.ts`:
- Around line 370-380: The router's dashboard procedure must declare an explicit
tRPC .output(...) Zod schema for MobileDashboardResult so runtime responses
enforce sleepNeed: null when appropriate; update the dashboard procedure (in
packages/server/src/routers/mobile-dashboard.ts) to call
.output(z.object({...})) matching MobileDashboardResult's fields and make
sleepNeed z.nullable(...) (or z.union([z.object({ baselineMinutes: z.number(),
strainDebtMinutes: z.number(), accumulatedDebtMinutes: z.number(),
totalNeedMinutes: z.number(), recentNights: z.array(z.any()) /* refine element
schema as needed */, canRecommend: z.boolean() }), z.null()])) so the nullable
sleepNeed produced by the sleepNeedResult code path is validated at the router
boundary.
---
Outside diff comments:
In `@packages/server/src/routers/mobile-dashboard.test.ts`:
- Around line 405-422: The test "does not return default sleep coach numbers
when no sleep rows exist" currently mocks execute to return three empty arrays
which removes metrics and load data too; instead mock execute so only
sleep-related queries return empty arrays while ensuring at least one metric row
is returned (e.g., make one execute.mockResolvedValueOnce([...metricRow...]) for
the metrics query) so that createCaller/caller.dashboard still has metrics but
no sleep rows; update the sequence of execute.mockResolvedValueOnce calls in the
test to return a metric row for the metrics query and empty arrays only for
sleep queries so the assertion about sleepNeed === null isolates the
no-sleep-row contract.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro Plus
Run ID: d479b6e5-2510-4997-bee6-19a065e9ca68
📒 Files selected for processing (4)
packages/mobile/app/(tabs)/index.test.tsxpackages/mobile/app/(tabs)/index.tsxpackages/server/src/routers/mobile-dashboard.test.tspackages/server/src/routers/mobile-dashboard.ts
|
Review app deployment was skipped for PR #1222. Hetzner could not allocate the configured review app server type in the configured location. This is provider capacity/placement availability, not a code failure in this PR. |
There was a problem hiding this comment.
No issues found across 4 files
Confidence score: 5/5
- Automated review surfaced no issues in the provided summaries.
- No files require special attention.
Auto-approved: This change prevents the mobile dashboard from showing a default 8‑hour sleep recommendation when no sleep data exists, replacing it with clear no‑data states; the logic is straightforward, the blast radius is limited, and both server and mobile tests validate the new behavior.
Re-trigger cubic
…g-sleep-data # Conflicts: # packages/server/src/routers/mobile-dashboard.ts
There was a problem hiding this comment.
0 issues found across 2 files (changes from recent commits).
Requires human review: This change modifies core business logic in a critical user-facing feature by removing a default sleep baseline and adding null-state handling, which carries risk of regression and requires human review to ensure correctness and data integrity.
Re-trigger cubic
Stops the mobile dashboard from showing fabricated sleep recommendation numbers when no sleep rows exist.
The server now returns null sleep-need data instead of defaulting to an 8-hour baseline, and the mobile dashboard renders explicit no-data sleep states.
This prevents users from seeing misleading Last Night or Sleep Coach values before previous-night sleep data has synced.
Validated with focused server/mobile tests, server typecheck, and Biome on touched files.
Summary by cubic
Stop showing default 8h sleep recommendations when no sleep data exists. The server now returns null
sleepNeed, and the mobile dashboard shows clear no‑data states in Last Night and Sleep Coach to avoid misleading values before sync.Bug Fixes
sleepNeedwhen no sleep baseline rows exist (no 8h fallback).sleepNeedis null, or “Need last night’s sleep…” when a recommendation can’t be made; breakdown only appears when a recommendation is available.Refactors
.output()typing formobileDashboard,sleepNeed(includingrecentNights), and anomalies.Written for commit e46115f. Summary will update on new commits.
Summary by CodeRabbit