From 14dc5eb7cca8a3c1c9d69ccfea3db808fcbf92fe Mon Sep 17 00:00:00 2001 From: alcatron <27321443+alcatron@users.noreply.github.com> Date: Wed, 18 Nov 2026 03:32:28 +1030 Subject: [PATCH] Add a preference for always-visible graph action icons (#8744) * Add optional always-visible graph action icons * Close visible graph submenus with Escape after Safari mouse clicks * Document graph action display preference (#8744) * Fix refreshed graph action labels and submenu stacking * Refresh realtime action names and repair browser test setup --- CHANGELOG | 1 + include/css/graph_drilldown.css | 43 +++++++ include/global_settings.php | 10 ++ include/layout.js | 33 ++++++ include/realtime.js | 1 + lib/html.php | 11 +- lib/html_graph.php | 4 +- locales/po/cacti.pot | 12 ++ .../Ui/Graph/GraphDrilldownMarkupTest.php | 2 +- tests/e2e/tests/graph-drilldown.spec.js | 2 +- tests/e2e/tests/graph-spikekill.spec.js | 2 +- tests/fixtures/Core/GraphDrilldownMarkup.php | 11 +- tests/fixtures/Core/HtmlGraphMarkup.php | 21 ++++ tests/js/develop_client_state.test.js | 3 + tests/js/graph_actions_display.test.js | 106 ++++++++++++++++++ 15 files changed, 253 insertions(+), 9 deletions(-) create mode 100644 tests/js/graph_actions_display.test.js diff --git a/CHANGELOG b/CHANGELOG index cd93e8fbae..8cfe30f60a 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -435,6 +435,7 @@ Cacti CHANGELOG -feature#7634: Add indexes for host-template and session lookup queries -feature#7681: Add fail2ban support with a stable authentication-failure log line and a bundled filter -feature#8281: Log user actions (create, delete, ...) +-feature#8744: Allow users to keep graph action icons visible beside graphs 1.2.32 -security#GHSA-fq9x-x3vf-3vf2: Substitute data-input field tokens in a single pass so a composed value cannot re-inject an escaped payload into the script command line diff --git a/include/css/graph_drilldown.css b/include/css/graph_drilldown.css index 6ce4bebf8e..a296a86962 100644 --- a/include/css/graph_drilldown.css +++ b/include/css/graph_drilldown.css @@ -134,3 +134,46 @@ text-align: center; vertical-align: middle; } + +/* Reserve space beside the graph for users who prefer direct actions. */ +.graphWrapperOuter > div:first-child:has(> .graphDrillDownAlways) { + display: flex; + align-items: flex-start; +} + +.graphWrapperOuter > div:first-child:has(> .graphDrillDownAlways) > .graphWrapper { + min-width: 0; +} + +.graphDrillDownAlways { + position: static; + z-index: auto; + display: block; + flex: 0 0 24px; + width: 24px; + min-width: 24px; + height: auto; + padding: 10px 3px; +} + +.graphDrillDownAlways .graphDrillDownMenu { + display: none; +} + +.graphDrillDownAlways .iconWrapper { + display: block; + visibility: visible; + opacity: 1; +} + +.graphDrillDownAlways .iconLink { + display: inline-block; + width: 24px; + line-height: 24px; + text-align: center; +} + +.graphDrillDownAlways .iconLink:focus-visible { + outline: 2px solid currentColor; + outline-offset: 1px; +} diff --git a/include/global_settings.php b/include/global_settings.php index c9a177bb30..39acf5320b 100644 --- a/include/global_settings.php +++ b/include/global_settings.php @@ -3173,6 +3173,16 @@ $settings_user = [ 'default' => read_config_option('selected_theme'), 'array' => $themes ], + 'graph_actions_display' => [ + 'friendly_name' => __('Graph Actions'), + 'description' => __('Show graph actions in a collapsed menu or as always-visible icons beside each graph.'), + 'method' => 'drop_array', + 'default' => 'menu', + 'array' => [ + 'menu' => __('Collapsed Menu'), + 'icons' => __('Always-visible Icons') + ] + ], 'default_view_mode' => [ 'friendly_name' => __('Default View Mode'), 'description' => __('Which Graph mode you want displayed by default when you first visit the Graphs page?'), diff --git a/include/layout.js b/include/layout.js index e90d0a3956..b544ad0921 100644 --- a/include/layout.js +++ b/include/layout.js @@ -940,6 +940,8 @@ function setupSelectmenuScrollClose() { * that can't be set using a live attribute 'on()' */ function applySkin() { + labelVisibleGraphActions(); + pageName = basename($(location).attr('pathname')); $('#messageContainer').remove(); @@ -4924,12 +4926,41 @@ function refreshGraphs() { }); } +function labelVisibleGraphActions() { + // Visible icons keep their tooltips and also expose names to assistive technology. + $('.graphDrillDownAlways .iconWrapper a').each(function () { + var link = $(this); + var currentLabel = link.attr('aria-label'); + var generatedLabel = link.attr('data-graph-action-label'); + if (currentLabel && currentLabel !== generatedLabel) { + return; + } + var label = link.attr('title') || link.find('i[title], img[title]').first().attr('title'); + if (label) { + link.attr('aria-label', label); + link.attr('data-graph-action-label', label); + } + }); +} + function initGraphDrilldown() { // Common graph drilldown behaviour for every theme (styled in graph_drilldown.css). // A hamburger glyph over the graph's top-right toggles the action icons; they // close on a second click, on moving off the graph image, or on an outside click. $(document).off('.graphdd'); + labelVisibleGraphActions(); + + $(document).on('keydown.graphdd', function (event) { + if (event.keyCode == 27 && typeof spikeKillClose == 'function' && typeof spikeKillAnchor != 'undefined' && spikeKillAnchor) { + var anchor = $(spikeKillAnchor); + if (anchor.closest('.graphDrillDownAlways').length) { + spikeKillClose(); + anchor.trigger('focus'); + } + } + }); + function closeGraphDrilldown(container) { container.removeClass('open'); container.closest('.graphWrapperOuter').removeClass('graphDrillActive'); @@ -5334,6 +5365,7 @@ function initializeGraphs(disable_cache) { if (realtimeArray[graph_id]) { $('#wrapper_' + graph_id).html(keepRealtime[graph_id]).trigger('change'); $(this).html(""); + labelVisibleGraphActions(); $('graph_id' + graph_id).tooltip().zoom({ inputfieldStartTime: 'date1', @@ -5346,6 +5378,7 @@ function initializeGraphs(disable_cache) { } else { keepRealtime[graph_id] = $('#wrapper_' + graph_id).html(); $(this).html(""); + labelVisibleGraphActions(); $(this).find('i').tooltip(); realtimeArray[graph_id] = true; setFilters(); diff --git a/include/realtime.js b/include/realtime.js index ae21fadece..f9630ee2f7 100644 --- a/include/realtime.js +++ b/include/realtime.js @@ -196,6 +196,7 @@ function stopRealtime() { realtimeArray[graph_id] = false; } + labelVisibleGraphActions(); setFilters(); tuneFilter(); } diff --git a/lib/html.php b/lib/html.php index ed178251a3..459e9f9eff 100644 --- a/lib/html.php +++ b/lib/html.php @@ -400,7 +400,7 @@ function html_graph_area(array &$graph_array, string $no_graphs_message = '', st