Style fix

This commit is contained in:
Moon 2022-02-22 11:25:51 -08:00
parent cb8dbbe3c6
commit 452a5bef13
6 changed files with 36 additions and 36 deletions

View File

@ -4,9 +4,9 @@
import TYPES from './action-types'; import TYPES from './action-types';
import { EXPERIMENT_NAME_PREFIX } from './constants'; import { EXPERIMENT_NAME_PREFIX } from './constants';
export function toggleExperiment(experimentName) { export function toggleExperiment( experimentName ) {
const storageItem = JSON.parse( const storageItem = JSON.parse(
window.localStorage.getItem(EXPERIMENT_NAME_PREFIX + experimentName) window.localStorage.getItem( EXPERIMENT_NAME_PREFIX + experimentName )
); );
const newVariation = const newVariation =
@ -16,7 +16,7 @@ export function toggleExperiment(experimentName) {
window.localStorage.setItem( window.localStorage.setItem(
EXPERIMENT_NAME_PREFIX + experimentName, EXPERIMENT_NAME_PREFIX + experimentName,
JSON.stringify(storageItem) JSON.stringify( storageItem )
); );
return { return {
@ -26,7 +26,7 @@ export function toggleExperiment(experimentName) {
}; };
} }
export function setExperiments(experiments) { export function setExperiments( experiments ) {
return { return {
type: TYPES.SET_EXPERIMENTS, type: TYPES.SET_EXPERIMENTS,
experiments, experiments,

View File

@ -13,10 +13,10 @@ import * as selectors from './selectors';
import reducer from './reducer'; import reducer from './reducer';
import { STORE_KEY } from './constants'; import { STORE_KEY } from './constants';
export default registerStore(STORE_KEY, { export default registerStore( STORE_KEY, {
actions, actions,
selectors, selectors,
resolvers, resolvers,
controls, controls,
reducer, reducer,
}); } );

View File

@ -7,18 +7,18 @@ const DEFAULT_STATE = {
experiments: [], experiments: [],
}; };
const reducer = (state = DEFAULT_STATE, action) => { const reducer = ( state = DEFAULT_STATE, action ) => {
switch (action.type) { switch ( action.type ) {
case TYPES.TOGGLE_EXPERIMENT: case TYPES.TOGGLE_EXPERIMENT:
return { return {
...state, ...state,
experiments: state.experiments.map((experiment) => ({ experiments: state.experiments.map( ( experiment ) => ( {
...experiment, ...experiment,
variation: variation:
experiment.name === action.experimentName experiment.name === action.experimentName
? action.newVariation ? action.newVariation
: experiment.variation, : experiment.variation,
})), } ) ),
}; };
case TYPES.SET_EXPERIMENTS: case TYPES.SET_EXPERIMENTS:
return { return {

View File

@ -5,20 +5,20 @@ import { setExperiments } from './actions';
import { EXPERIMENT_NAME_PREFIX } from './constants'; import { EXPERIMENT_NAME_PREFIX } from './constants';
export function* getExperiments() { export function* getExperiments() {
const storageItems = Object.entries({ ...window.localStorage }).filter( const storageItems = Object.entries( { ...window.localStorage } ).filter(
(item) => { ( item ) => {
return item[0].indexOf(EXPERIMENT_NAME_PREFIX) === 0; return item[ 0 ].indexOf( EXPERIMENT_NAME_PREFIX ) === 0;
} }
); );
const experiments = storageItems.map((storageItem) => { const experiments = storageItems.map( ( storageItem ) => {
const [key, value] = storageItem; const [ key, value ] = storageItem;
const objectValue = JSON.parse(value); const objectValue = JSON.parse( value );
return { return {
name: key.replace(EXPERIMENT_NAME_PREFIX, ''), name: key.replace( EXPERIMENT_NAME_PREFIX, '' ),
variation: objectValue.variationName || 'control', variation: objectValue.variationName || 'control',
}; };
}); } );
yield setExperiments(experiments); yield setExperiments( experiments );
} }

View File

@ -1,3 +1,3 @@
export function getExperiments(state) { export function getExperiments( state ) {
return state.experiments; return state.experiments;
} }

View File

@ -11,7 +11,7 @@ import { Button } from '@wordpress/components';
import { STORE_KEY } from './data/constants'; import { STORE_KEY } from './data/constants';
import './data'; import './data';
function Experiments({ experiments, toggleExperiment }) { function Experiments( { experiments, toggleExperiment } ) {
return ( return (
<div id="wc-admin-test-helper-experiments"> <div id="wc-admin-test-helper-experiments">
<h2>Experiments</h2> <h2>Experiments</h2>
@ -24,16 +24,16 @@ function Experiments({ experiments, toggleExperiment }) {
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
{experiments.map(({ name, variation }, index) => { { experiments.map( ( { name, variation }, index ) => {
return ( return (
<tr key={index}> <tr key={ index }>
<td className="experiment-name">{name}</td> <td className="experiment-name">{ name }</td>
<td align="center">{variation}</td> <td align="center">{ variation }</td>
<td align="center"> <td align="center">
<Button <Button
onClick={() => { onClick={ () => {
toggleExperiment(name); toggleExperiment( name );
}} } }
isPrimary isPrimary
> >
Toggle Toggle
@ -41,7 +41,7 @@ function Experiments({ experiments, toggleExperiment }) {
</td> </td>
</tr> </tr>
); );
})} } ) }
</tbody> </tbody>
</table> </table>
</div> </div>
@ -49,17 +49,17 @@ function Experiments({ experiments, toggleExperiment }) {
} }
export default compose( export default compose(
withSelect((select) => { withSelect( ( select ) => {
const { getExperiments } = select(STORE_KEY); const { getExperiments } = select( STORE_KEY );
return { return {
experiments: getExperiments(), experiments: getExperiments(),
}; };
}), } ),
withDispatch((dispatch) => { withDispatch( ( dispatch ) => {
const { toggleExperiment } = dispatch(STORE_KEY); const { toggleExperiment } = dispatch( STORE_KEY );
return { return {
toggleExperiment, toggleExperiment,
}; };
}) } )
)(Experiments); )( Experiments );