feat(preference): add InputHintOption for structured input options#1378
feat(preference): add InputHintOption for structured input options#1378whoAbhishekSah merged 11 commits intomainfrom
Conversation
Add InputHintOption struct with name and title fields for user-friendly option display. The InputOptions field in Trait allows specifying both machine-readable names and display titles. - Add InputHintOption struct - Add InputOptions field to Trait (takes precedence over InputHints) - Add NewSelectValidatorFromOptions function Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughAdds InputHintOption and InputOptions to Trait, Preference.ValueTitle, Trait.GetValueTitle, and NewSelectValidatorFromOptions; GetValidator now prefers InputOptions for select/combobox; service Create and LoadUserPreferences populate Preference.ValueTitle; API/schema and validation updated to include InputHintOption and value_title. Changes
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related PRs
Suggested reviewers
🚥 Pre-merge checks | ✅ 1 | ❌ 2❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (1 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Fix all issues with AI agents
In `@core/preference/preference.go`:
- Around line 108-112: The TraitInputMultiselect branch incorrectly routes to
NewSelectValidatorFromOptions (used by TraitInputSelect/Combobox) causing
comma-separated values like "1,3" to fail SelectValidator.Validate; fix by
changing handling of TraitInputMultiselect in the switch so it does not use
SelectValidator: either return NewTextValidator() for TraitInputMultiselect
(simple fallback) or implement and return a new NewMultiselectValidator that
splits on commas, trims each token and validates each against the options
(mirroring SelectValidator logic for individual tokens). Update the branch that
currently checks len(t.InputOptions) > 0 (and the case label
TraitInputMultiselect) to use the chosen approach and ensure tests referencing
multiselect behavior pass.
In `@core/preference/validator.go`:
- Around line 59-70: NewSelectValidatorFromOptions currently appends raw
opt.Name values which can contain surrounding whitespace and cause mismatches;
update the function (NewSelectValidatorFromOptions) to trim whitespace (e.g.,
strings.TrimSpace) from each InputHintOption.Name before adding to allowedValues
and skip entries that are empty after trimming so the
SelectValidator.allowedValues list is normalized and matches NewSelectValidator
behavior.
- Add ValueTitle field to Preference struct - Add GetValueTitle method to Trait for looking up title from InputOptions - Populate ValueTitle in LoadUserPreferences from trait's InputOptions - Only applies to select/combobox/multiselect input types Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@core/preference/preference.go`:
- Around line 132-140: The GetValueTitle method on Trait currently only matches
opt.Name exactly so comma-separated multiselect inputs like "opt1,opt2" return
empty; update Trait.GetValueTitle to detect if value contains commas, split by
"," (use strings.Split and strings.TrimSpace), look up each token against
t.InputOptions matching opt.Name to collect opt.Title values, then return the
joined titles (e.g., strings.Join with ", " or similar); ensure you add import
"strings" if not present and preserve existing exact-match behavior when value
has no commas.
- Update PROTON_COMMIT to include InputHintOption and value_title changes - Regenerate proto stubs - Fix multiselect to use text validator (not select validator) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Pull Request Test Coverage Report for Build 22059148885Warning: This coverage report may be inaccurate.This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.
Details
💛 - Coveralls |
- Add ValueTitle to Preference proto response for human-readable display - Add InputOptions to PreferenceTrait proto response for select/combobox Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
The Create method now populates ValueTitle from the matched trait's InputOptions before returning the created preference. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
core/preference/service.go (1)
136-151:⚠️ Potential issue | 🟡 MinorValueTitle is inconsistently exposed across API implementations.
While
CreateandLoadUserPreferencescorrectly populateValueTitle, the service methodsGetandListdo not enrich the response. More critically, the two API implementations handle this differently:
internal/api/v1beta1connect/preferences.go: includesValueTitlein the transformed responseinternal/api/v1beta1/preferences.go: omitsValueTitlefrom the response entirelyThis creates inconsistent data shapes depending on which API endpoint (Connect vs REST) clients use. Align the implementations by either:
- Populating
ValueTitleinGetandListservice methods (consistent withCreate)- Or explicitly document this field only applies to
Createresponses- Or update
v1beta1to includeValueTitlelikev1beta1connectdoes
…nces - Add tests verifying ValueTitle is populated from InputOptions - Test Create method populates ValueTitle in response - Test LoadUserPreferences populates ValueTitle for DB and default preferences Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
e0e1325 to
a058cdf
Compare
…iption Update proton commit to f0e1082c79c700a84e6da11ca75a80ab6420bc00. Align handler with proto field renames: InputHintOption.title → description, Preference.value_title → value_description. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The domain struct InputHintOption used Title (yaml: "title") but the YAML config and proto both use "description", causing value_description to always be empty. Renamed ValueTitle → ValueDescription and GetValueTitle → GetValueDescription throughout. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Consistent with NewSelectValidator which trims option names from comma-separated input_hints. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Summary
Add
InputHintOptionstruct andInputOptionsfield to support user-friendly option display in preference traits. Thevalue_descriptionfield is now returned in API responses showing the human-readable description for the selected value.Changes
core/preference/preference.go
core/preference/validator.go
NewSelectValidatorFromOptions()to validate against InputOptions namescore/preference/service.go
CreatepopulatesValueDescriptionfrom matched trait's InputOptionsLoadUserPreferencespopulatesValueDescriptionfor both DB and default preferencesinternal/api/v1beta1connect/preferences.go
transformPreferenceToPBincludesValueDescriptionin responsetransformPreferenceTraitToPBincludesInputOptionsin responseExample Response
ListCurrentUserPreferencesnow returnsvalue_description:{ "preferences": [ { "id": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", "name": "newsletter", "value": "true", "resource_id": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", "resource_type": "app/user", "scope_type": "", "scope_id": "", "value_description": "", "created_at": "2026-02-05T08:14:49.526Z", "updated_at": "2026-02-11T08:28:26.119Z" }, { "id": "", "name": "unit_area", "value": "sq_km", "resource_id": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", "resource_type": "app/user", "scope_type": "", "scope_id": "", "value_description": "Square Kilometers", "created_at": "0001-01-01T00:00:00.000Z", "updated_at": "0001-01-01T00:00:00.000Z" } ] }Note:
value_descriptionis populated for traits withinput_optionsconfigured (likeunit_area). For traits withoutinput_options(likenewsletter), it remains empty.CreateCurrentUserPreferencesalso returnsvalue_descriptionin the response.Usage
Dependencies
🤖 Generated with Claude Code