Fix incomplete pop-up message on delete Action

When an Action table is created with a 'danger' action_type and a
single handler method for a single object, the 'selection' and
'help' parameters are empty. This causes the pop-up message to be
incomplete. For example:

"You have selected: . Please confirm your selection. "

This patch fixes this behaviour by displaying the message with
the selected objects only when one or more objects are selected.
Otherwise, it only asks for confirmation.

Closes-Bug: 2000799

Test Plan:
PASS: Build python3-django-horizon package including these changes.
PASS: Test the behaviour for single delete actions. For example:
Create a patch strategy and press the "Delete" action. Verify
the following message is displayed in the pop-up message:
"Please confirm your selection. This action cannot be undone."

PASS: Test the behaviour for multiple delete actions. For example:
Upload more than one patch, select them and click on the 'Delete'
action. Verify the following message is displayed:
You have selected: "22.12_NRR_INSVC", "22.12_RESTART_FAILURE_INSVC".
Please confirm your selection. This action cannot be undone.

Signed-off-by: Enzo Candotti <enzo.candotti@windriver.com>
Change-Id: I85bc5c8155466e14a1a5fa84d54ed22032437f88
This commit is contained in:
Enzo Candotti 2022-12-30 18:06:03 -03:00
parent be6484350f
commit feb152c085
3 changed files with 73 additions and 3 deletions

View File

@ -0,0 +1,69 @@
From 25b0db5778a811c323e07958e03f33847eb7748d Mon Sep 17 00:00:00 2001
From: Enzo Candotti <enzo.candotti@windriver.com>
Date: Mon, 2 Jan 2023 13:24:07 -0300
Subject: [PATCH] Fix incomplete pop-up message on delete Action
When an Action table is created with a 'danger' action_type and a
single handler method for a single object, the 'selection' and
'help' parameters are empty. This causes the pop-up message to be
incomplete.
This patch fixes this behavior by displaying the message with
the selected objects only when one or more objects are selected.
Otherwise, it only asks for confirmation.
Signed-off-by: Enzo Candotti <enzo.candotti@windriver.com>
---
horizon/static/horizon/js/horizon.tables.js | 21 +++++++++++++------
.../horizon/client_side/_confirm.html | 2 +-
2 files changed, 16 insertions(+), 7 deletions(-)
diff --git a/horizon/static/horizon/js/horizon.tables.js b/horizon/static/horizon/js/horizon.tables.js
index 5f42784..b416f19 100644
--- a/horizon/static/horizon/js/horizon.tables.js
+++ b/horizon/static/horizon/js/horizon.tables.js
@@ -309,13 +309,22 @@ horizon.datatables.confirm = function(action) {
var title = interpolate(gettext("Confirm %s"), [action_string]);
// compose the action string using a template that can be overridden
- var template = horizon.templates.compiled_templates["#confirm_modal"],
- params = {
- selection: name_string,
- selection_list: name_array,
- help: help_text
- };
+ var template = horizon.templates.compiled_templates["#confirm_modal"]
+ if (name_string == "") {
+ params = {
+ selection_list: name_array,
+ help: 'This action cannot be undone.'
+ };
+
+ }
+ else {
+ params = {
+ selection: 'You have selected: ' + name_string + '.',
+ selection_list: name_array,
+ help: help_text
+ };
+ }
var body;
try {
body = $(template.render(params)).html();
diff --git a/horizon/templates/horizon/client_side/_confirm.html b/horizon/templates/horizon/client_side/_confirm.html
index f6642dd..31451f0 100644
--- a/horizon/templates/horizon/client_side/_confirm.html
+++ b/horizon/templates/horizon/client_side/_confirm.html
@@ -6,7 +6,7 @@
{% block template %}{% spaceless %}{% jstemplate %}
<div class="confirm-wrapper">
<span class="confirm-list" style="word-wrap: break-word; word-break: normal;">
- {% blocktrans %}You have selected: [[selection]]. {% endblocktrans %}
+ {% blocktrans %} [[selection]] {% endblocktrans %}
</span>
<span class="confirm-text">{% trans 'Please confirm your selection.'%} </span>
<span class="confirm-help">[[help]]</span>
--
2.25.1

View File

@ -1 +1,2 @@
0001-Use-policy_rules-for-user-role-assignment-and-group-tabs.patch 0001-Use-policy_rules-for-user-role-assignment-and-group-tabs.patch
0002-Fix-incomplete-pop-up-message-on-delete-Action.patch

View File

@ -17,7 +17,7 @@ setenv = VIRTUAL_ENV={envdir}
deps = -r{toxinidir}/test-requirements.txt deps = -r{toxinidir}/test-requirements.txt
[testenv:linters] [testenv:linters]
whitelist_externals = bash allowlist_externals = bash
commands = commands =
bash -c "find {toxinidir} \ bash -c "find {toxinidir} \
-not \( -type d -name .?\* -prune \) \ -not \( -type d -name .?\* -prune \) \
@ -61,7 +61,7 @@ deps = -r{toxinidir}/doc/requirements.txt
commands = commands =
rm -rf doc/build rm -rf doc/build
sphinx-build -a -E -W -d doc/build/doctrees -b html doc/source doc/build/html sphinx-build -a -E -W -d doc/build/doctrees -b html doc/source doc/build/html
whitelist_externals = rm allowlist_externals = rm
[testenv:releasenotes] [testenv:releasenotes]
basepython = python3 basepython = python3
@ -69,7 +69,7 @@ deps = -r{toxinidir}/doc/requirements.txt
commands = commands =
rm -rf releasenotes/build rm -rf releasenotes/build
sphinx-build -a -E -W -d releasenotes/build/doctrees -b html releasenotes/source releasenotes/build/html sphinx-build -a -E -W -d releasenotes/build/doctrees -b html releasenotes/source releasenotes/build/html
whitelist_externals = allowlist_externals =
rm rm
reno reno