feat: cascading & role-gated select options via option.visibleWhen (#2284)#2289
Merged
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
…ia option.visibleWhen (#2284) Select options now accept a per-option `visibleWhen` CEL predicate, evaluated against the live record + `current_user` (same engine/env as a field-level `visibleWhen`). Combined with a field-level `dependsOn`, this drives dependent selects (country → province → city) and role/context gating — reusing the same primitives dependent lookups (#2215) already use, no bespoke matrix. - core: new `resolveVisibleOptions` / `isOptionGroupGated` / `resolveDependsOnFields` / `isValueStillOffered` evaluator helpers, built on the canonical `evalFieldPredicate`. - components: the form renderer narrows a dependent select's options, gates the control with a "Select {parent} first" hint while a `dependsOn` field is empty, and clears a now-invalid value on parent change. - fields: `SelectField` applies the same resolution via `dependentValues` + the global predicate scope. - types: mirror `SelectOption.visibleWhen` (aligns with @objectstack/spec). - tests, docs (fields/select.mdx), schema-catalog example, and the schema-expressions skill guide. Client-side hiding is UX only — authorization-gated option values must also be enforced server-side. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019aYFm77ddLp6tzuJjt9hK2
os-zhuang
force-pushed
the
claude/cascading-form-input-nt2tvy
branch
from
July 5, 2026 12:48
574d01b to
705f7bb
Compare
Contributor
✅ Console Performance Budget
📦 Bundle Size Report
Size Limits
|
os-zhuang
marked this pull request as ready for review
July 5, 2026 13:01
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #2284.
What & why
Frontend forms need cascading / dependent selects (country → province → city) and role/context-gated options. Rather than invent a Salesforce-style
validFor/controllingFieldmatrix, this reuses the two primitives the codebase already has — so the mechanism is uniform with dependent lookups (#2215) and both humans and AI author it correctly by pattern-matching:SelectOption.visibleWhen— a per-option CEL predicate; the option is offered only when TRUE, evaluated against the liverecordpluscurrent_user(same engine/env as a field-levelvisibleWhen).field.dependsOn— declares the sibling field(s) the option list reacts to; while any is empty the control is gated ("Select country first"), and a parent change auto-clears a now-invalid value.The two purposes — cascade (record fields) and role gating (
current_user) — are the same predicate;dependsOnandvisibleWhenstay orthogonal (an option can havevisibleWhenwith nodependsOn).Changes
@object-ui/core— new evaluator helpersresolveVisibleOptions/isOptionGroupGated/resolveDependsOnFields/isValueStillOffered, built on the canonicalevalFieldPredicate(@objectstack/formula).@object-ui/components— the form renderer narrows a dependent select's options, gates with a "Select {parent} first" hint, and clears a now-invalid value on parent change (newusePredicateScope()wiring forcurrent_user).@object-ui/fields—SelectFieldapplies the same resolution viadependentValues+ the global predicate scope.@object-ui/types— mirrorSelectOption.visibleWhenonSelectOption/SelectOptionMetadata(aligns with@objectstack/spec).content/docs/fields/select.mdx, afields-select/cascading-optionsschema-catalog demo, theschema-expressionsskill guide, and the@object-ui/fieldsREADME.Security
Client-side hiding is UX, not authorization — a
visibleWhenonly removes the choice from the dropdown; the value is still submittable. For authorization-gated options the server must also reject writes of that value (rule-validator evaluates the picked value'svisibleWhen). Documented in the field docs and skill.Depends on spec
Requires
SelectOption.visibleWhenin@objectstack/spec— see companion PR objectstack-ai/framework#[spec] (claude/cascading-select-visiblewhen). The objectui types mirror the spec, as withdependsOn/visibleWhen.Tests
@object-ui/coreoptionRules.test.ts— cascade filtering, gating, role gating via scope, cascade-clear decision (13).@object-ui/fieldsSelectField.cascade.test.tsx— gate hint, unlock, cascade clear, role gating (6).@object-ui/componentsform-cascading-select.test.tsx— inline renderer gate transition end-to-end (1).standard-widgets/ form suites pass unchanged.@object-ui/fieldsclosure builds (tsc) clean.🤖 Generated with Claude Code
https://claude.ai/code/session_019aYFm77ddLp6tzuJjt9hK2
Generated by Claude Code