Skip to content
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
54 changes: 17 additions & 37 deletions frontend/web/components/feature-summary/FeatureRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import React, { FC, useCallback, useEffect, useMemo } from 'react'
import ConfirmToggleFeature from 'components/modals/ConfirmToggleFeature'
import ConfirmRemoveFeature from 'components/modals/ConfirmRemoveFeature'
import CreateFlagModal from 'components/modals/create-feature'
import CreateExperimentModal from 'components/modals/create-experiment'

@talissoncosta talissoncosta Jun 30, 2026

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.

Are we still gonna keep CreateExperimentModal ?
Just checking to prevent dead code.

import ProjectStore from 'common/stores/project-store'
import Constants from 'common/constants'
import { useProtectedTags } from 'common/utils/useProtectedTags'
Expand Down Expand Up @@ -57,7 +56,6 @@ interface FeatureRowProps {
releasePipelines?: ReleasePipeline[]
onCloseEditModal?: () => void
isCompact?: boolean
experimentMode?: boolean
}

const width = [220, 50, 55, 70, 450]
Expand All @@ -69,7 +67,6 @@ const FeatureRow: FC<FeatureRowProps> = (props) => {
disableControls,
environmentFlags,
environmentId,
experimentMode = false,
fadeEnabled,
fadeValue,
hideAudit = false,
Expand Down Expand Up @@ -114,9 +111,9 @@ const FeatureRow: FC<FeatureRowProps> = (props) => {
const { feature } = Utils.fromParam()
const { id } = projectFlag

const isModalOpen =
!!document?.getElementsByClassName('create-feature-modal')?.length ||
!!document?.getElementsByClassName('create-experiment-modal')?.length
const isModalOpen = !!document?.getElementsByClassName(
'create-feature-modal',
)?.length
if (`${id}` === feature && !isModalOpen) {
editFeature()
}
Expand Down Expand Up @@ -202,35 +199,18 @@ const FeatureRow: FC<FeatureRowProps> = (props) => {
search: `?feature=${projectFlag.id}&tab=${tabValue}`,
})

const ModalComponent = experimentMode
? CreateExperimentModal
: CreateFlagModal
const modalCssClass = experimentMode
? 'side-modal create-feature-modal create-experiment-modal'
: 'side-modal create-feature-modal'

const modalProps = experimentMode
? {
environmentFlag,
environmentId,
history,
noPermissions: !permission,
projectFlag,
projectId,
tab,
}
: {
environmentFlag,
environmentId,
hasUnhealthyEvents:
isFeatureHealthEnabled && !!featureUnhealthyEvents?.length,
hideTagsByType: ['UNHEALTHY'],
history,
noPermissions: !permission,
projectFlag,
projectId,
tab,
}
const modalProps = {
environmentFlag,
environmentId,
hasUnhealthyEvents:
isFeatureHealthEnabled && !!featureUnhealthyEvents?.length,
hideTagsByType: ['UNHEALTHY'],
history,
noPermissions: !permission,
projectFlag,
projectId,
tab,
}

const ownerChips = enforceFeatureOwners
? [
Expand Down Expand Up @@ -273,8 +253,8 @@ const FeatureRow: FC<FeatureRowProps> = (props) => {
</div>
)}
</Row>,
<ModalComponent {...modalProps} />,
modalCssClass,
<CreateFlagModal {...modalProps} />,
'side-modal create-feature-modal',
() => {
if (onCloseEditModal) {
return onCloseEditModal()
Expand Down
3 changes: 0 additions & 3 deletions frontend/web/components/modals/create-feature/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ type CreateFeatureModalProps = {
noPermissions?: boolean
disableCreate?: boolean
highlightSegmentId?: number
defaultExperiment?: boolean
history?: History
multivariate_options?: MultivariateFeatureStateValue[]
} & Partial<InjectedSegmentOverrideProps>
Expand Down Expand Up @@ -95,7 +94,6 @@ const mergeEnvironmentWeights = (options: any[], variations: any[]): any[] =>
const CreateFeatureModal: FC<CreateFeatureModalProps> = (props) => {
const {
changeRequest: existingChangeRequest,
defaultExperiment,
disableCreate,
environmentId,
environmentVariations,
Expand Down Expand Up @@ -862,7 +860,6 @@ const CreateFeatureModal: FC<CreateFeatureModalProps> = (props) => {
featureState={props.environmentFlag || environmentFlag}
projectFlag={projectFlag}
identity={identity}
defaultExperiment={defaultExperiment}
overrideFeatureState={
props.identityFlag ? environmentFlag : null
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
import React, { FC, useCallback, useEffect, useState } from 'react'
import React, { FC } from 'react'
import { FeatureState, ProjectFlag } from 'common/types/responses'
import FeatureValueTab from './FeatureValueTab'
import FeatureSettingsTab from './FeatureSettingsTab'
import ErrorMessage from 'components/ErrorMessage'
import WarningMessage from 'components/WarningMessage'
import { useHasPermission } from 'common/providers/Permission'
import { ProjectPermission } from 'common/types/permissions.types'
import Switch from 'components/Switch'
import Tooltip from 'components/Tooltip'
import Icon from 'components/icons/Icon'
import InfoMessage from 'components/InfoMessage'
import { useGetProjectQuery } from 'common/services/useProject'
import { useCreateTagMutation, useGetTagsQuery } from 'common/services/useTag'

type CreateFeatureTabProps = {
projectId: number
Expand All @@ -20,7 +16,6 @@ type CreateFeatureTabProps = {
overrideFeatureState?: FeatureState
projectFlag: ProjectFlag | null
identity?: string
defaultExperiment?: boolean
ownerIds?: number[]
groupOwnerIds?: number[]
onOwnerIdsChange?: (ids: number[]) => void
Expand All @@ -34,7 +29,6 @@ type CreateFeatureTabProps = {
}

const CreateFeatureTab: FC<CreateFeatureTabProps> = ({
defaultExperiment,
error,
featureError,
featureState,
Expand Down Expand Up @@ -69,76 +63,6 @@ const CreateFeatureTab: FC<CreateFeatureTabProps> = ({

const noPermissions = !createFeature && !projectAdmin

const showExperimentToggle =
Utils.getFlagsmithHasFeature('experimental_flags') && !identity

const { data: tags } = useGetTagsQuery(
{ projectId },
{ skip: !showExperimentToggle },
)
const [createTag] = useCreateTagMutation()

const [isExperimentFlag, setIsExperimentFlag] = useState(!!defaultExperiment)

const hasVariants = (projectFlag?.multivariate_options?.length ?? 0) > 0

// Auto-untoggle if all variants are removed
useEffect(() => {
if (!hasVariants && isExperimentFlag) {
setIsExperimentFlag(false)
if (projectFlag && tags) {
const experimentTag = tags.find(
(t) => t.label.toLowerCase() === 'experiment',
)
if (experimentTag) {
onProjectFlagChange({
...projectFlag,
tags: projectFlag.tags.filter((id) => id !== experimentTag.id),
})
}
}
}
}, [hasVariants]) // eslint-disable-line react-hooks/exhaustive-deps

const handleExperimentToggle = useCallback(
async (checked: boolean) => {
if (!projectFlag || !tags) return

setIsExperimentFlag(checked)

let experimentTag = tags.find(
(t) => t.label.toLowerCase() === 'experiment',
)

if (checked) {
if (!experimentTag) {
experimentTag = await createTag({
projectId,
tag: {
color: '#6A52CF',
description: 'Experiment flag',
label: 'experiment',
},
}).unwrap()
}
if (experimentTag && !projectFlag.tags.includes(experimentTag.id)) {
onProjectFlagChange({
...projectFlag,
tags: [...projectFlag.tags, experimentTag.id],
})
}
} else {
if (experimentTag) {
onProjectFlagChange({
...projectFlag,
tags: projectFlag.tags.filter((id) => id !== experimentTag?.id),
})
}
}
},
[projectFlag, tags, createTag, projectId, onProjectFlagChange],
)

return (
<>
<ErrorMessage error={featureError} />
Expand All @@ -163,30 +87,6 @@ const CreateFeatureTab: FC<CreateFeatureTabProps> = ({
onProjectFlagChange={onProjectFlagChange}
onRemoveMultivariateOption={onRemoveMultivariateOption}
/>
{showExperimentToggle && (
<FormGroup className='my-4'>
<Tooltip
title={
<div className='flex-row'>
<Switch
checked={isExperimentFlag}
onChange={handleExperimentToggle}
disabled={!hasVariants}
className='ml-0'
/>
<div className='label-switch ml-3 mr-1'>
Experiment flag
</div>
<Icon name='info-outlined' />
</div>
}
>
{!hasVariants
? 'Add at least one variant to start an experiment'
: 'Tag this feature as an experiment'}
</Tooltip>
</FormGroup>
)}
<FeatureSettingsTab
identity={identity}
projectId={projectId}
Expand Down
10 changes: 1 addition & 9 deletions frontend/web/components/pages/features/FeaturesPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,9 @@ function isSkeletonItem(
type FeaturesPageProps = {
pageTitle?: string
forcedTagIds?: number[]
defaultExperiment?: boolean
}

const FeaturesPage: FC<FeaturesPageProps> = ({
defaultExperiment,
forcedTagIds,
pageTitle,
}) => {
const FeaturesPage: FC<FeaturesPageProps> = ({ forcedTagIds, pageTitle }) => {
const history = useHistory()
const routeContext = useRouteContext()
const projectId = routeContext.projectId!
Expand Down Expand Up @@ -207,7 +202,6 @@ const FeaturesPage: FC<FeaturesPageProps> = ({
environmentId={environmentId}
history={history}
projectId={projectId}
defaultExperiment={defaultExperiment}
/>,
'side-modal create-feature-modal',
)
Expand Down Expand Up @@ -287,7 +281,6 @@ const FeaturesPage: FC<FeaturesPageProps> = ({
removeFlag={removeFlag}
projectFlag={projectFlag}
isCompact={isCompact}
experimentMode={defaultExperiment}
/>
)}
</Permission>
Expand All @@ -300,7 +293,6 @@ const FeaturesPage: FC<FeaturesPageProps> = ({
toggleFlag,
removeFlag,
isCompact,
defaultExperiment,
],
)

Expand Down
Loading