Skip to content

Conversation

@IgnisDa
Copy link
Owner

@IgnisDa IgnisDa commented Feb 3, 2026

Introduce an add button for measurement tracking, streamline the statistics update logic, and enhance the user interface for managing measurements. Refactor the measurements section into a dedicated component for better organization and maintainability. Update notification handling for demo users in preferences and add unit display to measurement statistics inputs. Additionally, provide informational text regarding measurement removal in preferences.

Fixes #1689.

Summary by CodeRabbit

  • New Features

    • Drag-and-drop support for organizing measurements in settings
    • New, dedicated measurements panel with per-item add/remove controls
  • Improvements

    • Measurement inputs now show units in labels
    • Disabled-state messaging and controls clarified for a smoother editing experience
  • Refactor

    • Measurements UI restructured for more consistent state handling and editing flow

Extract the measurements configuration UI (approximately 160 lines) into a
standalone MeasurementsSection component to improve code organization and
maintainability. This reduces complexity in the main Page component while
keeping all functionality intact, including drag-and-drop reordering,
add/remove operations, and form state management.

The component follows project conventions by using a single props parameter
and maintaining proper TypeScript typing.
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 3, 2026

Walkthrough

Extracted measurements UI into a new MeasurementsSection with drag-and-drop reordering; measurement form labels now include units and onChange handlers update the form's statistics array directly. EditDashboardElement signature now accepts an isEditDisabled prop; notificationContent renamed to disabledNotificationContent.

Changes

Cohort / File(s) Summary
Measurements settings UI
apps/frontend/app/routes/_dashboard.settings.preferences.tsx
Extracted inline measurement UI into a new MeasurementsSection component using DragDropContext/Droppable/Draggable. Renamed notificationContentdisabledNotificationContent. EditDashboardElement props now include isEditDisabled; measurements rendering and controls moved into the new component and receive form/isEditDisabled via props.
Measurement form updates
apps/frontend/app/components/routes/dashboard/forms/create-or-update-measurement-form.tsx
Adjusted buildInput return to use a parenthesized object cast. Statistics rendering now destructures entries to include unit; NumberInput labels append unit when present. Each NumberInput onChange now updates/inserts the corresponding statistics entry and calls form.setFieldValue("information.statistics", newStatistics) directly.

Sequence Diagram

sequenceDiagram
    participant User
    participant MeasurementsSection
    participant DragDropContext as Drag-Drop Context
    participant FormState as Form State

    User->>MeasurementsSection: Drag item
    MeasurementsSection->>Drag-Drop Context: onDragEnd(event)
    Drag-Drop Context-->>MeasurementsSection: {sourceIndex, destinationIndex}
    MeasurementsSection->>MeasurementsSection: Reorder measurements array
    MeasurementsSection->>Form State: form.setFieldValue("information.statistics", newArray)
    Form State-->>MeasurementsSection: Updated form values
    MeasurementsSection->>User: Render reordered list
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 3 | ❌ 2
❌ Failed checks (2 warnings)
Check name Status Explanation Resolution
Linked Issues check ⚠️ Warning The PR partially addresses #1689: it implements reordering via drag-and-drop but does not provide a warning or safe rename mechanism for measurement name changes. Implement either a warning dialog when renaming measurements or a mechanism to preserve historical values during rename operations to fully address #1689.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ 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 references both measurement tracking UI enhancement and preferences handling, which align with the primary changes: MeasurementsSection refactor and notification handling updates.
Out of Scope Changes check ✅ Passed Changes include the MeasurementsSection refactor, drag-and-drop reordering, unit display, notification handling updates, and immutable statistics handling—all directly supporting the PR objectives.

✏️ 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 IgnisDa/issue1689

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
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: 3

🤖 Fix all issues with AI agents
In
`@apps/frontend/app/components/routes/dashboard/forms/create-or-update-measurement-form.tsx`:
- Around line 117-126: The onChange handler for updating statistics mutates
objects inside form.values.information.statistics via newStatistics[idx].value =
..., causing direct state mutation; fix by creating a new array with a new
object for the replaced item (e.g., map or slice + object spread) instead of
mutating the existing object, then call
form.setFieldValue("information.statistics", newArray); ensure you update only
the matching item by name and leave others as new references so form libraries
detect the change (refer to the onChange closure,
form.values.information.statistics, and form.setFieldValue).

In `@apps/frontend/app/routes/_dashboard.settings.preferences.tsx`:
- Around line 708-722: The onDragEnd handler inside DragDropContext currently
uses destination?.index || 0 which moves items to index 0 when destination is
undefined; update the onDragEnd callback to early-return if destination is falsy
(i.e., if (!destination) return) before calling reorder and
props.form.setFieldValue, preserving order when dropped outside; keep the
existing props.isEditDisabled guard and
notifications.show(disabledNotificationContent) behavior for disabled edits and
apply the same early-return pattern to the other DragDropContext onDragEnd that
also uses reorder.
- Around line 731-734: The key currently uses the array index
(key={`measurement-${index}`}) which breaks reconciliation for
reorderable/drag-and-drop lists; change the component to use a stable identifier
(e.g., measurement.id) instead of index and, if measurements lack an id, assign
a UUID when a measurement is created/added (update the
addMeasurement/createMeasurement logic to set id). Replace
key={`measurement-${index}`} with something like
key={`measurement-${measurement.id}`} and ensure all places that construct new
measurement objects generate and persist the stable id.

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: 2

🤖 Fix all issues with AI agents
In `@apps/frontend/app/routes/_dashboard.settings.preferences.tsx`:
- Around line 705-707: The UI currently only warns about removing measurements
(the Text size="xs" c="dimmed" message) but allows renaming in the measurement
rename flow (the rename input/handler around lines 766-781) without any warning;
update the small help text to mention that renaming a measurement will also
affect history visibility and then add a confirmation/warning step in the rename
handler (the function that processes the rename action in the measurement rename
flow) that prompts the user to confirm the rename or choose to preserve history,
ensuring the confirmation includes the same wording as the updated Text and
blocks the rename unless the user explicitly accepts.
- Around line 681-685: Extract the MeasurementsSection React component into its
own module: create a new file exporting the MeasurementsSection component (named
export or default) that accepts props { isEditDisabled: boolean; form:
ReturnType<typeof useForm<UserPreferences>> } and preserve its internal JSX and
imports (bring over any used hooks, types like UserPreferences and useForm, and
UI components). In the original file replace the component definition with an
import of MeasurementsSection and update any relative imports/types as needed so
TypeScript compiles (ensure you export the component from the new module and
update the original file’s import statement). Run a quick build/TS check and
update any tests or story references that referenced MeasurementsSection
directly. Ensure the original file size drops below the 500-line guideline.

Comment on lines +681 to +685
const MeasurementsSection = (props: {
isEditDisabled: boolean;
form: ReturnType<typeof useForm<UserPreferences>>;
}) => (
<Stack gap="xs">
Copy link
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick | 🔵 Trivial

Consider extracting MeasurementsSection to keep the file under 500 lines.
This file is ~950 lines; moving MeasurementsSection to its own module would align with the 500-line guideline and improve maintainability.

As per coding guidelines: Keep code files below 500 lines. If a file exceeds this limit, split it into smaller files using functions, components, or modules to improve readability and maintainability.

🤖 Prompt for AI Agents
In `@apps/frontend/app/routes/_dashboard.settings.preferences.tsx` around lines
681 - 685, Extract the MeasurementsSection React component into its own module:
create a new file exporting the MeasurementsSection component (named export or
default) that accepts props { isEditDisabled: boolean; form: ReturnType<typeof
useForm<UserPreferences>> } and preserve its internal JSX and imports (bring
over any used hooks, types like UserPreferences and useForm, and UI components).
In the original file replace the component definition with an import of
MeasurementsSection and update any relative imports/types as needed so
TypeScript compiles (ensure you export the component from the new module and
update the original file’s import statement). Run a quick build/TS check and
update any tests or story references that referenced MeasurementsSection
directly. Ensure the original file size drops below the 500-line guideline.

Comment on lines +705 to +707
<Text size="xs" c="dimmed">
Removing a measurement will hide its past values from history. If you add
it again, those values will show back up.
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

Warn on renaming measurements to avoid silent history loss.
Line 705-707 only mentions removal, but Line 766-781 allows renaming without warning; per the issue objective, users should be warned or history preserved.

✏️ Suggested warning update
-		<Text size="xs" c="dimmed">
-			Removing a measurement will hide its past values from history. If you add
-			it again, those values will show back up.
-		</Text>
+		<Text size="xs" c="dimmed">
+			Renaming or removing a measurement will hide its past values from history.
+			If you add it again using the original name, those values will show back up.
+		</Text>

Also applies to: 766-781

🤖 Prompt for AI Agents
In `@apps/frontend/app/routes/_dashboard.settings.preferences.tsx` around lines
705 - 707, The UI currently only warns about removing measurements (the Text
size="xs" c="dimmed" message) but allows renaming in the measurement rename flow
(the rename input/handler around lines 766-781) without any warning; update the
small help text to mention that renaming a measurement will also affect history
visibility and then add a confirmation/warning step in the rename handler (the
function that processes the rename action in the measurement rename flow) that
prompts the user to confirm the rename or choose to preserve history, ensuring
the confirmation includes the same wording as the updated Text and blocks the
rename unless the user explicitly accepts.

@IgnisDa IgnisDa merged commit 917c682 into main Feb 3, 2026
14 checks passed
@IgnisDa IgnisDa deleted the IgnisDa/issue1689 branch February 3, 2026 18:17
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.

Allow for Reordering of Measurements

2 participants