Skip to content

refactor(featureStateToValue): extract into a Flux-free module - #8344

Merged
talissoncosta merged 1 commit into
mainfrom
refactor/decouple-feature-state-value
Aug 25, 2026
Merged

refactor(featureStateToValue): extract into a Flux-free module#8344
talissoncosta merged 1 commit into
mainfrom
refactor/decouple-feature-state-value

Conversation

@talissoncosta

Copy link
Copy Markdown
Contributor

Changes

Contributes to #8337 (follow-up to #8341)

Utils.featureStateToValue is a pure function, but it lives in utils.tsx, which imports the Flux stores (AccountStore/ProjectStore) at module load. That import chain breaks any unit-tested consumer, which is why #8341's deep-link hook had to inline its own copy of the flatten logic.

This extracts it into common/utils/featureStateToValue.ts (types only, no Flux) and has Utils delegate to it via a shorthand re-export — so the ~22 existing Utils.featureStateToValue(...) callers are unchanged. The deep-link hook now imports the shared function and drops its duplicate.

The function is broadened while moving:

  • accepts an already-flat value (returned untouched), so the hook doesn't need a cast;
  • normalises a missing int/float to null.

This is the first step of decoupling the pure helpers from utils.tsx (which follows the existing common/utils/<name>.ts convention, e.g. ensureTrailingSlash, multivariate).

Note: stacked on fix/deeplink-feature-value-8337 (#8341). Retarget to main once that merges.

How did you test this code?

  • New common/utils/__tests__/featureStateToValue.test.ts: covers every type branch (bool/float/int/unicode), value_type for core traits, missing int/float → null, null/undefined → null, and already-flat passthrough.
  • deepLinkedFeature.test.ts: keeps the pickEnvironmentFlag behaviour tests plus one integration case proving the nested value is flattened via the shared function.
  • 20 unit tests pass; eslint + typecheck clean on the changed files.

@vercel

vercel Bot commented Aug 21, 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 3:31pm
flagsmith-frontend-staging Ready Ready Preview Aug 25, 2026 3:31pm
1 Skipped Deployment
Project Deployment Actions Updated (UTC)
docs Ignored Ignored Preview Aug 25, 2026 3:31pm

Request Review

@coderabbitai

coderabbitai Bot commented Aug 21, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Added the shared featureStateToValue utility. It converts nested feature-state and core-trait values, flat scalar values, and undefined values. It supports boolean, float, integer, and string representations. Updated Utils and pickEnvironmentFlag to use the utility. Added unit tests for conversion behaviour and retained focused Unicode integration coverage.

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

Merge Risk: 🟡 Moderate · up to fcc8b

The refactor centralizes feature-state flattening, but the current head still uses a disallowed relative import and does not model the typed core-trait input without a cast; these issues can break repository checks and weaken compile-time safety, so merge should wait for both fixes.


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 21, 2026
@talissoncosta talissoncosta changed the title Extract featureStateToValue into a Flux-free module refactor(featureStateToValue): extract into a Flux-free module Aug 21, 2026
@talissoncosta
talissoncosta marked this pull request as ready for review August 21, 2026 19:03
@talissoncosta
talissoncosta requested a review from a team as a code owner August 21, 2026 19:03
@talissoncosta
talissoncosta requested review from kyle-ssg and removed request for a team August 21, 2026 19:03
@github-actions

github-actions Bot commented Aug 21, 2026

Copy link
Copy Markdown
Contributor

Docker builds report

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

@github-actions

github-actions Bot commented Aug 21, 2026

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

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

passed  2 passed

Details

stats  2 tests across 2 suites
duration  38.8 seconds
commit  3c29081
info  🔄 Run: #19751 (attempt 1)

🗂️ Previous results
✅ oss · depot-ubuntu-latest-arm-16 — run #19751 (attempt 1)

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

passed  1 passed

Details

stats  1 test across 1 suite
duration  54.7 seconds
commit  3c29081
info  🔄 Run: #19751 (attempt 1)

✅ private-cloud · depot-ubuntu-latest-16 — run #19751 (attempt 1)

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

passed  2 passed

Details

stats  2 tests across 2 suites
duration  32.3 seconds
commit  3c29081
info  🔄 Run: #19751 (attempt 1)

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

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

passed  1 passed

Details

stats  1 test across 1 suite
duration  41.1 seconds
commit  3c29081
info  🔄 Run: #19751 (attempt 1)

✅ private-cloud · depot-ubuntu-latest-16 — run #19720 (attempt 1)

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

passed  2 passed

Details

stats  2 tests across 2 suites
duration  59.8 seconds
commit  ac9cdd1
info  🔄 Run: #19720 (attempt 1)

✅ private-cloud · depot-ubuntu-latest-arm-16 — run #19720 (attempt 1)

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

passed  3 passed

Details

stats  3 tests across 3 suites
duration  37.4 seconds
commit  ac9cdd1
info  🔄 Run: #19720 (attempt 1)

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

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

passed  1 passed

Details

stats  1 test across 1 suite
duration  44.3 seconds
commit  ac9cdd1
info  🔄 Run: #19720 (attempt 1)

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

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

passed  1 passed

Details

stats  1 test across 1 suite
duration  36.6 seconds
commit  ac9cdd1
info  🔄 Run: #19720 (attempt 1)

✅ private-cloud · depot-ubuntu-latest-arm-16 — run #19715 (attempt 1)

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

passed  1 passed

Details

stats  1 test across 1 suite
duration  1 minute, 1 second
commit  3f35fe7
info  🔄 Run: #19715 (attempt 1)

✅ private-cloud · depot-ubuntu-latest-16 — run #19715 (attempt 1)

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

passed  3 passed

Details

stats  3 tests across 3 suites
duration  32.4 seconds
commit  3f35fe7
info  🔄 Run: #19715 (attempt 1)

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

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

passed  1 passed

Details

stats  1 test across 1 suite
duration  45.4 seconds
commit  3f35fe7
info  🔄 Run: #19715 (attempt 1)

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

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

passed  1 passed

Details

stats  1 test across 1 suite
duration  41.5 seconds
commit  3f35fe7
info  🔄 Run: #19715 (attempt 1)

@github-actions

github-actions Bot commented Aug 21, 2026

Copy link
Copy Markdown
Contributor

Visual Regression

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

Zaimwa9
Zaimwa9 previously approved these changes Aug 24, 2026

@Zaimwa9 Zaimwa9 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

👍

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


ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 0cccb99f-04e2-4734-8fd0-297e1a2cedc3

📥 Commits

Reviewing files that changed from the base of the PR and between ac56c47 and fcc8bf6.

📒 Files selected for processing (5)
  • frontend/common/utils/__tests__/featureStateToValue.test.ts
  • frontend/common/utils/featureStateToValue.ts
  • frontend/common/utils/utils.tsx
  • frontend/web/components/pages/features/hooks/__tests__/deepLinkedFeature.test.ts
  • frontend/web/components/pages/features/hooks/deepLinkedFeature.ts

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

Comment thread frontend/common/utils/featureStateToValue.ts
Comment thread frontend/common/utils/utils.tsx

@Zaimwa9 Zaimwa9 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

One non blocking comment otherwise good to go

Comment thread frontend/common/utils/featureStateToValue.ts
Utils.featureStateToValue is a pure function, but it lives in utils.tsx,
which imports the Flux stores (AccountStore/ProjectStore) at module load.
That import chain breaks any unit-tested consumer, which is why the
deep-link hook had to inline its own copy of the flatten logic.

Move it to common/utils/featureStateToValue.ts (types only, no Flux) and
have Utils delegate via a shorthand re-export, so the ~22 existing callers
are unchanged. The deep-link hook now imports the shared function and
drops its duplicate. The function is broadened to also accept an
already-flat value (returned untouched) and to normalise a missing
int/float to null.

First step of decoupling the pure helpers from utils.tsx.

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

@Zaimwa9 Zaimwa9 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Giving the approval again as it stalled

@talissoncosta
talissoncosta merged commit 0212201 into main Aug 25, 2026
31 checks passed
@talissoncosta
talissoncosta deleted the refactor/decouple-feature-state-value branch August 25, 2026 17:20
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.

2 participants