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

View File

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

View File

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

View File

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

View File

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