-
Notifications
You must be signed in to change notification settings - Fork 316
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WIP: Working version of AJAX status report
- Loading branch information
1 parent
63fee1b
commit 7d98765
Showing
6 changed files
with
158 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
assets/js/status-report/components/reports/report/container.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { Panel, PanelHeader, Button, Notice } from '@wordpress/components'; | ||
import { decodeEntities } from '@wordpress/html-entities'; | ||
import { RawHTML } from '@wordpress/element'; | ||
import { safeHTML } from '@wordpress/dom'; | ||
|
||
export default ({ id, title, actions = [], messages = [], children }) => { | ||
return ( | ||
<Panel id={title} className="ep-status-report"> | ||
<PanelHeader> | ||
<h2 id={id}>{title}</h2> | ||
{actions.map(({ href, label }) => ( | ||
<Button | ||
href={decodeEntities(href)} | ||
isDestructive | ||
isSecondary | ||
isSmall | ||
key={href} | ||
> | ||
{label} | ||
</Button> | ||
))} | ||
</PanelHeader> | ||
|
||
{messages.map(({ message, type }) => ( | ||
<Notice status={type} isDismissible={false}> | ||
<RawHTML>{safeHTML(message)}</RawHTML> | ||
</Notice> | ||
))} | ||
|
||
{children} | ||
</Panel> | ||
); | ||
}; |
42 changes: 42 additions & 0 deletions
42
assets/js/status-report/components/reports/report/content.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/** | ||
* WordPress dependencies. | ||
*/ | ||
import { PanelBody } from '@wordpress/components'; | ||
import { WPElement } from '@wordpress/element'; | ||
import { decodeEntities } from '@wordpress/html-entities'; | ||
import Value from './value'; | ||
|
||
/** | ||
* Field value component. | ||
* | ||
* @param {object} props Component props. | ||
* @param {object} props.fields Fields to render. | ||
* @param {string} props.title Title. | ||
* | ||
* @returns {WPElement} Value component. | ||
*/ | ||
export default ({ fields, title }) => { | ||
return ( | ||
<PanelBody key={title} title={decodeEntities(title)} initialOpen={false}> | ||
<table cellPadding="0" cellSpacing="0" className="wp-list-table widefat striped"> | ||
<colgroup> | ||
<col /> | ||
<col /> | ||
</colgroup> | ||
<tbody> | ||
{Object.entries(fields).map(([key, { description = '', label, value }]) => ( | ||
<tr key={key}> | ||
<td> | ||
{label} | ||
{description ? <small>{description}</small> : null} | ||
</td> | ||
<td> | ||
<Value value={value} /> | ||
</td> | ||
</tr> | ||
))} | ||
</tbody> | ||
</table> | ||
</PanelBody> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/** | ||
* Load a group report data via AJAX | ||
* | ||
* @param {string} id Group ID. | ||
* | ||
* | ||
* @returns {Promise} Group data. | ||
*/ | ||
export const loadGroupAjax = async (id) => { | ||
const { ajaxurl } = window; | ||
|
||
const data = new FormData(); | ||
data.append('action', 'ep_load_groups'); | ||
data.append('report', id); | ||
return fetch(ajaxurl, { method: 'POST', body: data }); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters