diff --git a/src/experiments/data/action-types.js b/src/experiments/data/action-types.js index b056a6db667..3402b35dc10 100644 --- a/src/experiments/data/action-types.js +++ b/src/experiments/data/action-types.js @@ -2,6 +2,7 @@ const TYPES = { TOGGLE_EXPERIMENT: 'TOGGLE_EXPERIMENT', SET_EXPERIMENTS: 'SET_EXPERIMENTS', ADD_EXPERIMENT: 'ADD_EXPERIMENT', + DELETE_EXPERIMENT: 'DELETE_EXPERIMENT', }; export default TYPES; diff --git a/src/experiments/data/actions.js b/src/experiments/data/actions.js index c17d4077078..8ac78e3d40a 100644 --- a/src/experiments/data/actions.js +++ b/src/experiments/data/actions.js @@ -84,3 +84,22 @@ export function* addExperiment( experimentName, variation ) { variation, }; } + +export function* deleteExperiment( experimentName ) { + window.localStorage.removeItem( EXPERIMENT_NAME_PREFIX + experimentName ); + + const optionNames = [ + TRANSIENT_NAME_PREFIX + experimentName, + TRANSIENT_TIMEOUT_NAME_PREFIX + experimentName, + ]; + + yield apiFetch( { + method: 'DELETE', + path: '/wc-admin-test-helper/options/' + optionNames.join( ',' ), + } ); + + return { + type: TYPES.DELETE_EXPERIMENT, + experimentName, + }; +} diff --git a/src/experiments/data/reducer.js b/src/experiments/data/reducer.js index e33b4f7b293..3f34bd0a8ef 100644 --- a/src/experiments/data/reducer.js +++ b/src/experiments/data/reducer.js @@ -9,6 +9,13 @@ const DEFAULT_STATE = { const reducer = ( state = DEFAULT_STATE, action ) => { switch ( action.type ) { + case TYPES.DELETE_EXPERIMENT: + return { + ...state, + experiments: state.experiments.filter( ( experiment ) => { + return experiment.name !== action.experimentName; + } ), + }; case TYPES.ADD_EXPERIMENT: const existingExperimentIndex = state.experiments.findIndex( ( element ) => { diff --git a/src/experiments/index.js b/src/experiments/index.js index 83ddb45ff30..10c364173f0 100644 --- a/src/experiments/index.js +++ b/src/experiments/index.js @@ -15,6 +15,7 @@ import NewExperimentForm from './NewExperimentForm'; function Experiments( { experiments, toggleExperiment, + deleteExperiment, isTrackingEnabled, isResolving, } ) { @@ -51,7 +52,7 @@ function Experiments( {