Skip to content

86exm8u3j metrics in db#77

Merged
Tamir198 merged 3 commits into
mainfrom
86exm8u3j-metricsInDb
May 27, 2026
Merged

86exm8u3j metrics in db#77
Tamir198 merged 3 commits into
mainfrom
86exm8u3j-metricsInDb

Conversation

@Lavi2910
Copy link
Copy Markdown
Collaborator

@Lavi2910 Lavi2910 commented May 21, 2026

Description

Save metrics in db
Please include a summary of the changes and the related issue.

Related Issue(s)

86exm8u3j
Fixes # (issue number)

Checklist:

  • I have performed a self-review of my own code
  • My changes generate no new warnings

Screenshots (if appropriate):

Summary by CodeRabbit

  • New Features

    • Added metrics reporting functionality allowing users to track daily health metrics including energy level, sleep quality, pain level, concentration, brain fog, and mood.
    • Metrics submission now persists data and updates the interface to reflect submission status.
  • Refactor

    • Restructured metrics report component to improve state management and user interaction flow.

Review Change Stack

@Lavi2910 Lavi2910 requested a review from Tamir198 May 21, 2026 22:28
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 21, 2026

Warning

Rate limit exceeded

@Lavi2910 has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 46 minutes and 17 seconds before requesting another review.

You’ve run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: cb734729-fdd3-4ef8-8c49-e7c19a181d10

📥 Commits

Reviewing files that changed from the base of the PR and between dede41f and 86c9f96.

📒 Files selected for processing (4)
  • src/constants/api.constants.ts
  • src/hooks/useMetricsReport.ts
  • src/pages/dailyReports/metricsReport/MetricsReport.tsx
  • src/pages/dailyReports/metricsReport/MetricsReportButton.tsx
📝 Walkthrough

Walkthrough

The PR refactors the metrics reporting component from prop-driven to self-contained. A new useMetricsReport hook fetches and submits metrics via a fresh /api/metrics/ endpoint. MetricsReport now owns metric state, delegates child component updates through callbacks, and displays server-side submission status. All supporting interfaces and data structures are updated to enable bidirectional id-based metric flow.

Changes

Metrics Report Component Refactoring

Layer / File(s) Summary
API endpoint and metrics hook
src/constants/api.constants.ts, src/hooks/useMetricsReport.ts
/api/metrics/ endpoint is registered, and useMetricsReport hook provides a query to fetch today's metrics and a mutation to submit MetricsPayload for a hardcoded patient ID, returning { sentToday, submitReport }.
Metrics data structure and child component interfaces
src/pages/dailyReports/metricsReport/MetricsReportData.ts, src/pages/dailyReports/metricsReport/MetricsReportListCard.tsx
Each metric object gains an id field, and MetricsReportListCard introduces MetricsReportListCardProps with an onChange(id, value) callback to propagate metric changes to the parent.
Child component prop and logic updates
src/pages/dailyReports/metricsReport/MetricsReportListCard.tsx, src/pages/dailyReports/metricsReport/MetricsReportButton.tsx
MetricsReportListCard wires each metric's onChange to call the parent callback with metric id and value; MetricsReportButton accepts and uses sentToday boolean to show success UI when either local report state or server sentToday is true.
MetricsReport component state and submission
src/pages/dailyReports/metricsReport/MetricsReport.tsx, src/pages/dailyReports/DailyReports.tsx
MetricsReport becomes a stateful, self-contained component managing local metric values, consuming useMetricsReport for submission and server state, and wiring child components; the onClick prop interface is removed. DailyReports renders MetricsReport without props.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • ColmanDevClubORG/Sagol360Management#66: Refactors the MetricsReport component and related child components, directly extending the component prop/state flow with the new hook integration and metric id/onChange patterns.

Suggested reviewers

  • Tamir198

Poem

🐰 The metrics hop with state and pride,
No props to pass, they self-collide,
A hook now queries, saves with care,
Ids and values float through air. 🎯✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Title check ❓ Inconclusive The title '86exm8u3j metrics in db' is vague and uses an issue ID instead of a descriptive summary, making it unclear what the actual change accomplishes. Use a clear, descriptive title like 'Add metrics reporting and persistence' or 'Implement metrics submission to database' that explains the feature without relying on issue references.
✅ Passed checks (4 passed)
Check name Status Explanation
Description check ✅ Passed The description follows the template structure with required sections present but lacks substantive detail about what was implemented and how.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch 86exm8u3j-metricsInDb

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@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

🤖 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 `@src/hooks/useMetricsReport.ts`:
- Around line 15-17: Remove the hardcoded PATIENT_ID in the useMetricsReport
hook and instead obtain the patient ID from the authenticated user context or
accept it as an injected parameter to the hook; replace usages of the PATIENT_ID
constant (the declaration named PATIENT_ID and other occurrences around lines
where queries/mutations are invoked inside useMetricsReport) with the
derived/received id, and guard all query/mutation calls in useMetricsReport (and
any functions like the fetch/update calls referenced there) to only run when the
patient id is present to avoid accidental global reads/writes.

In `@src/pages/dailyReports/metricsReport/MetricsReportButton.tsx`:
- Around line 11-12: The component sets the success state (report via
setReport(true)) immediately after calling the onClick prop, which can show
success even if the async persistence fails; update the MetricsReportButton so
the onClick handler is async (or wraps the provided onClick in an async
function), await the onClick() promise, and only call setReport(true) after the
awaited call resolves successfully (and setReport(false) or handle errors if it
rejects), ensuring you reference the onClick prop and the setReport state
updater in your change.
🪄 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: defaults

Review profile: CHILL

Plan: Pro

Run ID: 9db10d66-e4bf-49b0-823f-d25ef877b97e

📥 Commits

Reviewing files that changed from the base of the PR and between 9bb6825 and dede41f.

📒 Files selected for processing (7)
  • src/constants/api.constants.ts
  • src/hooks/useMetricsReport.ts
  • src/pages/dailyReports/DailyReports.tsx
  • src/pages/dailyReports/metricsReport/MetricsReport.tsx
  • src/pages/dailyReports/metricsReport/MetricsReportButton.tsx
  • src/pages/dailyReports/metricsReport/MetricsReportData.ts
  • src/pages/dailyReports/metricsReport/MetricsReportListCard.tsx

Comment on lines +15 to +17
//TODO: remove hardcoded user and get it from the login
const PATIENT_ID = '1622017'

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major | 🏗️ Heavy lift

Remove the hardcoded patient identifier before merge.

Line 16 hardcodes the patient context, so every user will read/write metrics for the same record. That creates a real multi-user correctness and privacy risk. Derive patient ID from authenticated user context (or pass it into the hook) and only query/mutate when it is available.

Also applies to: 21-21, 28-28

🤖 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 `@src/hooks/useMetricsReport.ts` around lines 15 - 17, Remove the hardcoded
PATIENT_ID in the useMetricsReport hook and instead obtain the patient ID from
the authenticated user context or accept it as an injected parameter to the
hook; replace usages of the PATIENT_ID constant (the declaration named
PATIENT_ID and other occurrences around lines where queries/mutations are
invoked inside useMetricsReport) with the derived/received id, and guard all
query/mutation calls in useMetricsReport (and any functions like the
fetch/update calls referenced there) to only run when the patient id is present
to avoid accidental global reads/writes.

Comment thread src/pages/dailyReports/metricsReport/MetricsReportButton.tsx Outdated
queryKey: ['metrics', 'today', PATIENT_ID],
queryFn: async () => {
const response = await apiService.get<boolean>(`${API_ENDPOINTS.metrics}today/${PATIENT_ID}`)
return response
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

today is hardcoded

<MetricsReportListCard />
<MetricsReportButton onClick={onClick} />
<MetricsReportListCard onChange={handleChange} />
<MetricsReportButton onClick={() => submitReport(metrics)} sentToday={sentToday ?? false} />
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

sentToday={!!sentToday}

Comment thread src/pages/dailyReports/metricsReport/MetricsReportButton.tsx Outdated
@Lavi2910 Lavi2910 requested a review from Tamir198 May 22, 2026 11:58
@Tamir198 Tamir198 merged commit 133ead3 into main May 27, 2026
2 checks passed
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.

2 participants