Fix formatting

This commit is contained in:
Lourens Schep 2022-03-18 16:33:36 -03:00
parent 66073a6b8f
commit 4347d0bef6
5 changed files with 44 additions and 42 deletions

View File

@ -12,44 +12,44 @@ import { API_NAMESPACE, STORE_KEY } from './constants';
export function* resetModifiedFeatures() { export function* resetModifiedFeatures() {
try { try {
const response = yield apiFetch({ const response = yield apiFetch( {
path: `${API_NAMESPACE}/features/reset`, path: `${ API_NAMESPACE }/features/reset`,
method: 'POST', method: 'POST',
}); } );
yield setModifiedFeatures([]); yield setModifiedFeatures( [] );
yield setFeatures(response); yield setFeatures( response );
} catch (error) { } catch ( error ) {
throw new Error(); throw new Error();
} }
} }
export function* toggleFeature(featureName) { export function* toggleFeature( featureName ) {
try { try {
const response = yield apiFetch({ const response = yield apiFetch( {
method: 'POST', method: 'POST',
path: API_NAMESPACE + '/features/' + featureName + '/toggle', path: API_NAMESPACE + '/features/' + featureName + '/toggle',
headers: { 'content-type': 'application/json' }, headers: { 'content-type': 'application/json' },
}); } );
yield setFeatures(response); yield setFeatures( response );
yield controls.dispatch( yield controls.dispatch(
STORE_KEY, STORE_KEY,
'invalidateResolutionForStoreSelector', 'invalidateResolutionForStoreSelector',
'getModifiedFeatures' 'getModifiedFeatures'
); );
} catch (error) { } catch ( error ) {
throw new Error(); throw new Error();
} }
} }
export function setFeatures(features) { export function setFeatures( features ) {
return { return {
type: TYPES.SET_FEATURES, type: TYPES.SET_FEATURES,
features, features,
}; };
} }
export function setModifiedFeatures(modifiedFeatures) { export function setModifiedFeatures( modifiedFeatures ) {
return { return {
type: TYPES.SET_MODIFIED_FEATURES, type: TYPES.SET_MODIFIED_FEATURES,
modifiedFeatures, modifiedFeatures,

View File

@ -8,8 +8,8 @@ const DEFAULT_STATE = {
modifiedFeatures: [], modifiedFeatures: [],
}; };
const reducer = (state = DEFAULT_STATE, action) => { const reducer = ( state = DEFAULT_STATE, action ) => {
switch (action.type) { switch ( action.type ) {
case TYPES.SET_MODIFIED_FEATURES: case TYPES.SET_MODIFIED_FEATURES:
return { return {
...state, ...state,

View File

@ -11,28 +11,28 @@ import { API_NAMESPACE, OPTION_NAME_PREFIX } from './constants';
export function* getModifiedFeatures() { export function* getModifiedFeatures() {
try { try {
const response = yield apiFetch({ const response = yield apiFetch( {
path: `wc-admin/options?options=` + OPTION_NAME_PREFIX, path: `wc-admin/options?options=` + OPTION_NAME_PREFIX,
}); } );
yield setModifiedFeatures( yield setModifiedFeatures(
response && response[OPTION_NAME_PREFIX] response && response[ OPTION_NAME_PREFIX ]
? Object.keys(response[OPTION_NAME_PREFIX]) ? Object.keys( response[ OPTION_NAME_PREFIX ] )
: [] : []
); );
} catch (error) { } catch ( error ) {
throw new Error(); throw new Error();
} }
} }
export function* getFeatures() { export function* getFeatures() {
try { try {
const response = yield apiFetch({ const response = yield apiFetch( {
path: `${API_NAMESPACE}/features`, path: `${ API_NAMESPACE }/features`,
}); } );
yield setFeatures(response); yield setFeatures( response );
} catch (error) { } catch ( error ) {
throw new Error(); throw new Error();
} }
} }

View File

@ -1,7 +1,7 @@
export function getFeatures(state) { export function getFeatures( state ) {
return state.features; return state.features;
} }
export function getModifiedFeatures(state) { export function getModifiedFeatures( state ) {
return state.modifiedFeatures; return state.modifiedFeatures;
} }

View File

@ -11,25 +11,25 @@ import { STORE_KEY } from './data/constants';
import './data'; import './data';
function Features() { function Features() {
const { features = {}, modifiedFeatures = [] } = useSelect((select) => { const { features = {}, modifiedFeatures = [] } = useSelect( ( select ) => {
const { getFeatures, getModifiedFeatures } = select(STORE_KEY); const { getFeatures, getModifiedFeatures } = select( STORE_KEY );
return { return {
features: getFeatures(), features: getFeatures(),
modifiedFeatures: getModifiedFeatures(), modifiedFeatures: getModifiedFeatures(),
}; };
}); } );
const { toggleFeature, resetModifiedFeatures } = useDispatch(STORE_KEY); const { toggleFeature, resetModifiedFeatures } = useDispatch( STORE_KEY );
return ( return (
<div id="wc-admin-test-helper-features"> <div id="wc-admin-test-helper-features">
<h2> <h2>
Features Features
<Button <Button
disabled={modifiedFeatures.length === 0} disabled={ modifiedFeatures.length === 0 }
onClick={() => resetModifiedFeatures()} onClick={ () => resetModifiedFeatures() }
isSecondary isSecondary
style={{ marginLeft: '24px' }} style={ { marginLeft: '24px' } }
> >
Reset to defaults Reset to defaults
</Button> </Button>
@ -43,16 +43,18 @@ function Features() {
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
{Object.keys(features).map((feature_name) => { { Object.keys( features ).map( ( feature_name ) => {
return ( return (
<tr key={feature_name}> <tr key={ feature_name }>
<td className="feature-name">{feature_name}</td> <td className="feature-name">
<td>{features[feature_name].toString()}</td> { feature_name }
</td>
<td>{ features[ feature_name ].toString() }</td>
<td> <td>
<Button <Button
onClick={() => { onClick={ () => {
toggleFeature(feature_name); toggleFeature( feature_name );
}} } }
isPrimary isPrimary
> >
Toggle Toggle
@ -60,7 +62,7 @@ function Features() {
</td> </td>
</tr> </tr>
); );
})} } ) }
</tbody> </tbody>
</table> </table>
</div> </div>