Skip to content

Commit 1a381c2

Browse files
talissoncostaclaude
andcommitted
refactor(mv): share the control value weight label
The feature drawer rendered "Control Value" with a weight chip; segment overrides rendered the same idea as "Segment Control Value - 50%". Same concept, two treatments, and only one of them a chip. ControlValueLabel renders it once and both call sites pass it as the editor's label. It uses the canonical Chip rather than the legacy .chip class the feature drawer had inline: the legacy one carries a hand-written .dark block, and a new component should not add a 36th usage of what #6606 is trying to retire. The story uses it too rather than hand-rolling the markup. The accessible name still contains "Value", which is what the E2E role selectors match on. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
1 parent e466799 commit 1a381c2

4 files changed

Lines changed: 39 additions & 13 deletions

File tree

frontend/documentation/components/ValueEditor.stories.tsx

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import React, { useState } from 'react'
22
import type { Meta, StoryObj } from 'storybook'
33

44
import ValueEditor from 'components/ValueEditor'
5+
import ControlValueLabel from 'components/mv/ControlValueLabel'
56

67
const meta: Meta = {
78
parameters: { chromatic: { disableSnapshot: false } },
@@ -87,17 +88,14 @@ export const Disabled: Story = {
8788
// The multivariate control value carries a weight chip and a tooltip, so it is
8889
// the widest label this component gets. Label and format buttons share one flex
8990
// row, so they compress rather than overlap.
90-
const ControlValueLabel = (
91-
<span className='d-inline-flex align-items-center'>
92-
Control Value
93-
<span className='chip chip--xs ml-2'>100%</span>
94-
</span>
91+
const controlValueLabel = (
92+
<ControlValueLabel percentage={100}>Control Value</ControlValueLabel>
9593
)
9694

9795
export const BadgeLabel: Story = {
9896
render: () => (
9997
<Interactive
100-
label={ControlValueLabel}
98+
label={controlValueLabel}
10199
labelTooltip='The value served when no variation matches.'
102100
initialValue='DEFAULT_VALUE'
103101
/>
@@ -108,7 +106,7 @@ export const BadgeLabel: Story = {
108106
export const BadgeLabelNarrow: Story = {
109107
render: () => (
110108
<Interactive
111-
label={ControlValueLabel}
109+
label={controlValueLabel}
112110
labelTooltip='The value served when no variation matches.'
113111
initialValue='DEFAULT_VALUE'
114112
width={380}

frontend/web/components/SegmentOverrides.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { RestrictToVerticalAxis } from '@dnd-kit/abstract/modifiers'
99
import { arrayMove } from '@dnd-kit/helpers'
1010
import ProjectStore from 'common/stores/project-store'
1111
import ValueEditor from './ValueEditor'
12+
import ControlValueLabel from './mv/ControlValueLabel'
1213
import { VariationOptions } from './mv/VariationOptions'
1314
import FeatureListStore from 'common/stores/feature-list-store'
1415
import CreateSegmentModal from './modals/CreateSegment'
@@ -299,7 +300,11 @@ const SegmentOverrideInner = class Override extends React.Component {
299300
) : (
300301
<div className='flex-1 flex-column'>
301302
<ValueEditor
302-
label={`Segment Control Value - ${controlPercent}%`}
303+
label={
304+
<ControlValueLabel percentage={controlPercent}>
305+
Segment Control Value
306+
</ControlValueLabel>
307+
}
303308
value={v.value}
304309
disabled={readOnly}
305310
onChange={

frontend/web/components/modals/create-feature/tabs/FeatureValueTab.tsx

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import React, { FC, useEffect, useRef, useState } from 'react'
22
import FieldLabel from 'components/base/forms/FieldLabel'
33
import ValueEditor from 'components/ValueEditor'
4+
import ControlValueLabel from 'components/mv/ControlValueLabel'
45
import Constants from 'common/constants'
56
import { VariationOptions } from 'components/mv/VariationOptions'
67
import { AddVariationButton } from 'components/mv/AddVariationButton'
@@ -247,12 +248,9 @@ const FeatureValueTab: FC<FeatureValueTabProps> = ({
247248
)
248249
})
249250
const valueTitle = hasVariations ? (
250-
<span className='d-inline-flex align-items-center'>
251+
<ControlValueLabel percentage={controlPercentage}>
251252
Control Value
252-
<span className='chip chip--xs ml-2'>
253-
{Math.max(0, controlPercentage)}%
254-
</span>
255-
</span>
253+
</ControlValueLabel>
256254
) : (
257255
'Value'
258256
)
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import React, { FC, ReactNode } from 'react'
2+
3+
import Chip from 'components/base/Chip'
4+
5+
interface ControlValueLabelProps {
6+
children: ReactNode
7+
percentage: number
8+
}
9+
10+
// The control value's share of the variation split, shown beside its label.
11+
// The feature drawer and segment overrides both need it and had drifted apart:
12+
// a chip in one, a hyphenated string in the other.
13+
const ControlValueLabel: FC<ControlValueLabelProps> = ({
14+
children,
15+
percentage,
16+
}) => (
17+
<span className='d-inline-flex align-items-center gap-2'>
18+
{children}
19+
<Chip variant='accent' size='xs'>
20+
{Math.max(0, percentage)}%
21+
</Chip>
22+
</span>
23+
)
24+
25+
export default ControlValueLabel

0 commit comments

Comments
 (0)