Commit beaf779
authored
🤖 refactor: simplify stats tab experiment to toggle (#1224)
Convert the Stats Tab experiment setting from a 3-option dropdown to a
simple on/off toggle, matching the UX pattern used for other
experiments.
**Changes:**
- Replace dropdown with Switch component in ExperimentsSection
- Simplify FeatureFlagsContext API: `setStatsTabOverride` →
`setStatsTabEnabled`
- Remove PostHog implementation details from user-facing description
- Backend schema unchanged (preserves flexibility)
---
<details>
<summary>📋 Implementation Plan</summary>
# Plan: Simplify Stats Tab Experiment Toggle
## Goal
Convert the Stats Tab experiment from a 3-option dropdown (`Default
(experiment)`, `Always on`, `Always off`) to a simple on/off toggle,
matching the pattern used for other experiments like Post-Compaction
Context.
## Current State
- **UI**: `ExperimentsSection.tsx` renders `StatsTabOverrideRow` with a
`<select>` dropdown containing 3 options
- **Frontend context**: `FeatureFlagsContext.tsx` exposes
`StatsTabState` with `variant`, `override`, and `enabled` fields
- **Backend service**: `featureFlagService.ts` fetches PostHog variant
and applies 3-way override logic
- **Storage**: Backend stores override in `~/.mux/config.json` under
`featureFlagOverrides[stats_tab_v1]`
- **Schema**: `api.ts` defines `StatsTabOverrideSchema =
z.enum(["default", "on", "off"])`
## Proposed Changes
### 1. Frontend: Replace dropdown with toggle (~-30 LoC)
**File:
`src/browser/components/Settings/sections/ExperimentsSection.tsx`**
- Replace `StatsTabOverrideRow` with a simpler row using `<Switch>`:
- Label: "Stats tab"
- Description: "Show timing statistics in the right sidebar" (no PostHog
mention)
- Toggle reflects `statsTabState.enabled`
- Toggle calls `setStatsTabOverride("on" | "off")` based on new state
### 2. Context: Simplify `setStatsTabOverride` signature (~-5 LoC)
**File: `src/browser/contexts/FeatureFlagsContext.tsx`**
- `setStatsTabOverride(override: StatsTabOverride)` →
`setStatsTabEnabled(enabled: boolean)`
- Internally convert boolean to `"on" | "off"` when calling backend
- No more "default" option exposed to UI
### 3. Backend & Schema: Unchanged
The backend already stores `"on" | "off" | "default"` and computes
`enabled` based on PostHog variant + override. We keep this to allow
future flexibility, but the UI will only ever set `"on"` or `"off"`
(never `"default"`).
<details>
<summary>Alternative: Migrate to experiments system</summary>
We could move Stats Tab to the existing `EXPERIMENTS` +
`ExperimentsContext` pattern (localStorage-based), but:
- That would lose PostHog A/B tracking capability
- Would require data migration from `config.json` to localStorage
- The current feature flag service is already correct; simplifying the
UI is sufficient
This alternative is **not recommended** for this change.
</details>
## Net LoC Estimate
~-25 lines (remove dropdown complexity, add simpler toggle, simplify
context API)
## Files Modified
1. `src/browser/components/Settings/sections/ExperimentsSection.tsx`
2. `src/browser/contexts/FeatureFlagsContext.tsx`
## Testing
- Manual: Open Settings → Experiments → verify toggle works
- Existing typecheck and lint will catch regressions
</details>
---
_Generated with `mux` • Model: `anthropic:claude-opus-4-5` • Thinking:
`high`_
Signed-off-by: Thomas Kosiewski <tk@coder.com>1 parent 32712c6 commit beaf779
File tree
2 files changed
+29
-40
lines changed- src/browser
- components/Settings/sections
- contexts
2 files changed
+29
-40
lines changedLines changed: 18 additions & 24 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
9 | | - | |
| 9 | + | |
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
| |||
48 | 48 | | |
49 | 49 | | |
50 | 50 | | |
51 | | - | |
52 | | - | |
| 51 | + | |
| 52 | + | |
53 | 53 | | |
54 | | - | |
55 | | - | |
56 | | - | |
57 | | - | |
58 | | - | |
59 | | - | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
60 | 62 | | |
61 | 63 | | |
62 | 64 | | |
63 | 65 | | |
64 | 66 | | |
65 | | - | |
66 | | - | |
67 | | - | |
68 | | - | |
| 67 | + | |
69 | 68 | | |
70 | | - | |
71 | | - | |
72 | | - | |
73 | | - | |
74 | | - | |
75 | | - | |
76 | | - | |
77 | | - | |
78 | | - | |
79 | | - | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
80 | 74 | | |
81 | 75 | | |
82 | 76 | | |
| |||
105 | 99 | | |
106 | 100 | | |
107 | 101 | | |
108 | | - | |
| 102 | + | |
109 | 103 | | |
110 | 104 | | |
111 | 105 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
26 | 26 | | |
27 | 27 | | |
28 | 28 | | |
29 | | - | |
30 | | - | |
31 | | - | |
32 | 29 | | |
33 | 30 | | |
34 | | - | |
35 | | - | |
36 | 31 | | |
37 | 32 | | |
38 | 33 | | |
39 | 34 | | |
40 | 35 | | |
41 | | - | |
| 36 | + | |
42 | 37 | | |
43 | 38 | | |
44 | 39 | | |
| |||
53 | 48 | | |
54 | 49 | | |
55 | 50 | | |
56 | | - | |
| 51 | + | |
57 | 52 | | |
58 | 53 | | |
59 | 54 | | |
60 | 55 | | |
61 | 56 | | |
62 | 57 | | |
63 | 58 | | |
64 | | - | |
| 59 | + | |
65 | 60 | | |
66 | 61 | | |
67 | 62 | | |
68 | 63 | | |
69 | | - | |
| 64 | + | |
70 | 65 | | |
71 | 66 | | |
72 | | - | |
| 67 | + | |
73 | 68 | | |
74 | 69 | | |
75 | 70 | | |
76 | 71 | | |
77 | | - | |
78 | | - | |
| 72 | + | |
| 73 | + | |
79 | 74 | | |
80 | 75 | | |
81 | 76 | | |
| |||
86 | 81 | | |
87 | 82 | | |
88 | 83 | | |
89 | | - | |
| 84 | + | |
90 | 85 | | |
91 | 86 | | |
92 | 87 | | |
93 | 88 | | |
94 | | - | |
| 89 | + | |
95 | 90 | | |
96 | 91 | | |
97 | | - | |
| 92 | + | |
98 | 93 | | |
99 | 94 | | |
100 | 95 | | |
101 | 96 | | |
102 | 97 | | |
103 | 98 | | |
104 | | - | |
| 99 | + | |
105 | 100 | | |
106 | 101 | | |
107 | 102 | | |
| |||
0 commit comments