Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(flags): Ensure activity log reflects removing variants #29379

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -528,5 +528,177 @@ describe('the activity log logic', () => {
'peter changed the filter conditions to apply to 76% of Initial Browser = Chrome , and 99% of Initial Browser Version = 100 on with two changes'
)
})

it('can handle changing variants from a multivariate flag', async () => {
const logic = await featureFlagsTestSetup('test flag', 'updated', [
{
type: ActivityScope.FEATURE_FLAG,
action: 'changed',
field: 'filters',
before: {
groups: [
{
properties: [],
rollout_percentage: 75,
},
],
multivariate: {
variants: [
{ key: 'control', rollout_percentage: 50 },
{ key: 'test-1', rollout_percentage: 50 },
],
},
},
after: {
groups: [
{
properties: [],
rollout_percentage: 75,
},
],
multivariate: {
variants: [
{ key: 'control', rollout_percentage: 60 },
{ key: 'test-1', rollout_percentage: 40 },
],
},
},
},
])

const actual = logic.values.humanizedActivity
expect(render(<>{actual[0].description}</>).container).toHaveTextContent(
'peter changed the rollout percentage for the variants to control: 60%, and test-1: 40% on test flag'
)
})

it('can handle removing variant from a multivariate flag', async () => {
const logic = await featureFlagsTestSetup('test flag', 'updated', [
{
type: ActivityScope.FEATURE_FLAG,
action: 'changed',
field: 'filters',
before: {
groups: [
{
properties: [],
rollout_percentage: 75,
},
],
multivariate: {
variants: [
{ key: 'control', rollout_percentage: 33 },
{ key: 'test-1', rollout_percentage: 33 },
{ key: 'test-2', rollout_percentage: 34 },
],
},
},
after: {
groups: [
{
properties: [],
rollout_percentage: 75,
},
],
multivariate: {
variants: [
{ key: 'control', rollout_percentage: 50 },
{ key: 'test-1', rollout_percentage: 50 },
],
},
},
},
])

const actual = logic.values.humanizedActivity
expect(render(<>{actual[0].description}</>).container).toHaveTextContent(
'peter changed the rollout percentage for the variants to control: 50%, and test-1: 50%, and removed variant(s) test-2 on test flag'
)
})

it('can handle removing more than one variant from a multivariate flag', async () => {
const logic = await featureFlagsTestSetup('test flag', 'updated', [
{
type: ActivityScope.FEATURE_FLAG,
action: 'changed',
field: 'filters',
before: {
groups: [
{
properties: [],
rollout_percentage: 75,
},
],
multivariate: {
variants: [
{ key: 'control', rollout_percentage: 33 },
{ key: 'test-1', rollout_percentage: 33 },
{ key: 'test-2', rollout_percentage: 34 },
{ key: 'test-3', rollout_percentage: 34 },
],
},
},
after: {
groups: [
{
properties: [],
rollout_percentage: 75,
},
],
multivariate: {
variants: [
{ key: 'control', rollout_percentage: 50 },
{ key: 'test-1', rollout_percentage: 50 },
],
},
},
},
])

const actual = logic.values.humanizedActivity
expect(render(<>{actual[0].description}</>).container).toHaveTextContent(
'peter changed the rollout percentage for the variants to control: 50%, and test-1: 50%, and removed variant(s) test-2, and test-3 on test flag'
)
})

it('can handle removing all variants from a multivariate flag', async () => {
const logic = await featureFlagsTestSetup('test flag', 'updated', [
{
type: ActivityScope.FEATURE_FLAG,
action: 'changed',
field: 'filters',
before: {
groups: [
{
properties: [],
rollout_percentage: 75,
},
],
multivariate: {
variants: [
{ key: 'control', rollout_percentage: 33 },
{ key: 'test-1', rollout_percentage: 33 },
{ key: 'test-2', rollout_percentage: 34 },
{ key: 'test-3', rollout_percentage: 34 },
],
},
},
after: {
groups: [
{
properties: [],
rollout_percentage: 75,
},
],
multivariate: null,
},
},
])

const actual = logic.values.humanizedActivity
expect(render(<>{actual[0].description}</>).container).toHaveTextContent(
'peter removed all variants on test flag'
)
})
})
})
29 changes: 28 additions & 1 deletion frontend/src/scenes/feature-flags/activityDescriptions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,14 @@ const featureFlagActionsMapping: Record<
}
}

if (isMultivariateFlag) {
if (filtersBefore?.multivariate?.variants?.length && filtersAfter.multivariate === null) {
changes.push(
<SentenceList
key="remove-variants-list"
listParts={[<span key="remove-variants">removed all variants</span>]}
/>
)
} else if (isMultivariateFlag) {
filtersAfter.payloads &&
Object.keys(filtersAfter.payloads).forEach((key: string) => {
const changedPayload = filtersAfter.payloads?.[key]?.toString() || null
Expand All @@ -162,6 +169,12 @@ const featureFlagActionsMapping: Record<
)
})

// Identify removed variants
const beforeVariants = new Set((filtersBefore?.multivariate?.variants || []).map((v) => v.key))
const afterVariants = new Set((filtersAfter?.multivariate?.variants || []).map((v) => v.key))
const removedVariants = [...beforeVariants].filter((key) => !afterVariants.has(key))

// First add the rollout percentage changes
changes.push(
<SentenceList
listParts={(filtersAfter.multivariate?.variants || []).map((v) => (
Expand All @@ -172,6 +185,20 @@ const featureFlagActionsMapping: Record<
prefix="changed the rollout percentage for the variants to"
/>
)

// Then add removed variants if any
if (removedVariants.length > 0) {
changes.push(
<SentenceList
listParts={removedVariants.map((key) => (
<span key={key} className="highlighted-activity">
<strong>{key}</strong>
</span>
))}
prefix="removed variant(s)"
/>
)
}
}

if (changes.length > 0) {
Expand Down