Skip to content

refactor(types): name the trait value shape - #8366

Open
talissoncosta wants to merge 1 commit into
mainfrom
refactor/trait-value-type-8365
Open

refactor(types): name the trait value shape#8366
talissoncosta wants to merge 1 commit into
mainfrom
refactor/trait-value-type-8365

Conversation

@talissoncosta

@talissoncosta talissoncosta commented Aug 25, 2026

Copy link
Copy Markdown
Contributor
  • I have read the Contributing Guide.
  • I have added information to docs/ if required so people know about the feature.
  • I have filled in the "Changes" section below.
  • I have filled in the "How did you test this code" section below.

Changes

Closes #8365, follow-up to Wadii's comment on #8344.

featureStateToValue cast an inline { value_type?: ... } to read the type key core traits use, so the key was tied to nothing and a rename was silent. TraitValue names that shape and in narrows the union instead. Utils.valueToTrait gets the same type as its return, which is the half that actually catches renames.

How did you test this code?

  • 14 unit tests passing, with the trait cases typed rather than cast
  • tsc error count unchanged against main
  • Renaming value_type now fails in the consumer, the producer and the tests. Before, nowhere

featureStateToValue asserted an inline `{ value_type?: ... }` to read the
type key core traits use, so the key was tied to nothing and a rename was
silent. TraitValue names the shape, `in` narrows the union instead of
asserting, and annotating Utils.valueToTrait as the producer means both
ends of the contract share one type.

float_value and 'float' are included because traits carry both
(api/environments/identities/traits/models.py).

Closes #8365

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

vercel Bot commented Aug 25, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
flagsmith-frontend-preview Ready Ready Preview Aug 25, 2026 5:27pm
flagsmith-frontend-staging Ready Ready Preview Aug 25, 2026 5:27pm
1 Skipped Deployment
Project Deployment Actions Updated (UTC)
docs Ignored Ignored Aug 25, 2026 5:27pm

Request Review

@coderabbitai

coderabbitai Bot commented Aug 25, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The change adds the exported TraitValue response type with nullable trait fields and a value_type discriminator. featureStateToValue now accepts TraitValue and resolves its discriminator directly. valueToTrait declares TraitValue as its return type. Tests cover integer, float, boolean, and unicode trait values with compile-time type checks.

Estimated code review effort: 2 (Simple) | ~10 minutes

Merge Risk: ⚪ Minimal · up to be06c

The change preserves behavior while naming the trait-value shape; the remaining inline-union style issue is localized and non-blocking, so the PR is merge-ready after normal checks.

✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Create stacked PR
  • Commit on current branch

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.

@github-actions github-actions Bot added the front-end Issue related to the React Front End Dashboard label Aug 25, 2026
@talissoncosta talissoncosta changed the title Add a shared TraitValue type instead of casting value_type refactor(types): name the trait value shape Aug 25, 2026
@talissoncosta
talissoncosta marked this pull request as ready for review August 25, 2026 17:29
@talissoncosta
talissoncosta requested a review from a team as a code owner August 25, 2026 17:29
@talissoncosta
talissoncosta requested review from kyle-ssg and removed request for a team August 25, 2026 17:29
@github-actions

github-actions Bot commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

Docker builds report

Image Build Status Security report
ghcr.io/flagsmith/flagsmith-api-test:pr-8366 Finished ✅ Skipped
ghcr.io/flagsmith/flagsmith-e2e:pr-8366 Finished ✅ Skipped
ghcr.io/flagsmith/flagsmith-api:pr-8366 Finished ✅ Results
ghcr.io/flagsmith/flagsmith:pr-8366 Finished ✅ Results
ghcr.io/flagsmith/flagsmith-private-cloud:pr-8366 Finished ✅ Results
ghcr.io/flagsmith/flagsmith-frontend:pr-8366 Finished ✅ Results

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 692c445b-67f1-4f45-97da-4e79702e05f4

📥 Commits

Reviewing files that changed from the base of the PR and between 0212201 and be06c26.

📒 Files selected for processing (4)
  • frontend/common/types/responses.ts
  • frontend/common/utils/__tests__/featureStateToValue.test.ts
  • frontend/common/utils/featureStateToValue.ts
  • frontend/common/utils/utils.tsx

Included review availability: Your plan provides up to 8 included reviews per hour; 7 remain after this review.

float_value?: number | null
integer_value: number | null
string_value: string | null
value_type: 'int' | 'unicode' | 'bool' | 'float'

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

📐 Maintainability & Code Quality | 🟠 Major | ⚡ Quick win

Extract the inline value_type union into a named type.

Line 605 adds an inline union type. The frontend TypeScript guideline requires union types to use named aliases. Define a named alias such as TraitValueType and use it for TraitValue.value_type. Reuse the alias for FeatureStateValue.type if both fields share the same contract.

As per coding guidelines: frontend/**/*.{ts,tsx} requires inline union types to be extracted into named types.

Proposed refactor
+export type TraitValueType = 'int' | 'unicode' | 'bool' | 'float'
+
 export type TraitValue = {
   boolean_value: boolean | null
   float_value?: number | null
   integer_value: number | null
   string_value: string | null
-  value_type: 'int' | 'unicode' | 'bool' | 'float'
+  value_type: TraitValueType
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
value_type: 'int' | 'unicode' | 'bool' | 'float'
export type TraitValueType = 'int' | 'unicode' | 'bool' | 'float'
export type TraitValue = {
boolean_value: boolean | null
float_value?: number | null
integer_value: number | null
string_value: string | null
value_type: TraitValueType
}

Source: Coding guidelines

@github-actions

github-actions Bot commented Aug 25, 2026

Copy link
Copy Markdown
Contributor
✅ private-cloud · depot-ubuntu-latest-arm-16 — run #19755 (attempt 1)

Playwright Test Results (private-cloud - depot-ubuntu-latest-arm-16)

passed  2 passed

Details

stats  2 tests across 2 suites
duration  38.7 seconds
commit  be06c26
info  🔄 Run: #19755 (attempt 1)

🗂️ Previous results
✅ private-cloud · depot-ubuntu-latest-16 — run #19755 (attempt 1)

Playwright Test Results (private-cloud - depot-ubuntu-latest-16)

passed  1 passed

Details

stats  1 test across 1 suite
duration  35.8 seconds
commit  be06c26
info  🔄 Run: #19755 (attempt 1)

✅ oss · depot-ubuntu-latest-arm-16 — run #19755 (attempt 1)

Playwright Test Results (oss - depot-ubuntu-latest-arm-16)

passed  1 passed

Details

stats  1 test across 1 suite
duration  46.2 seconds
commit  be06c26
info  🔄 Run: #19755 (attempt 1)

✅ oss · depot-ubuntu-latest-16 — run #19755 (attempt 1)

Playwright Test Results (oss - depot-ubuntu-latest-16)

passed  1 passed

Details

stats  1 test across 1 suite
duration  36.3 seconds
commit  be06c26
info  🔄 Run: #19755 (attempt 1)

@github-actions

Copy link
Copy Markdown
Contributor

Visual Regression

19 screenshots compared. See report for details.
View full report

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

front-end Issue related to the React Front End Dashboard refactor

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add a shared TraitValue type instead of casting value_type

2 participants