Skip to content

Conversation

@domhhv
Copy link
Owner

@domhhv domhhv commented Feb 1, 2026

Remove useHabitMetrics and useOccurrenceMetricValues from the metrics store and drop the zustand shallow import. Update EditHabitDialog to stop fetching habit metrics and instead read metricDefinitions from the habit prop, simplify related effects, and wire metrics actions (add/remove/update) accordingly. This reduces redundant fetching and relies on the habit's embedded metric definitions for editing.

Summary by CodeRabbit

  • Refactor
    • Streamlined internal metric data handling to improve system efficiency and maintainability.

✏️ Tip: You can customize this high-level summary in your review settings.

@domhhv domhhv self-assigned this Feb 1, 2026
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 1, 2026

📝 Walkthrough

Walkthrough

This PR removes store-based metric hooks (useHabitMetrics and useOccurrenceMetricValues) and updates EditHabitDialog to derive metricDefinitions directly from the habit object instead of fetching through a dedicated metrics hook. This eliminates an indirection layer in the metrics data flow.

Changes

Cohort / File(s) Summary
Component metric simplification
src/components/habit/EditHabitDialog.tsx
Removed useHabitMetrics hook dependency and refactored to source metricDefinitions directly from habit object; updated useEffect dependencies to reflect direct habit usage rather than store-fetched metrics.
Store hook removal
src/stores/metrics.store.ts
Deleted useHabitMetrics and useOccurrenceMetricValues public hooks that previously exposed sorted metrics and metric values via shallow state selectors.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Poem

🐰 ✨
Hooks untangled, metrics flow clear,
Straight from habit—no detours here!
Shallow selectors fade away,
Simpler logic saves the day!

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'refactor: use included metrics data in edit habit dialog' is fully related to the main changeset, which removes useHabitMetrics hook and updates EditHabitDialog to read metricDefinitions directly from the habit prop instead of fetching them.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

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

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch refactor/use-included-metric-data-in-edit-habit-dialog

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.

@relativeci
Copy link

relativeci bot commented Feb 1, 2026

#211 Bundle Size — 1.87MiB (~-0.01%).

af764bd(current) vs df7f052 main#210(baseline)

Warning

Bundle contains 2 duplicate packages – View duplicate packages

Bundle metrics  Change 1 change Improvement 1 improvement
                 Current
#211
     Baseline
#210
Improvement  Initial JS 1.11MiB(-0.01%) 1.11MiB
No change  Initial CSS 0B 0B
No change  Cache Invalidation 87.3% 87.3%
No change  Chunks 8 8
No change  Assets 9 9
No change  Modules 6686 6686
No change  Duplicate Modules 0 0
No change  Duplicate Code 0% 0%
No change  Packages 223 223
No change  Duplicate Packages 2 2
Bundle size by type  Change 1 change Improvement 1 improvement
                 Current
#211
     Baseline
#210
Improvement  JS 1.63MiB (~-0.01%) 1.63MiB
No change  CSS 243.46KiB 243.46KiB

Bundle analysis reportBranch refactor/use-included-metric-dat...Project dashboard


Generated by RelativeCIDocumentationReport issue

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

🤖 Fix all issues with AI agents
In `@src/components/habit/EditHabitDialog.tsx`:
- Around line 65-76: The mapping from habit.metricDefinitions to localMetrics
uses an unchecked cast (m.config as LocalMetricDefinition['config']) which can
hide incompatibilities; replace the cast by either validating/transforming
m.config with a type guard or converter function (e.g., isValidLocalMetricConfig
or normalizeMetricConfig) and use a concise spread mapping (map(m => ({ ...m,
config: normalizeMetricConfig(m.config) }))) so LocalMetricDefinition fields are
constructed safely; update the mapping in EditHabitDialog.tsx (localMetrics and
the map callback) to call the validator/converter and remove the raw type
assertion.
🧹 Nitpick comments (1)
src/components/habit/EditHabitDialog.tsx (1)

1-25: Consider organizing imports per perfectionist plugin rules.

The imports could be better organized according to the perfectionist plugin configuration specified in the coding guidelines. Typically, external packages should be sorted alphabetically, followed by internal path aliases.

Expected organization:

  1. External packages in alphabetical order: react before @heroui/react
  2. Internal aliases in alphabetical order (currently correct: @components, @hooks, @models, @stores, @utils)

As per coding guidelines: Apply ESLint v9 flat config rules and use perfectionist plugin for import organization.

Comment on lines +65 to +76
const localMetrics: LocalMetricDefinition[] = habit.metricDefinitions.map(
(m) => {
return {
config: m.config as LocalMetricDefinition['config'],
id: m.id,
isRequired: m.isRequired,
name: m.name,
sortOrder: m.sortOrder,
type: m.type,
};
}
);
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 | 🟠 Major

Verify type safety and consider simplifying the mapping.

The type cast on line 68 (m.config as LocalMetricDefinition['config']) asserts type compatibility without validation. If habit.metricDefinitions[].config doesn't match LocalMetricDefinition['config'], this could cause runtime issues.

Additionally, the explicit return statement and property-by-property mapping could be simplified using object spread or direct return.

Run the following script to examine the type definitions and verify compatibility:

#!/bin/bash
# Description: Check type definitions for Habit metricDefinitions config vs LocalMetricDefinition config

# Find LocalMetricDefinition type definition
echo "=== LocalMetricDefinition type ==="
ast-grep --pattern 'type LocalMetricDefinition = {
  $$$
}'

# Find MetricDefinition interface/type in models
echo -e "\n=== MetricDefinition in models ==="
rg -A 10 'type MetricDefinition|interface MetricDefinition' --type=ts

# Find Habit type definition to see metricDefinitions property
echo -e "\n=== Habit type metricDefinitions property ==="
rg -A 20 'type Habit|interface Habit' --type=ts | rg -A 20 'metricDefinitions'
♻️ Optional: Simplify the mapping
-      const localMetrics: LocalMetricDefinition[] = habit.metricDefinitions.map(
-        (m) => {
-          return {
-            config: m.config as LocalMetricDefinition['config'],
-            id: m.id,
-            isRequired: m.isRequired,
-            name: m.name,
-            sortOrder: m.sortOrder,
-            type: m.type,
-          };
-        }
-      );
+      const localMetrics: LocalMetricDefinition[] = habit.metricDefinitions.map(
+        (m) => ({
+          config: m.config as LocalMetricDefinition['config'],
+          id: m.id,
+          isRequired: m.isRequired,
+          name: m.name,
+          sortOrder: m.sortOrder,
+          type: m.type,
+        })
+      );
🤖 Prompt for AI Agents
In `@src/components/habit/EditHabitDialog.tsx` around lines 65 - 76, The mapping
from habit.metricDefinitions to localMetrics uses an unchecked cast (m.config as
LocalMetricDefinition['config']) which can hide incompatibilities; replace the
cast by either validating/transforming m.config with a type guard or converter
function (e.g., isValidLocalMetricConfig or normalizeMetricConfig) and use a
concise spread mapping (map(m => ({ ...m, config:
normalizeMetricConfig(m.config) }))) so LocalMetricDefinition fields are
constructed safely; update the mapping in EditHabitDialog.tsx (localMetrics and
the map callback) to call the validator/converter and remove the raw type
assertion.

@domhhv domhhv merged commit df969ef into main Feb 1, 2026
11 checks passed
@domhhv domhhv deleted the refactor/use-included-metric-data-in-edit-habit-dialog branch February 1, 2026 17:32
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