| 1 |
/** |
| 2 |
* WordPress dependencies. |
| 3 |
*/ |
| 4 |
import { Button, Notice, Panel, PanelBody, PanelHeader } from '@wordpress/components'; |
| 5 |
import { safeHTML } from '@wordpress/dom'; |
| 6 |
import { RawHTML, WPElement } from '@wordpress/element'; |
| 7 |
import { decodeEntities } from '@wordpress/html-entities'; |
| 8 |
|
| 9 |
/** |
| 10 |
* Internal dependencies. |
| 11 |
*/ |
| 12 |
import Value from './report/value'; |
| 13 |
|
| 14 |
/** |
| 15 |
* Report components. |
| 16 |
* |
| 17 |
* @param {object} props Component props. |
| 18 |
* @param {Array} props.actions Report actions. |
| 19 |
* @param {object} props.groups Report groups. |
| 20 |
* @param {string} props.id Report ID. |
| 21 |
* @param {string} props.messages Report messages. |
| 22 |
* @param {string} props.title Report title. |
| 23 |
* @returns {WPElement} Report component. |
| 24 |
*/ |
| 25 |
export default ({ actions, groups, id, messages, title }) => { |
| 26 |
if (groups.length < 1) { |
| 27 |
return null; |
| 28 |
} |
| 29 |
|
| 30 |
return ( |
| 31 |
<Panel id={title}> |
| 32 |
<PanelHeader> |
| 33 |
<h2 id={id}>{title}</h2> |
| 34 |
{actions.map(({ href, label }) => ( |
| 35 |
<Button |
| 36 |
href={decodeEntities(href)} |
| 37 |
isDestructive |
| 38 |
isSecondary |
| 39 |
isSmall |
| 40 |
key={href} |
| 41 |
> |
| 42 |
{label} |
| 43 |
</Button> |
| 44 |
))} |
| 45 |
</PanelHeader> |
| 46 |
{messages.map(({ message, type }) => ( |
| 47 |
<Notice status={type} isDismissible={false}> |
| 48 |
<RawHTML>{safeHTML(message)}</RawHTML> |
| 49 |
</Notice> |
| 50 |
))} |
| 51 |
{groups.map(({ fields, title }) => ( |
| 52 |
<PanelBody key={title} title={decodeEntities(title)} initialOpen={false}> |
| 53 |
<table |
| 54 |
cellPadding="0" |
| 55 |
cellSpacing="0" |
| 56 |
className="wp-list-table widefat striped" |
| 57 |
> |
| 58 |
<colgroup> |
| 59 |
<col /> |
| 60 |
<col /> |
| 61 |
</colgroup> |
| 62 |
<tbody> |
| 63 |
{Object.entries(fields).map( |
| 64 |
([key, { description = '', label, value }]) => ( |
| 65 |
<tr key={key}> |
| 66 |
<td> |
| 67 |
{label} |
| 68 |
{description ? <small>{description}</small> : null} |
| 69 |
</td> |
| 70 |
<td> |
| 71 |
<Value value={value} /> |
| 72 |
</td> |
| 73 |
</tr> |
| 74 |
), |
| 75 |
)} |
| 76 |
</tbody> |
| 77 |
</table> |
| 78 |
</PanelBody> |
| 79 |
))} |
| 80 |
</Panel> |
| 81 |
); |
| 82 |
}; |
| 83 |
|