Skip to content

Commit

Permalink
WIP: Report panel body variations
Browse files Browse the repository at this point in the history
  • Loading branch information
oscarssanchez committed Jan 27, 2025
1 parent 85deca7 commit 63fee1b
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 20 deletions.
23 changes: 13 additions & 10 deletions assets/js/status-report/components/reports.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,16 +65,19 @@ export default ({ plainTextReport, reports }) => {
</FlexItem>
</Flex>
</p>
{Object.entries(reports).map(([key, { actions, groups, messages, title }]) => (
<Report
actions={actions}
groups={groups}
id={key}
key={key}
messages={messages}
title={title}
/>
))}
{Object.entries(reports).map(
([key, { actions, groups, messages, title, is_ajax_report }]) => (
<Report
actions={actions}
groups={groups}
id={key}
key={key}
is_ajax_report={is_ajax_report}
messages={messages}
title={title}
/>
),
)}
</>
);
};
41 changes: 40 additions & 1 deletion assets/js/status-report/components/reports/report.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,52 @@ import Value from './report/value';
* @param {string} props.id Report ID.
* @param {string} props.messages Report messages.
* @param {string} props.title Report title.
* @param {boolean} props.is_ajax_report Whether the report is loaded via AJAX.
*
* @returns {WPElement} Report component.
*/
export default ({ actions, groups, id, messages, title }) => {
export default ({ actions, groups, id, messages, title, is_ajax_report }) => {
if (groups.length < 1) {
return null;
}

const loadAjax = () => {
console.log('test panel opened');
};

if (is_ajax_report) {
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>
))}
{groups.map(({ fields, title }) => (
<PanelBody
initialOpen={false}
onToggle={loadAjax}
key={title}
title={decodeEntities(title)}
/>
))}
</Panel>
);
}
return (
<Panel id={title} className="ep-status-report">
<PanelHeader>
Expand Down
1 change: 1 addition & 0 deletions includes/classes/Screen/StatusReport.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ function ( $report ) {
'groups' => $report->get_groups(),
'messages' => $report->get_messages(),
'title' => $report->get_title(),
'is_ajax_report' => $report->is_ajax_report(),
];
},
$reports
Expand Down
9 changes: 9 additions & 0 deletions includes/classes/StatusReport/IndexableContent.php
Original file line number Diff line number Diff line change
Expand Up @@ -191,4 +191,13 @@ protected function get_post_meta_fields(): array {

return $fields;
}

/**
* Return whether the report is loaded via AJAX.
*
* @return bool
*/
public function is_ajax_report(): bool {
return true;
}
}
9 changes: 0 additions & 9 deletions includes/classes/StatusReport/Indices.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,4 @@ function ( $fields, $label ) use ( $index ) {

return $groups;
}

/**
* Return whether the report is loaded via AJAX.
*
* @return bool
*/
public function is_ajax_report(): bool {
return true;
}
}

0 comments on commit 63fee1b

Please sign in to comment.