Skip to content

fix(ui): default measurement value-type by measurement type (#604) - #815

Open
skearnes wants to merge 1 commit into
mainfrom
fix/604-measurement-value-default
Open

fix(ui): default measurement value-type by measurement type (#604)#815
skearnes wants to merge 1 commit into
mainfrom
fix/604-measurement-value-default

Conversation

@skearnes

@skearnes skearnes commented Jun 23, 2026

Copy link
Copy Markdown
Member

Closes #604.

Problem

The Product Measurements value field always preselected the % value-type for every measurement type — so e.g. a Selectivity measurement defaulted to %, which is wrong for a ratio.

Cause

MeasurementValueControl used a single global defaultValueType = Percent with no per-type branching.

Fix

Pick the default value-type from the measurement's own type (MeasurementValueControl.tsx):

  • Yield / Purity → %
  • Amount → Mass
  • everything else (Selectivity, Area, Counts, Intensity, Custom, …) → Number

Only applies when no value has been entered yet; saved measurements keep their stored type.

Tests

Parametrized tests assert the preselected value-type per measurement type (Selectivity→Number, Yield/Purity→%, Amount→Mass, Area→Number); existing numeric-render/view-only tests retained (mock updated for the new getValues read). tsc -b + lint green.

🤖 Generated with Claude Code

Greptile Summary

This PR fixes the Product Measurements UI always pre-selecting % as the value-type regardless of measurement kind. A per-type lookup map (YIELD/PURITY → Percent, AMOUNT → Mass, everything else → Number) now drives the default, applied only when no value has yet been stored.

  • Adds measurementTypeToDefaultValueType and buildDefaultMeasurementValue, reading the sibling type field via formMethods.getValues(), replacing the former hard-coded Percent default.
  • Test helper updated with a getValues stub and a parametrized it.each block asserting the correct pre-selection for Selectivity, Yield, Purity, Amount, and Area; field name corrected from "measurement" to "value" to match the actual form model.

Confidence Score: 5/5

Safe to merge — the change is narrowly scoped to the unset-value path, existing saved measurements are unaffected, and the new lookup map covers all types listed in valueCompatibleTypes.

The fix is small, well-bounded, and fully exercised by the updated parametrized tests. The getValues() call reads live form state (the parent re-renders on every dropdown change in Mantine's useForm, so the snapshot is always fresh on remount). No regressions introduced to saved data or view-only mode.

No files require special attention.

Important Files Changed

Filename Overview
ui/src/features/reactions/ReactionEntities/entityFormConfiguration/measurements/MeasurementValueControl/MeasurementValueControl.tsx Replaces single Percent default with a per-measurement-type lookup; adds buildDefaultMeasurementValue using getValues()?.type — logic is sound, types are safe, and only applies when no value has been entered.
ui/src/features/reactions/ReactionEntities/entityFormConfiguration/measurements/MeasurementValueControl/MeasurementValueControl.test.tsx Adds makeFormMethods factory with getValues stub, corrects name from "measurement" to "value", and adds parametrized per-measurement-type default assertions. Coverage is good.

Reviews (1): Last reviewed commit: "fix(ui): default measurement value-type ..." | Re-trigger Greptile

A single global "%" default was applied to every measurement's value, which is
wrong for non-percentage types (e.g. a Selectivity ratio preselected as %).
Replace it with a per-measurement-type default: Yield/Purity → %, Amount → Mass,
and everything else (Selectivity, Area, Counts, Intensity, Custom, …) → Number.
Only affects measurements with no value yet; saved values keep their stored type.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@pulumi

pulumi Bot commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

🤖 Pulumi Neo didn't review this pull request: no Pulumi preview ran for it. Agentic reviews require a preview of the affected stacks (for example from your CI's pulumi preview).

@sonarqubecloud

Copy link
Copy Markdown

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.

Measurements Sidebar in Product: Preselected fields for Selectivity value is String.

1 participant