Add workflow count to automation listing page

[MAILPOET-4540]
This commit is contained in:
Jan Jakes
2022-10-14 13:57:58 +02:00
committed by David Remer
parent 3eaa13a421
commit efd32043e3
5 changed files with 21 additions and 1 deletions

View File

@@ -4,7 +4,9 @@ declare global {
root: string; root: string;
nonce: string; nonce: string;
}; };
mailpoet_workflow_count: number;
} }
} }
export const api = window.mailpoet_automation_api; export const api = window.mailpoet_automation_api;
export const workflowCount = window.mailpoet_workflow_count;

View File

@@ -1,6 +1,11 @@
import { State } from './types'; import { State } from './types';
import { Workflow } from '../workflow'; import { Workflow } from '../workflow';
import { workflowCount } from '../../config';
export function getWorkflows(state: State): Workflow[] { export function getWorkflows(state: State): Workflow[] {
return state.workflows; return state.workflows;
} }
export function getWorkflowCount(state: State): number {
return state.workflows ? state.workflows.length : workflowCount;
}

View File

@@ -4,6 +4,7 @@ namespace MailPoet\AdminPages\Pages;
use MailPoet\AdminPages\PageRenderer; use MailPoet\AdminPages\PageRenderer;
use MailPoet\Automation\Engine\Migrations\Migrator; use MailPoet\Automation\Engine\Migrations\Migrator;
use MailPoet\Automation\Engine\Storage\WorkflowStorage;
use MailPoet\WP\Functions as WPFunctions; use MailPoet\WP\Functions as WPFunctions;
class Automation { class Automation {
@@ -16,14 +17,19 @@ class Automation {
/** @var WPFunctions */ /** @var WPFunctions */
private $wp; private $wp;
/** @var WorkflowStorage */
private $workflowStorage;
public function __construct( public function __construct(
Migrator $migrator, Migrator $migrator,
PageRenderer $pageRenderer, PageRenderer $pageRenderer,
WPFunctions $wp WPFunctions $wp,
WorkflowStorage $workflowStorage
) { ) {
$this->migrator = $migrator; $this->migrator = $migrator;
$this->pageRenderer = $pageRenderer; $this->pageRenderer = $pageRenderer;
$this->wp = $wp; $this->wp = $wp;
$this->workflowStorage = $workflowStorage;
} }
public function render() { public function render() {
@@ -36,6 +42,7 @@ class Automation {
'root' => rtrim($this->wp->escUrlRaw($this->wp->restUrl()), '/'), 'root' => rtrim($this->wp->escUrlRaw($this->wp->restUrl()), '/'),
'nonce' => $this->wp->wpCreateNonce('wp_rest'), 'nonce' => $this->wp->wpCreateNonce('wp_rest'),
], ],
'workflowCount' => $this->workflowStorage->getWorkflowCount(),
]); ]);
} }
} }

View File

@@ -93,6 +93,11 @@ class WorkflowStorage {
}, (array)$data); }, (array)$data);
} }
public function getWorkflowCount(): int {
$workflowTable = esc_sql($this->workflowTable);
return (int)$this->wpdb->get_var("SELECT COUNT(*) FROM $workflowTable");
}
/** @return string[] */ /** @return string[] */
public function getActiveTriggerKeys(): array { public function getActiveTriggerKeys(): array {
$workflowTable = esc_sql($this->workflowTable); $workflowTable = esc_sql($this->workflowTable);

View File

@@ -10,6 +10,7 @@
<% block after_javascript %> <% block after_javascript %>
<script type="text/javascript"> <script type="text/javascript">
var mailpoet_automation_api = <%= json_encode(api) %>; var mailpoet_automation_api = <%= json_encode(api) %>;
var mailpoet_workflow_count = <%= json_encode(workflowCount) %>;
</script> </script>
<%= javascript('automation.js')%> <%= javascript('automation.js')%>
<% endblock %> <% endblock %>