Load data inconsistencies async from API
[MAILPOET-6219]
This commit is contained in:
committed by
Aschepikov
parent
a4c901fba7
commit
f3d6813d97
@ -1,6 +1,6 @@
|
||||
import { MailPoet } from 'mailpoet';
|
||||
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 { KeyValueTable } from 'common/key-value-table';
|
||||
|
||||
@ -8,14 +8,28 @@ type DataInconsistencies = {
|
||||
[key: string]: number;
|
||||
};
|
||||
|
||||
type Props = {
|
||||
dataInconsistencies: DataInconsistencies;
|
||||
};
|
||||
|
||||
export function DataInconsistencies({ dataInconsistencies }: Props) {
|
||||
const [data, setData] = useState(dataInconsistencies);
|
||||
export function DataInconsistencies() {
|
||||
const [data, setData] = useState({ total: 0 } as DataInconsistencies);
|
||||
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(
|
||||
() => ({
|
||||
orphaned_sending_tasks: __('Orphaned Sending Tasks', 'mailpoet'),
|
||||
|
@ -98,7 +98,6 @@ function renderMSSSection(data) {
|
||||
export function SystemStatus() {
|
||||
const systemStatusData = window.systemStatusData;
|
||||
const actionSchedulerData = window.actionSchedulerData;
|
||||
const dataInconsistencies = window.dataInconsistencies;
|
||||
|
||||
return (
|
||||
<>
|
||||
@ -116,7 +115,7 @@ export function SystemStatus() {
|
||||
{actionSchedulerData ? (
|
||||
<QueueStatus statusData={systemStatusData.queueStatus} />
|
||||
) : null}
|
||||
<DataInconsistencies dataInconsistencies={dataInconsistencies} />
|
||||
<DataInconsistencies />
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
@ -63,6 +63,10 @@ class Help extends APIEndpoint {
|
||||
}
|
||||
}
|
||||
|
||||
public function getInconsistentDataStatus(): Response {
|
||||
return $this->successResponse($this->dataInconsistencyController->getInconsistentDataStatus());
|
||||
}
|
||||
|
||||
public function fixInconsistentData($data): Response {
|
||||
try {
|
||||
$this->dataInconsistencyController->fixInconsistentData($data['inconsistency'] ?? '');
|
||||
|
@ -15,7 +15,6 @@ use MailPoet\Newsletter\Url as NewsletterURL;
|
||||
use MailPoet\Router\Endpoints\CronDaemon;
|
||||
use MailPoet\Services\Bridge;
|
||||
use MailPoet\SystemReport\SystemReportCollector;
|
||||
use MailPoet\Util\DataInconsistency\DataInconsistencyController;
|
||||
use MailPoet\WP\DateTime;
|
||||
use MailPoet\WP\Functions as WPFunctions;
|
||||
|
||||
@ -26,7 +25,6 @@ class Help {
|
||||
private Bridge $bridge;
|
||||
private ScheduledTasksRepository $scheduledTasksRepository;
|
||||
private SendingQueuesRepository $sendingQueuesRepository;
|
||||
private DataInconsistencyController $dataInconsistencyController;
|
||||
private NewsletterURL $newsletterUrl;
|
||||
|
||||
public function __construct(
|
||||
@ -36,7 +34,6 @@ class Help {
|
||||
Bridge $bridge,
|
||||
ScheduledTasksRepository $scheduledTasksRepository,
|
||||
SendingQueuesRepository $sendingQueuesRepository,
|
||||
DataInconsistencyController $dataInconsistencyController,
|
||||
NewsletterURL $newsletterUrl
|
||||
) {
|
||||
$this->pageRenderer = $pageRenderer;
|
||||
@ -45,7 +42,6 @@ class Help {
|
||||
$this->bridge = $bridge;
|
||||
$this->scheduledTasksRepository = $scheduledTasksRepository;
|
||||
$this->sendingQueuesRepository = $sendingQueuesRepository;
|
||||
$this->dataInconsistencyController = $dataInconsistencyController;
|
||||
$this->newsletterUrl = $newsletterUrl;
|
||||
}
|
||||
|
||||
@ -90,7 +86,6 @@ class Help {
|
||||
'systemInfoData' => $systemInfoData,
|
||||
'systemStatusData' => $systemStatusData,
|
||||
'actionSchedulerData' => $this->getActionSchedulerData(),
|
||||
'dataInconsistencies' => $this->dataInconsistencyController->getInconsistentDataStatus(),
|
||||
]
|
||||
);
|
||||
}
|
||||
|
@ -16,7 +16,6 @@ use MailPoet\Services\Bridge;
|
||||
use MailPoet\SystemReport\SystemReportCollector;
|
||||
use MailPoet\Test\DataFactories\Newsletter;
|
||||
use MailPoet\Test\DataFactories\ScheduledTask as ScheduledTaskFactory;
|
||||
use MailPoet\Util\DataInconsistency\DataInconsistencyController;
|
||||
use MailPoetVendor\Carbon\Carbon;
|
||||
|
||||
class HelpTest extends \MailPoetTest {
|
||||
@ -44,7 +43,6 @@ class HelpTest extends \MailPoetTest {
|
||||
$this->diContainer->get(Bridge::class),
|
||||
$this->diContainer->get(ScheduledTasksRepository::class),
|
||||
$this->sendingQueuesRepository,
|
||||
$this->diContainer->get(DataInconsistencyController::class),
|
||||
$this->diContainer->get(Url::class)
|
||||
);
|
||||
}
|
||||
|
@ -8,7 +8,6 @@
|
||||
var systemInfoData = <%= json_encode(systemInfoData) %>;
|
||||
var systemStatusData = <%= json_encode(systemStatusData) %>;
|
||||
var actionSchedulerData = <%= json_encode(actionSchedulerData) %>;
|
||||
var dataInconsistencies = <%= json_encode(dataInconsistencies) %>;
|
||||
</script>
|
||||
|
||||
<div id="help_container"></div>
|
||||
|
Reference in New Issue
Block a user