Load data inconsistencies async from API

[MAILPOET-6219]
This commit is contained in:
Rostislav Wolny
2024-09-10 14:48:10 +02:00
committed by Aschepikov
parent a4c901fba7
commit f3d6813d97
6 changed files with 26 additions and 17 deletions

View File

@ -1,6 +1,6 @@
import { MailPoet } from 'mailpoet'; import { MailPoet } from 'mailpoet';
import { Button } from '@wordpress/components'; import { Button } from '@wordpress/components';
import { useState, useCallback, useMemo } from '@wordpress/element'; import { useState, useCallback, useMemo, useEffect } from '@wordpress/element';
import { __ } from '@wordpress/i18n'; import { __ } from '@wordpress/i18n';
import { KeyValueTable } from 'common/key-value-table'; import { KeyValueTable } from 'common/key-value-table';
@ -8,14 +8,28 @@ type DataInconsistencies = {
[key: string]: number; [key: string]: number;
}; };
type Props = { export function DataInconsistencies() {
dataInconsistencies: DataInconsistencies; const [data, setData] = useState({ total: 0 } as DataInconsistencies);
};
export function DataInconsistencies({ dataInconsistencies }: Props) {
const [data, setData] = useState(dataInconsistencies);
const [cleaningKey, setCleaningKey] = useState(''); const [cleaningKey, setCleaningKey] = useState('');
useEffect(() => {
MailPoet.Ajax.post({
api_version: window.mailpoet_api_version,
endpoint: 'help',
action: 'getInconsistentDataStatus',
})
.done((response) => {
setData((response.data as DataInconsistencies) || null);
})
.catch((e) => {
MailPoet.Notice.show({
type: 'error',
message: e.errors.map((error) => error.message).join(' '),
scroll: true,
});
});
}, []);
const labelsMap = useMemo( const labelsMap = useMemo(
() => ({ () => ({
orphaned_sending_tasks: __('Orphaned Sending Tasks', 'mailpoet'), orphaned_sending_tasks: __('Orphaned Sending Tasks', 'mailpoet'),

View File

@ -98,7 +98,6 @@ function renderMSSSection(data) {
export function SystemStatus() { export function SystemStatus() {
const systemStatusData = window.systemStatusData; const systemStatusData = window.systemStatusData;
const actionSchedulerData = window.actionSchedulerData; const actionSchedulerData = window.actionSchedulerData;
const dataInconsistencies = window.dataInconsistencies;
return ( return (
<> <>
@ -116,7 +115,7 @@ export function SystemStatus() {
{actionSchedulerData ? ( {actionSchedulerData ? (
<QueueStatus statusData={systemStatusData.queueStatus} /> <QueueStatus statusData={systemStatusData.queueStatus} />
) : null} ) : null}
<DataInconsistencies dataInconsistencies={dataInconsistencies} /> <DataInconsistencies />
</> </>
); );
} }

View File

@ -63,6 +63,10 @@ class Help extends APIEndpoint {
} }
} }
public function getInconsistentDataStatus(): Response {
return $this->successResponse($this->dataInconsistencyController->getInconsistentDataStatus());
}
public function fixInconsistentData($data): Response { public function fixInconsistentData($data): Response {
try { try {
$this->dataInconsistencyController->fixInconsistentData($data['inconsistency'] ?? ''); $this->dataInconsistencyController->fixInconsistentData($data['inconsistency'] ?? '');

View File

@ -15,7 +15,6 @@ use MailPoet\Newsletter\Url as NewsletterURL;
use MailPoet\Router\Endpoints\CronDaemon; use MailPoet\Router\Endpoints\CronDaemon;
use MailPoet\Services\Bridge; use MailPoet\Services\Bridge;
use MailPoet\SystemReport\SystemReportCollector; use MailPoet\SystemReport\SystemReportCollector;
use MailPoet\Util\DataInconsistency\DataInconsistencyController;
use MailPoet\WP\DateTime; use MailPoet\WP\DateTime;
use MailPoet\WP\Functions as WPFunctions; use MailPoet\WP\Functions as WPFunctions;
@ -26,7 +25,6 @@ class Help {
private Bridge $bridge; private Bridge $bridge;
private ScheduledTasksRepository $scheduledTasksRepository; private ScheduledTasksRepository $scheduledTasksRepository;
private SendingQueuesRepository $sendingQueuesRepository; private SendingQueuesRepository $sendingQueuesRepository;
private DataInconsistencyController $dataInconsistencyController;
private NewsletterURL $newsletterUrl; private NewsletterURL $newsletterUrl;
public function __construct( public function __construct(
@ -36,7 +34,6 @@ class Help {
Bridge $bridge, Bridge $bridge,
ScheduledTasksRepository $scheduledTasksRepository, ScheduledTasksRepository $scheduledTasksRepository,
SendingQueuesRepository $sendingQueuesRepository, SendingQueuesRepository $sendingQueuesRepository,
DataInconsistencyController $dataInconsistencyController,
NewsletterURL $newsletterUrl NewsletterURL $newsletterUrl
) { ) {
$this->pageRenderer = $pageRenderer; $this->pageRenderer = $pageRenderer;
@ -45,7 +42,6 @@ class Help {
$this->bridge = $bridge; $this->bridge = $bridge;
$this->scheduledTasksRepository = $scheduledTasksRepository; $this->scheduledTasksRepository = $scheduledTasksRepository;
$this->sendingQueuesRepository = $sendingQueuesRepository; $this->sendingQueuesRepository = $sendingQueuesRepository;
$this->dataInconsistencyController = $dataInconsistencyController;
$this->newsletterUrl = $newsletterUrl; $this->newsletterUrl = $newsletterUrl;
} }
@ -90,7 +86,6 @@ class Help {
'systemInfoData' => $systemInfoData, 'systemInfoData' => $systemInfoData,
'systemStatusData' => $systemStatusData, 'systemStatusData' => $systemStatusData,
'actionSchedulerData' => $this->getActionSchedulerData(), 'actionSchedulerData' => $this->getActionSchedulerData(),
'dataInconsistencies' => $this->dataInconsistencyController->getInconsistentDataStatus(),
] ]
); );
} }

View File

@ -16,7 +16,6 @@ use MailPoet\Services\Bridge;
use MailPoet\SystemReport\SystemReportCollector; use MailPoet\SystemReport\SystemReportCollector;
use MailPoet\Test\DataFactories\Newsletter; use MailPoet\Test\DataFactories\Newsletter;
use MailPoet\Test\DataFactories\ScheduledTask as ScheduledTaskFactory; use MailPoet\Test\DataFactories\ScheduledTask as ScheduledTaskFactory;
use MailPoet\Util\DataInconsistency\DataInconsistencyController;
use MailPoetVendor\Carbon\Carbon; use MailPoetVendor\Carbon\Carbon;
class HelpTest extends \MailPoetTest { class HelpTest extends \MailPoetTest {
@ -44,7 +43,6 @@ class HelpTest extends \MailPoetTest {
$this->diContainer->get(Bridge::class), $this->diContainer->get(Bridge::class),
$this->diContainer->get(ScheduledTasksRepository::class), $this->diContainer->get(ScheduledTasksRepository::class),
$this->sendingQueuesRepository, $this->sendingQueuesRepository,
$this->diContainer->get(DataInconsistencyController::class),
$this->diContainer->get(Url::class) $this->diContainer->get(Url::class)
); );
} }

View File

@ -8,7 +8,6 @@
var systemInfoData = <%= json_encode(systemInfoData) %>; var systemInfoData = <%= json_encode(systemInfoData) %>;
var systemStatusData = <%= json_encode(systemStatusData) %>; var systemStatusData = <%= json_encode(systemStatusData) %>;
var actionSchedulerData = <%= json_encode(actionSchedulerData) %>; var actionSchedulerData = <%= json_encode(actionSchedulerData) %>;
var dataInconsistencies = <%= json_encode(dataInconsistencies) %>;
</script> </script>
<div id="help_container"></div> <div id="help_container"></div>