Repository navigation
feat(experimentation): choose the rollout when completing an experiment #9021
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
base: feat/experiment-complete-rollout-decision
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -11,14 +11,16 @@ type SelectableCardProps = { | |||||
| selected?: boolean | ||||||
| onClick: () => void | ||||||
| icon?: ReactNode | ||||||
| title: string | ||||||
| description: string | ||||||
| title: ReactNode | ||||||
| description: ReactNode | ||||||
| badge?: { label: string; variant: BadgeVariant } | ||||||
| tags?: string[] | ||||||
| disabled?: boolean | ||||||
| className?: string | ||||||
| // Extra content below the description (e.g. an illustrative preview). | ||||||
| children?: ReactNode | ||||||
| // Content inside the card but outside its button (e.g. a form control). | ||||||
| footer?: ReactNode | ||||||
| } | ||||||
|
|
||||||
| const SelectableCard: FC<SelectableCardProps> = ({ | ||||||
|
|
@@ -27,14 +29,15 @@ const SelectableCard: FC<SelectableCardProps> = ({ | |||||
| className, | ||||||
| description, | ||||||
| disabled, | ||||||
| footer, | ||||||
| icon, | ||||||
| onClick, | ||||||
| selected, | ||||||
| tags, | ||||||
| title, | ||||||
| }) => { | ||||||
| return ( | ||||||
| <BareButton | ||||||
| <div | ||||||
| className={cn( | ||||||
| 'selectable-card', | ||||||
| { | ||||||
|
|
@@ -43,34 +46,39 @@ const SelectableCard: FC<SelectableCardProps> = ({ | |||||
| }, | ||||||
| className, | ||||||
| )} | ||||||
| onClick={onClick} | ||||||
| disabled={disabled} | ||||||
| > | ||||||
| <div className='selectable-card__content'> | ||||||
| {icon && <div className='selectable-card__icon'>{icon}</div>} | ||||||
| <span className='selectable-card__title'>{title}</span> | ||||||
| <span className='selectable-card__description'>{description}</span> | ||||||
| {!!tags?.length && ( | ||||||
| <div className='selectable-card__tags'> | ||||||
| {tags.map((tag) => ( | ||||||
| <span key={tag} className='selectable-card__tag'> | ||||||
| {tag} | ||||||
| </span> | ||||||
| ))} | ||||||
| <BareButton | ||||||
| className='selectable-card__body' | ||||||
| onClick={onClick} | ||||||
| disabled={disabled} | ||||||
| > | ||||||
| <div className='selectable-card__content'> | ||||||
| {icon && <div className='selectable-card__icon'>{icon}</div>} | ||||||
| <span className='selectable-card__title'>{title}</span> | ||||||
| <span className='selectable-card__description'>{description}</span> | ||||||
| {!!tags?.length && ( | ||||||
| <div className='selectable-card__tags'> | ||||||
| {tags.map((tag) => ( | ||||||
| <span key={tag} className='selectable-card__tag'> | ||||||
| {tag} | ||||||
| </span> | ||||||
| ))} | ||||||
| </div> | ||||||
| )} | ||||||
| {children} | ||||||
| </div> | ||||||
| {badge && ( | ||||||
| <div className='selectable-card__aside'> | ||||||
| <span | ||||||
| className={`selectable-card__badge selectable-card__badge--${badge.variant}`} | ||||||
| > | ||||||
| {badge.label} | ||||||
| </span> | ||||||
| </div> | ||||||
| )} | ||||||
| {children} | ||||||
| </div> | ||||||
| {badge && ( | ||||||
| <div className='selectable-card__aside'> | ||||||
| <span | ||||||
| className={`selectable-card__badge selectable-card__badge--${badge.variant}`} | ||||||
| > | ||||||
| {badge.label} | ||||||
| </span> | ||||||
| </div> | ||||||
| )} | ||||||
| </BareButton> | ||||||
| </BareButton> | ||||||
| {footer && <div className='px-3 pb-3'>{footer}</div>} | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P3: The footer slot drops numeric zero because Prompt for AI agents
Suggested change
|
||||||
| </div> | ||||||
| ) | ||||||
| } | ||||||
|
|
||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,144 @@ | ||
| import { FC, useMemo, useState } from 'react' | ||
| import { | ||
| useCompleteExperimentMutation, | ||
| useGetExperimentBayesianResultsQuery, | ||
| useGetExperimentQuery, | ||
| } from 'common/services/useExperiment' | ||
| import { useGetEnvironmentQuery } from 'common/services/useEnvironment' | ||
| import Banner from 'components/base/Banner' | ||
| import Button from 'components/base/forms/Button' | ||
| import ErrorMessage from 'components/ErrorMessage' | ||
| import ModalHR from 'components/modals/ModalHR' | ||
| import { getVariantIdentities } from 'components/experiments/results/derive' | ||
| import RolloutDecisionPicker from './RolloutDecisionPicker' | ||
| import { | ||
| RolloutSelection, | ||
| buildCompleteExperimentBody, | ||
| getControlSelectedMessage, | ||
| getDefaultSelection, | ||
| getServedVariant, | ||
| getVariantChoices, | ||
| } from './utils' | ||
|
|
||
| type CompleteExperimentModalProps = { | ||
| environmentId: string | ||
| experimentId: number | ||
| } | ||
|
|
||
| const CompleteExperimentModal: FC<CompleteExperimentModalProps> = ({ | ||
| environmentId, | ||
| experimentId, | ||
| }) => { | ||
| const params = { environmentId, experimentId } | ||
| const { data: experiment, isError } = useGetExperimentQuery(params) | ||
| const { data: bayesianResults, isLoading: isLoadingResults } = | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P1: A failed Bayesian-results request is treated as a successful no-results response, so the modal can silently roll out control during an irreversible completion. Handle the results error separately and block completion with an error state. Prompt for AI agents |
||
| useGetExperimentBayesianResultsQuery(params) | ||
| const { data: environment } = useGetEnvironmentQuery({ id: environmentId }) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P2: A failed environment request leaves this modal showing a loader forever with no error or retry path. Destructure the query error state and render an error state when the environment cannot load. Prompt for AI agents |
||
| const [completeExperiment, { isLoading: isCompleting }] = | ||
| useCompleteExperimentMutation() | ||
| const [selection, setSelection] = useState<RolloutSelection>() | ||
|
|
||
| const results = bayesianResults?.payload ?? undefined | ||
| const choices = useMemo( | ||
| () => (experiment ? getVariantChoices(experiment, results) : []), | ||
| [experiment, results], | ||
| ) | ||
|
|
||
| if (isError) { | ||
| return ( | ||
| <div className='modal-body'> | ||
| <ErrorMessage | ||
| errorMessageClass='mb-0' | ||
| error="We couldn't load this experiment." | ||
| /> | ||
| </div> | ||
| ) | ||
| } | ||
|
|
||
| if (!experiment || !environment || isLoadingResults) { | ||
| return ( | ||
| <div className='modal-body text-center'> | ||
| <Loader /> | ||
| </div> | ||
| ) | ||
| } | ||
|
|
||
| const defaultSelection = getDefaultSelection(experiment, choices, results) | ||
| const activeSelection = selection ?? defaultSelection | ||
| const control = getVariantIdentities(experiment.feature)[0] | ||
| const servedVariant = getServedVariant(activeSelection, control, choices) | ||
| const hasAudience = !!experiment.experiment_rollout?.audience?.segments.length | ||
|
|
||
| const handleComplete = async () => { | ||
| try { | ||
| await completeExperiment({ | ||
| ...params, | ||
| body: buildCompleteExperimentBody(activeSelection), | ||
| }).unwrap() | ||
| toast('Experiment completed') | ||
| closeModal() | ||
| } catch { | ||
| toast('Failed to complete experiment', 'danger') | ||
| } | ||
| } | ||
|
|
||
| return ( | ||
| <> | ||
| <div className='modal-body d-flex flex-column gap-3 mx-0'> | ||
| <p className='mb-0'> | ||
| Choose what <b>{experiment.feature.name}</b> serves in{' '} | ||
| <b>{environment.name}</b> after <b>{experiment.name}</b> ends. Results | ||
| stay available; this can't be undone. | ||
| </p> | ||
| {defaultSelection.decision === 'control' && | ||
| activeSelection.decision === 'control' && ( | ||
| <Banner>{getControlSelectedMessage(experiment, results)}</Banner> | ||
| )} | ||
| <RolloutDecisionPicker | ||
| choices={choices} | ||
| control={control} | ||
| environmentName={environment.name} | ||
| featureName={experiment.feature.name} | ||
| selection={activeSelection} | ||
| onChange={setSelection} | ||
| /> | ||
| <div className='bg-surface-muted rounded-md p-3'> | ||
| The experiment's rollout override is removed and{' '} | ||
| {servedVariant ? ( | ||
| <> | ||
| <b>100% of users</b> get <b>{servedVariant.name}</b>. | ||
| </> | ||
| ) : ( | ||
| <> | ||
| <b>{experiment.feature.name}</b> is turned off for everyone. | ||
| </> | ||
| )} | ||
| {hasAudience && ( | ||
| <> | ||
| {' '} | ||
| This applies to everyone in <b>{environment.name}</b>, not only | ||
| the experiment's audience. | ||
| </> | ||
| )} | ||
| </div> | ||
| </div> | ||
| <ModalHR /> | ||
| <div className='modal-footer'> | ||
| <Button className='mr-2' onClick={closeModal} theme='secondary'> | ||
| Cancel | ||
| </Button> | ||
| <Button | ||
| disabled={ | ||
| isCompleting || | ||
| (!servedVariant && activeSelection.decision !== 'disable') | ||
| } | ||
| onClick={handleComplete} | ||
| > | ||
| Complete experiment | ||
| </Button> | ||
| </div> | ||
| </> | ||
| ) | ||
| } | ||
|
|
||
| export default CompleteExperimentModal | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P2: A disabled card can still expose an interactive footer control to keyboard users because
disabledonly reaches the body button andpointer-events: nonedoes not prevent sequential focus. Mark the footer inert whendisabledis true.Prompt for AI agents