Add workflow count to automation listing page
[MAILPOET-4540]
This commit is contained in:
@@ -4,7 +4,9 @@ declare global {
|
||||
root: string;
|
||||
nonce: string;
|
||||
};
|
||||
mailpoet_workflow_count: number;
|
||||
}
|
||||
}
|
||||
|
||||
export const api = window.mailpoet_automation_api;
|
||||
export const workflowCount = window.mailpoet_workflow_count;
|
||||
|
@@ -1,6 +1,11 @@
|
||||
import { State } from './types';
|
||||
import { Workflow } from '../workflow';
|
||||
import { workflowCount } from '../../config';
|
||||
|
||||
export function getWorkflows(state: State): Workflow[] {
|
||||
return state.workflows;
|
||||
}
|
||||
|
||||
export function getWorkflowCount(state: State): number {
|
||||
return state.workflows ? state.workflows.length : workflowCount;
|
||||
}
|
||||
|
@@ -4,6 +4,7 @@ namespace MailPoet\AdminPages\Pages;
|
||||
|
||||
use MailPoet\AdminPages\PageRenderer;
|
||||
use MailPoet\Automation\Engine\Migrations\Migrator;
|
||||
use MailPoet\Automation\Engine\Storage\WorkflowStorage;
|
||||
use MailPoet\WP\Functions as WPFunctions;
|
||||
|
||||
class Automation {
|
||||
@@ -16,14 +17,19 @@ class Automation {
|
||||
/** @var WPFunctions */
|
||||
private $wp;
|
||||
|
||||
/** @var WorkflowStorage */
|
||||
private $workflowStorage;
|
||||
|
||||
public function __construct(
|
||||
Migrator $migrator,
|
||||
PageRenderer $pageRenderer,
|
||||
WPFunctions $wp
|
||||
WPFunctions $wp,
|
||||
WorkflowStorage $workflowStorage
|
||||
) {
|
||||
$this->migrator = $migrator;
|
||||
$this->pageRenderer = $pageRenderer;
|
||||
$this->wp = $wp;
|
||||
$this->workflowStorage = $workflowStorage;
|
||||
}
|
||||
|
||||
public function render() {
|
||||
@@ -36,6 +42,7 @@ class Automation {
|
||||
'root' => rtrim($this->wp->escUrlRaw($this->wp->restUrl()), '/'),
|
||||
'nonce' => $this->wp->wpCreateNonce('wp_rest'),
|
||||
],
|
||||
'workflowCount' => $this->workflowStorage->getWorkflowCount(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
@@ -93,6 +93,11 @@ class WorkflowStorage {
|
||||
}, (array)$data);
|
||||
}
|
||||
|
||||
public function getWorkflowCount(): int {
|
||||
$workflowTable = esc_sql($this->workflowTable);
|
||||
return (int)$this->wpdb->get_var("SELECT COUNT(*) FROM $workflowTable");
|
||||
}
|
||||
|
||||
/** @return string[] */
|
||||
public function getActiveTriggerKeys(): array {
|
||||
$workflowTable = esc_sql($this->workflowTable);
|
||||
|
@@ -10,6 +10,7 @@
|
||||
<% block after_javascript %>
|
||||
<script type="text/javascript">
|
||||
var mailpoet_automation_api = <%= json_encode(api) %>;
|
||||
var mailpoet_workflow_count = <%= json_encode(workflowCount) %>;
|
||||
</script>
|
||||
<%= javascript('automation.js')%>
|
||||
<% endblock %>
|
||||
|
Reference in New Issue
Block a user