Changed hooks for TriggerCronJob
This commit is contained in:
parent
1089048afd
commit
e9faecbfc7
|
@ -2,8 +2,7 @@
|
||||||
* External dependencies.
|
* External dependencies.
|
||||||
*/
|
*/
|
||||||
import { SelectControl } from '@wordpress/components';
|
import { SelectControl } from '@wordpress/components';
|
||||||
import { withDispatch, withSelect } from '@wordpress/data';
|
import { useDispatch, useSelect } from '@wordpress/data';
|
||||||
import { compose } from '@wordpress/compose';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Internal dependencies
|
* Internal dependencies
|
||||||
|
@ -12,13 +11,21 @@ import { STORE_KEY } from '../data/constants';
|
||||||
|
|
||||||
export const TRIGGER_CRON_ACTION_NAME = 'runSelectedCronJob';
|
export const TRIGGER_CRON_ACTION_NAME = 'runSelectedCronJob';
|
||||||
|
|
||||||
const TriggerCron = ({ cronList, updateCommandParams }) => {
|
export const TriggerCronJob = () => {
|
||||||
|
const { cronList } = useSelect((select) => {
|
||||||
|
const { getCronJobs } = select(STORE_KEY);
|
||||||
|
return {
|
||||||
|
cronList: getCronJobs(),
|
||||||
|
};
|
||||||
|
});
|
||||||
|
const { updateCommandParams } = useDispatch(STORE_KEY);
|
||||||
|
|
||||||
function onCronChange(selectedValue) {
|
function onCronChange(selectedValue) {
|
||||||
const { hook, signature } = cronList[selectedValue];
|
const { hook, signature } = cronList[selectedValue];
|
||||||
updateCommandParams(TRIGGER_CRON_ACTION_NAME, { hook, signature });
|
updateCommandParams(TRIGGER_CRON_ACTION_NAME, { hook, signature });
|
||||||
}
|
}
|
||||||
|
|
||||||
function getOptions(cronList) {
|
function getOptions() {
|
||||||
return Object.keys(cronList).map((name) => {
|
return Object.keys(cronList).map((name) => {
|
||||||
return { label: name, value: name };
|
return { label: name, value: name };
|
||||||
});
|
});
|
||||||
|
@ -33,22 +40,9 @@ const TriggerCron = ({ cronList, updateCommandParams }) => {
|
||||||
label="Select cron job to run"
|
label="Select cron job to run"
|
||||||
onChange={onCronChange}
|
onChange={onCronChange}
|
||||||
labelPosition="side"
|
labelPosition="side"
|
||||||
options={getOptions(cronList)}
|
options={getOptions()}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export const TriggerCronJob = compose(
|
|
||||||
withSelect((select) => {
|
|
||||||
const { getCronJobs } = select(STORE_KEY);
|
|
||||||
return {
|
|
||||||
cronList: getCronJobs(),
|
|
||||||
};
|
|
||||||
}),
|
|
||||||
withDispatch((dispatch) => {
|
|
||||||
const { updateCommandParams } = dispatch(STORE_KEY);
|
|
||||||
return { updateCommandParams };
|
|
||||||
})
|
|
||||||
)(TriggerCron);
|
|
||||||
|
|
Loading…
Reference in New Issue