Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Afform - Improve UX for batch-processing submissions #31906

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions ext/afform/core/afform.php
Original file line number Diff line number Diff line change
Expand Up @@ -687,9 +687,25 @@ function afform_shortcode_content($content, $atts, $args, $context) {
*/
function afform_civicrm_searchKitTasks(array &$tasks, bool $checkPermissions, ?int $userID) {
$tasks['AfformSubmission']['process'] = [
'module' => 'afSearchTasks',
'title' => E::ts('Process Submissions'),
'icon' => 'fa-check-square-o',
'uiDialog' => ['templateUrl' => '~/afSearchTasks/afformSubmissionProcessTask.html'],
// The Afform.process API doesn't support batches so use get+chaining
'apiBatch' => [
'action' => 'get',
'params' => [
'select' => ['id', 'afform_name'],
'where' => [['status_id:name', '=', 'Pending']],
'chain' => [
['Afform', 'process', ['submissionId' => '$id', 'name' => '$afform_name']],
],
],
'conditions' => [
['check user permission', '=', ['administer afform']],
],
'confirmMsg' => E::ts('Confirm processing %1 %2.'),
'runMsg' => E::ts('Processing %1 %2...'),
'successMsg' => E::ts('Successfully processed %1 %2.'),
'errorMsg' => E::ts('An error occurred while attempting to process %1 %2.'),
],
];
}
14 changes: 0 additions & 14 deletions ext/afform/core/ang/afSearchTasks.ang.php

This file was deleted.

7 changes: 0 additions & 7 deletions ext/afform/core/ang/afSearchTasks.module.js

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -705,7 +705,7 @@ private function checkLinkAccess(array $link, array $data): bool {
if (empty($link['path']) && empty($link['task'])) {
return FALSE;
}
if (!empty($link['entity']) && !empty($link['action']) && !in_array($link['action'], ['view', 'preview'], TRUE) && $this->getCheckPermissions()) {
if (!empty($link['entity']) && !empty($link['action']) && !in_array($link['action'], ['view', 'preview', 'get'], TRUE) && $this->getCheckPermissions()) {
$actionName = $this->getPermittedLinkAction($link['entity'], $link['action']);
if (!$actionName) {
return FALSE;
Expand Down
16 changes: 12 additions & 4 deletions ext/search_kit/Civi/Api4/Action/SearchDisplay/GetSearchTasks.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,12 @@ public function _run(\Civi\Api4\Generic\Result $result) {
$tasks[$entity['name']]['enable'] = [
'title' => E::ts('Enable %1', [1 => $entity['title_plural']]),
'icon' => 'fa-toggle-on',
'conditions' => [['is_active', '=', FALSE]],
'apiBatch' => [
'action' => 'update',
'params' => ['values' => ['is_active' => TRUE]],
'params' => [
'values' => ['is_active' => TRUE],
'where' => [['is_active', '=', FALSE]],
],
'runMsg' => E::ts('Enabling %1 %2...'),
'successMsg' => E::ts('Successfully enabled %1 %2.'),
'errorMsg' => E::ts('An error occurred while attempting to enable %1 %2.'),
Expand All @@ -96,10 +98,12 @@ public function _run(\Civi\Api4\Generic\Result $result) {
$tasks[$entity['name']]['disable'] = [
'title' => E::ts('Disable %1', [1 => $entity['title_plural']]),
'icon' => 'fa-toggle-off',
'conditions' => [['is_active', '=', TRUE]],
'apiBatch' => [
'action' => 'update',
'params' => ['values' => ['is_active' => FALSE]],
'params' => [
'values' => ['is_active' => FALSE],
'where' => [['is_active', '=', TRUE]],
],
'confirmMsg' => E::ts('Are you sure you want to disable %1 %2?'),
'runMsg' => E::ts('Disabling %1 %2...'),
'successMsg' => E::ts('Successfully disabled %1 %2.'),
Expand Down Expand Up @@ -222,6 +226,10 @@ public function _run(\Civi\Api4\Generic\Result $result) {
if (!empty($task['apiBatch']['fields'])) {
$this->getApiBatchFields($task);
}
// If action includes a WHERE clause, add it to the conditions (see e.g. the enable/disable actions)
if (!empty($task['apiBatch']['params']['where'])) {
$task['conditions'] = array_merge($task['conditions'] ?? [], $task['apiBatch']['params']['where']);
}
}

usort($tasks[$entity['name']], function($a, $b) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@
this.refreshAfterTask = function(result, ids) {
displayCtrl.selectedRows = [];
displayCtrl.allRowsSelected = false;
if (result.action === 'inlineEdit' && ids && ids.length === 1) {
if (ids && result.action === 'inlineEdit' && ids.length === 1) {
displayCtrl.refreshAfterEditing(result, ids[0]);
}
else {
Expand Down