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 { EXPERIMENT_NAME_PREFIX } from './constants';
export function toggleExperiment(experimentName) {
export function toggleExperiment( experimentName ) {
const storageItem = JSON.parse(
window.localStorage.getItem(EXPERIMENT_NAME_PREFIX + experimentName)
window.localStorage.getItem( EXPERIMENT_NAME_PREFIX + experimentName )
);
const newVariation =
@ -16,7 +16,7 @@ export function toggleExperiment(experimentName) {
window.localStorage.setItem(
EXPERIMENT_NAME_PREFIX + experimentName,
JSON.stringify(storageItem)
JSON.stringify( storageItem )
);
return {
@ -26,7 +26,7 @@ export function toggleExperiment(experimentName) {
};
}
export function setExperiments(experiments) {
export function setExperiments( experiments ) {
return {
type: TYPES.SET_EXPERIMENTS,
experiments,

View File

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

View File

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

View File

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

View File

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