woocommerce/plugins/woocommerce-beta-tester/src/tools/index.js

88 lines
2.0 KiB
JavaScript
Raw Normal View History

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';
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>
{ commands.map( ( { action, command, description }, index ) => {
const params = comandParams[ action ] ?? false;
2021-04-27 02:20:42 +00:00
return (
<tr key={ index }>
<td className="command">{ command }</td>
<td>{ description }</td>
2021-04-27 02:20:42 +00:00
<td>
<Button
onClick={ () => actions[ action ]( params ) }
2021-04-27 02:20:42 +00:00
disabled={
currentlyRunningCommands[
command
2021-04-27 02:20:42 +00:00
]
}
isPrimary
>
Run
</Button>
</td>
</tr>
);
} ) }
</tbody>
</table>
</div>
);
}
export default compose(
withSelect( ( select ) => {
const { getCurrentlyRunning, getMessages, getCommandParams } = select( STORE_KEY );
2021-04-27 02:20:42 +00:00
return {
currentlyRunningCommands: getCurrentlyRunning(),
messages: getMessages(),
comandParams: getCommandParams(),
2021-04-27 02:20:42 +00:00
};
} ),
withDispatch( ( dispatch ) => {
const actions = function () {
return dispatch( STORE_KEY );
};
return {
actions,
};
} )
)( Tools );