Update reset to default functionality
This commit is contained in:
parent
46cba23313
commit
66073a6b8f
|
@ -2,12 +2,13 @@
|
|||
* External dependencies
|
||||
*/
|
||||
import { apiFetch } from '@wordpress/data-controls';
|
||||
import { controls } from '@wordpress/data';
|
||||
|
||||
/**
|
||||
* Internal dependencies
|
||||
*/
|
||||
import TYPES from './action-types';
|
||||
import { API_NAMESPACE } from './constants';
|
||||
import { API_NAMESPACE, STORE_KEY } from './constants';
|
||||
|
||||
export function* resetModifiedFeatures() {
|
||||
try {
|
||||
|
@ -30,7 +31,12 @@ export function* toggleFeature(featureName) {
|
|||
path: API_NAMESPACE + '/features/' + featureName + '/toggle',
|
||||
headers: { 'content-type': 'application/json' },
|
||||
});
|
||||
return yield setFeatures(response);
|
||||
yield setFeatures(response);
|
||||
yield controls.dispatch(
|
||||
STORE_KEY,
|
||||
'invalidateResolutionForStoreSelector',
|
||||
'getModifiedFeatures'
|
||||
);
|
||||
} catch (error) {
|
||||
throw new Error();
|
||||
}
|
||||
|
|
|
@ -12,10 +12,14 @@ import { API_NAMESPACE, OPTION_NAME_PREFIX } from './constants';
|
|||
export function* getModifiedFeatures() {
|
||||
try {
|
||||
const response = yield apiFetch({
|
||||
path: `${API_NAMESPACE}/options?search=` + OPTION_NAME_PREFIX,
|
||||
path: `wc-admin/options?options=` + OPTION_NAME_PREFIX,
|
||||
});
|
||||
|
||||
yield setModifiedFeatures(Object.keys(response));
|
||||
yield setModifiedFeatures(
|
||||
response && response[OPTION_NAME_PREFIX]
|
||||
? Object.keys(response[OPTION_NAME_PREFIX])
|
||||
: []
|
||||
);
|
||||
} catch (error) {
|
||||
throw new Error();
|
||||
}
|
||||
|
|
|
@ -23,13 +23,17 @@ function Features() {
|
|||
|
||||
return (
|
||||
<div id="wc-admin-test-helper-features">
|
||||
<h2>Features</h2>
|
||||
<h2>
|
||||
Features
|
||||
<Button
|
||||
disabled={modifiedFeatures.length === 0}
|
||||
onClick={() => resetModifiedFeatures()}
|
||||
isSecondary
|
||||
style={{ marginLeft: '24px' }}
|
||||
>
|
||||
Reset to defaults
|
||||
</Button>
|
||||
</h2>
|
||||
<table className="features wp-list-table striped table-view-list widefat">
|
||||
<thead>
|
||||
<tr>
|
||||
|
|
Loading…
Reference in New Issue