issue: shorten thold VRULE graph drilldown button title (#855)

* issue: shorten thold VRULE graph drilldown button title

The graph action menu now renders each drilldown button's title as a visible label, so 'Toggle Threshold VRULES %s' reads as an overlong menu entry. Shorten it to 'Toggle VRULES %s', add a unit test exercising thold_graph_button()'s VRULE branch (with the two missing request-var stubs it needs) so the changed line stays covered, and regenerate locales/po/cacti.pot.

* Update copyright notice in TholdGraphButtonTest.php

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

* Fix Last-Translator entry in cacti.pot

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

* test: cover the VRULEs-enabled 'Off' title branch for patch coverage

---------

Co-authored-by: TheWitness <1439914+TheWitness@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
authored and GitHub committed 2026-10-13 12:38:48 -04:00
1 parent 2de8e1c7eb
commit 10c93541dd
5 files changed
+106 -9

No files matched your search

+1
View File
@@ -1,6 +1,7 @@
## ChangeLog
--- develop ---
* issue: Shorten the VRULE graph drilldown button title so it reads cleanly as a label in Cacti's graph action menu, using two complete 'Toggle Threshold VRULES On'/'Off' strings (keeping the Threshold reference) so the label stays grammatical across translations
* issue: Log each template import error using its own message (#757)
* bug: Element-qualify the `.thold-pill` CSS so it outranks the single-class theme rules (e.g. `.deviceUpFull` `width:14%`) that were clipping the pill to a fixed width; status pills now size to their label on the Device Status page and everywhere else
* feature: Clicking an already-selected status pill now clears that filter (resets to All) instead of re-applying it, on the Thresholds, Device Status and Threshold Log sub-tabs
+3 -8
View File
@@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: Cacti \n"
"Report-Msgid-Bugs-To: developers@cacti.net\n"
"POT-Creation-Date: 2026-10-08 16:02-0400\n"
"POT-Creation-Date: 2026-10-13 09:23-0400\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: Cacti Developers <developers@cacti.net>\n"
"Language-Team: Cacti Developers <developers@cacti.net>\n"
@@ -2216,16 +2216,11 @@ msgid "No Notifications"
msgstr ""
#: setup.php
msgid "Off"
msgid "Toggle Threshold VRULES Off"
msgstr ""
#: setup.php
msgid "On"
msgstr ""
#: setup.php
#, php-format
msgid "Toggle Threshold VRULES %s"
msgid "Toggle Threshold VRULES On"
msgstr ""
#: setup.php
+9 -1
View File
@@ -344,7 +344,15 @@ function thold_graph_button($data) {
}
if (api_user_realm_auth('thold_graph.php') && !empty($thold_id)) {
print '<a class="iconLink tholdVRule" href="' . html_escape($url . $separator . 'thold_vrule=' . $vrules) . '" title="' . __esc('Toggle Threshold VRULES %s', ($vrules == 'on' ? __('Off') : __('On')), 'thold') . '"><i class="tholdVRules far fa-chart-bar"></i></a><br>';
// Two complete strings rather than a trailing On/Off fragment so the
// label stays grammatical when a translation reorders the words.
if ($vrules == 'on') {
$vrule_title = __esc('Toggle Threshold VRULES Off', 'thold');
} else {
$vrule_title = __esc('Toggle Threshold VRULES On', 'thold');
}
print '<a class="iconLink tholdVRule" href="' . html_escape($url . $separator . 'thold_vrule=' . $vrules) . '" title="' . $vrule_title . '"><i class="tholdVRules far fa-chart-bar"></i></a><br>';
}
// Add Threshold Creation button
+81
View File
@@ -0,0 +1,81 @@
<?php
/*
+-------------------------------------------------------------------------+
| Copyright (C) 2004-2026 The Cacti Group |
| |
| This program is free software; you can redistribute it and/or |
| modify it under the terms of the GNU General Public License |
| as published by the Free Software Foundation; either version 2 |
| of the License, or (at your option) any later version. |
+-------------------------------------------------------------------------+
| Cacti: The Complete RRDtool-based Graphing Solution |
+-------------------------------------------------------------------------+
| http://www.cacti.net/ |
+-------------------------------------------------------------------------+
*/
/**
* thold_graph_button() renders this plugin's graph-page drilldown action
* icons. This covers the VRULE toggle button's markup, including the
* 'Toggle Threshold VRULES On'/'Off' title that shows as a label in Cacti's
* graph action menu.
*/
final class TholdGraphButtonTest extends TestCase {
/**
* @return void
*/
public static function setUpBeforeClass(): void {
self::loadPluginSource('setup.php');
}
/**
* @return void
*/
protected function setUp(): void {
parent::setUp();
CactiStubs::reset();
}
/**
* @return void
*/
public function test_it_prints_the_vrule_button_with_the_shortened_title(): void {
// A threshold exists for the graph, so the VRULE toggle is shown; the
// aggregate lookup returns a row so the Create Threshold branch is skipped.
CactiStubs::willReturnFor('db_fetch_cell_prepared', 'thold_data', 123);
CactiStubs::willReturnFor('db_fetch_cell_prepared', 'aggregate_graphs', 5);
$_SERVER['REQUEST_URI'] = '/cacti/graph_view.php?action=preview';
$_SESSION = [];
ob_start();
thold_graph_button([1 => ['local_graph_id' => 10, 'rra' => 5]]);
$html = ob_get_clean();
$this->assertStringContainsString('iconLink tholdVRule', $html);
$this->assertStringContainsString('tholdVRules far fa-chart-bar', $html);
// Default state (no session/request var) resolves to the 'On' action and
// keeps the Thold-specific 'Threshold' reference.
$this->assertStringContainsString('Toggle Threshold VRULES On', $html);
$this->assertStringNotContainsString('Toggle VRULES', $html);
}
/**
* @return void
*/
public function test_it_shows_the_off_title_when_vrules_are_enabled(): void {
CactiStubs::willReturnFor('db_fetch_cell_prepared', 'thold_data', 123);
CactiStubs::willReturnFor('db_fetch_cell_prepared', 'aggregate_graphs', 5);
$_SERVER['REQUEST_URI'] = '/cacti/graph_view.php?action=preview';
// VRULEs already drawing (session on) resolves to the 'Off' action title.
$_SESSION = ['sess_config_array' => ['thold_draw_vrules' => 'on']];
ob_start();
thold_graph_button([1 => ['local_graph_id' => 10, 'rra' => 5]]);
$html = ob_get_clean();
$this->assertStringContainsString('Toggle Threshold VRULES Off', $html);
}
}
+12
View File
@@ -384,6 +384,18 @@ if (!function_exists('isset_request_var')) {
}
}
if (!function_exists('isempty_request_var')) {
function isempty_request_var($name) {
return !isset(CactiStubs::$requestVars[$name]) || CactiStubs::$requestVars[$name] === '';
}
}
if (!function_exists('set_request_var')) {
function set_request_var($name, $value) {
CactiStubs::$requestVars[$name] = $value;
}
}
if (!function_exists('cacti_escapeshellarg')) {
function cacti_escapeshellarg($string, $quote = true) {
return escapeshellarg((string) $string);