From e9faecbfc7968380d36da529b3b92c129d3fd0b5 Mon Sep 17 00:00:00 2001 From: Fernando Marichal Date: Fri, 18 Jun 2021 13:54:45 -0300 Subject: [PATCH] Changed hooks for TriggerCronJob --- src/tools/commands/trigger-cron.js | 30 ++++++++++++------------------ 1 file changed, 12 insertions(+), 18 deletions(-) diff --git a/src/tools/commands/trigger-cron.js b/src/tools/commands/trigger-cron.js index 7c0d687983f..fc232455ccf 100644 --- a/src/tools/commands/trigger-cron.js +++ b/src/tools/commands/trigger-cron.js @@ -2,8 +2,7 @@ * External dependencies. */ import { SelectControl } from '@wordpress/components'; -import { withDispatch, withSelect } from '@wordpress/data'; -import { compose } from '@wordpress/compose'; +import { useDispatch, useSelect } from '@wordpress/data'; /** * Internal dependencies @@ -12,13 +11,21 @@ import { STORE_KEY } from '../data/constants'; 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) { const { hook, signature } = cronList[selectedValue]; updateCommandParams(TRIGGER_CRON_ACTION_NAME, { hook, signature }); } - function getOptions(cronList) { + function getOptions() { return Object.keys(cronList).map((name) => { return { label: name, value: name }; }); @@ -33,22 +40,9 @@ const TriggerCron = ({ cronList, updateCommandParams }) => { label="Select cron job to run" onChange={onCronChange} labelPosition="side" - options={getOptions(cronList)} + options={getOptions()} /> )} ); }; - -export const TriggerCronJob = compose( - withSelect((select) => { - const { getCronJobs } = select(STORE_KEY); - return { - cronList: getCronJobs(), - }; - }), - withDispatch((dispatch) => { - const { updateCommandParams } = dispatch(STORE_KEY); - return { updateCommandParams }; - }) -)(TriggerCron);