2021-04-27 02:20:42 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
import { withDispatch, withSelect } from '@wordpress/data';
|
|
|
|
import { compose } from '@wordpress/compose';
|
|
|
|
import { Notice, Button } from '@wordpress/components';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
|
|
|
import { default as commands } from './commands';
|
|
|
|
import { STORE_KEY } from './data/constants';
|
|
|
|
import './data';
|
|
|
|
|
2021-05-24 17:50:44 +00:00
|
|
|
function Tools( { actions, currentlyRunningCommands, messages, comandParams } ) {
|
2021-04-27 02:20:42 +00:00
|
|
|
actions = actions();
|
|
|
|
return (
|
|
|
|
<div id="wc-admin-test-helper-tools">
|
|
|
|
<h2>Tools</h2>
|
|
|
|
<p>This section contains miscellaneous tools.</p>
|
|
|
|
{ Object.keys( messages ).map( ( key ) => {
|
|
|
|
return (
|
|
|
|
<Notice
|
|
|
|
status={ messages[ key ].status }
|
|
|
|
key={ key }
|
|
|
|
isDismissible={ false }
|
|
|
|
>
|
|
|
|
{ key }: { messages[ key ].message }
|
|
|
|
</Notice>
|
|
|
|
);
|
|
|
|
} ) }
|
|
|
|
<table className="tools wp-list-table striped table-view-list widefat">
|
|
|
|
<thead>
|
|
|
|
<tr>
|
|
|
|
<th>Command</th>
|
|
|
|
<th>Description</th>
|
|
|
|
<th>Run</th>
|
|
|
|
</tr>
|
|
|
|
</thead>
|
|
|
|
<tbody>
|
2021-05-24 17:50:44 +00:00
|
|
|
{ commands.map( ( { action, command, description }, index ) => {
|
|
|
|
const params = comandParams[ action ] ?? false;
|
2021-04-27 02:20:42 +00:00
|
|
|
return (
|
|
|
|
<tr key={ index }>
|
2021-05-24 17:50:44 +00:00
|
|
|
<td className="command">{ command }</td>
|
|
|
|
<td>{ description }</td>
|
2021-04-27 02:20:42 +00:00
|
|
|
<td>
|
|
|
|
<Button
|
2021-05-24 17:50:44 +00:00
|
|
|
onClick={ () => actions[ action ]( params ) }
|
2021-04-27 02:20:42 +00:00
|
|
|
disabled={
|
|
|
|
currentlyRunningCommands[
|
2021-05-24 17:50:44 +00:00
|
|
|
command
|
2021-04-27 02:20:42 +00:00
|
|
|
]
|
|
|
|
}
|
|
|
|
isPrimary
|
|
|
|
>
|
|
|
|
Run
|
|
|
|
</Button>
|
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
);
|
|
|
|
} ) }
|
|
|
|
</tbody>
|
|
|
|
</table>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
export default compose(
|
|
|
|
withSelect( ( select ) => {
|
2021-05-24 17:50:44 +00:00
|
|
|
const { getCurrentlyRunning, getMessages, getCommandParams } = select( STORE_KEY );
|
2021-04-27 02:20:42 +00:00
|
|
|
return {
|
|
|
|
currentlyRunningCommands: getCurrentlyRunning(),
|
|
|
|
messages: getMessages(),
|
2021-05-24 17:50:44 +00:00
|
|
|
comandParams: getCommandParams(),
|
2021-04-27 02:20:42 +00:00
|
|
|
};
|
|
|
|
} ),
|
|
|
|
withDispatch( ( dispatch ) => {
|
|
|
|
const actions = function () {
|
|
|
|
return dispatch( STORE_KEY );
|
|
|
|
};
|
|
|
|
|
|
|
|
return {
|
|
|
|
actions,
|
|
|
|
};
|
|
|
|
} )
|
|
|
|
)( Tools );
|