From 26a2ddc5d7212bc9910d800f5eb0c32e775000fc Mon Sep 17 00:00:00 2001 From: mikemikimike <13286568797@163.com> Date: Mon, 14 Sep 2026 22:05:57 +0800 Subject: [PATCH] Fix agent delete confirmation target --- web/htdocs/js/lib.js | 9 +++++++++ web/htdocs/js/shield.js | 4 +++- web/test/tests.js | 13 +++++++++++++ 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/web/htdocs/js/lib.js b/web/htdocs/js/lib.js index 405d69813..ce8bd1cdd 100644 --- a/web/htdocs/js/lib.js +++ b/web/htdocs/js/lib.js @@ -34,6 +34,15 @@ return ok }; + exported.agentByUUID = function (agents, uuid) { + for (var i = 0; i < agents.length; i++) { + if (agents[i].uuid == uuid) { + return agents[i]; + } + } + return undefined; + }; + /*************************************************** pluralize(n, word [, words]) - Pluralize a number + unit. diff --git a/web/htdocs/js/shield.js b/web/htdocs/js/shield.js index de9b63307..4349e6a7d 100644 --- a/web/htdocs/js/shield.js +++ b/web/htdocs/js/shield.js @@ -714,7 +714,9 @@ function dispatch(page) { }); } else if (action == 'delete') { var agent_uuid = $(event.target).extract('agent-uuid'); - modal($($.template('agents-delete', { agent: data.agents[0] })) + modal($($.template('agents-delete', { + agent: agentByUUID(data.agents, agent_uuid) + })) .on('click', '[rel="yes"]', function (event) { event.preventDefault(); api({ diff --git a/web/test/tests.js b/web/test/tests.js index be6f4468a..e28d5eb02 100644 --- a/web/test/tests.js +++ b/web/test/tests.js @@ -75,6 +75,19 @@ QUnit.assert.any = function (actual, expected, message) { }); }; +QUnit.module('Agent UI Helpers'); +QUnit.test('agentByUUID selects the clicked agent', function (is) { + var agents = [ + { uuid: 'first-agent', name: 'First' }, + { uuid: 'second-agent', name: 'Second' } + ]; + + is.equal(agentByUUID(agents, 'second-agent').name, 'Second', + 'the confirmation modal receives the clicked agent'); + is.strictEqual(agentByUUID(agents, 'missing-agent'), undefined, + 'an unknown UUID does not select another agent'); +}); + QUnit.module('AEGIS Data Operations'); QUnit.test('Basic Operations', function(is) { var thing, db = $.aegis();