Update reset to default functionality

This commit is contained in:
Lourens Schep 2022-03-15 11:29:43 -03:00
parent 46cba23313
commit 66073a6b8f
4 changed files with 39 additions and 25 deletions

View File

@ -2,12 +2,13 @@
* External dependencies * External dependencies
*/ */
import { apiFetch } from '@wordpress/data-controls'; import { apiFetch } from '@wordpress/data-controls';
import { controls } from '@wordpress/data';
/** /**
* Internal dependencies * Internal dependencies
*/ */
import TYPES from './action-types'; import TYPES from './action-types';
import { API_NAMESPACE } from './constants'; import { API_NAMESPACE, STORE_KEY } from './constants';
export function* resetModifiedFeatures() { export function* resetModifiedFeatures() {
try { try {
@ -30,7 +31,12 @@ export function* toggleFeature(featureName) {
path: API_NAMESPACE + '/features/' + featureName + '/toggle', path: API_NAMESPACE + '/features/' + featureName + '/toggle',
headers: { 'content-type': 'application/json' }, headers: { 'content-type': 'application/json' },
}); });
return yield setFeatures(response); yield setFeatures(response);
yield controls.dispatch(
STORE_KEY,
'invalidateResolutionForStoreSelector',
'getModifiedFeatures'
);
} catch (error) { } catch (error) {
throw new Error(); throw new Error();
} }

View File

@ -12,10 +12,14 @@ 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: `${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) { } catch (error) {
throw new Error(); throw new Error();
} }

View File

@ -23,13 +23,17 @@ function Features() {
return ( return (
<div id="wc-admin-test-helper-features"> <div id="wc-admin-test-helper-features">
<h2>Features</h2> <h2>
Features
<Button <Button
disabled={modifiedFeatures.length === 0} disabled={modifiedFeatures.length === 0}
onClick={() => resetModifiedFeatures()} onClick={() => resetModifiedFeatures()}
isSecondary
style={{ marginLeft: '24px' }}
> >
Reset to defaults Reset to defaults
</Button> </Button>
</h2>
<table className="features wp-list-table striped table-view-list widefat"> <table className="features wp-list-table striped table-view-list widefat">
<thead> <thead>
<tr> <tr>