Skip to content

Commit 9c98eba

Browse files
committed
fix(ui): A2A agent list now refreshes correctly after deletion
Signed-off-by: Rakhi Dutta <rakhibiswas@yahoo.com>
1 parent 67e63ea commit 9c98eba

File tree

2 files changed

+43
-4
lines changed

2 files changed

+43
-4
lines changed

mcpgateway/admin_ui/formHandlers.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { TOGGLE_FRAGMENT_MAP } from "./constants.js";
1+
import { PANEL_SEARCH_CONFIG, TOGGLE_FRAGMENT_MAP } from "./constants.js";
22
import { navigateAdmin } from "./navigation.js";
33
import { getCookie, isInactiveChecked } from "./utils.js";
44

@@ -48,12 +48,14 @@ export const handleToggleSubmit = async function (event, type) {
4848
}
4949

5050
// Trigger HTMX request to refresh the table
51-
const tableId = `${type}-table`;
52-
const partialUrl = `${window.ROOT_PATH}/admin/${type}/partial?${params.toString()}`;
51+
const panelConfig = PANEL_SEARCH_CONFIG[type];
52+
const partialPath = panelConfig?.partialPath || `${type}/partial`;
53+
const targetSelector = panelConfig?.targetSelector || `#${type}-table`;
54+
const partialUrl = `${window.ROOT_PATH}/admin/${partialPath}?${params.toString()}`;
5355

5456
if (window.htmx) {
5557
window.htmx.ajax('GET', partialUrl, {
56-
target: `#${tableId}`,
58+
target: targetSelector,
5759
swap: 'outerHTML'
5860
});
5961
} else {

tests/unit/js/formHandlers.test.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,4 +241,41 @@ describe("handleDeleteSubmit", () => {
241241

242242
expect(capturedFormData.get("is_inactive_checked")).toBe("true");
243243
});
244+
245+
test("uses PANEL_SEARCH_CONFIG for A2A agents refresh (partialPath and targetSelector)", async () => {
246+
const form = document.createElement("form");
247+
form.id = "test-form";
248+
form.action = "/test";
249+
document.body.appendChild(form);
250+
251+
const tableDiv = document.createElement("div");
252+
tableDiv.id = "agents-table"; // Correct ID per PANEL_SEARCH_CONFIG
253+
document.body.appendChild(tableDiv);
254+
255+
const fetchMock = vi.fn().mockResolvedValue({ ok: true });
256+
global.fetch = fetchMock;
257+
258+
// Mock HTMX
259+
const htmxAjaxMock = vi.fn();
260+
global.window.htmx = { ajax: htmxAjaxMock };
261+
global.window.ROOT_PATH = "";
262+
263+
const event = { preventDefault: vi.fn(), target: form };
264+
265+
vi.spyOn(window, "confirm")
266+
.mockReturnValueOnce(true)
267+
.mockReturnValueOnce(false);
268+
269+
await handleDeleteSubmit(event, "agent", "test-agent", "a2a-agents");
270+
271+
// Verify HTMX was called with correct partial path (a2a/partial) and target selector (#agents-table)
272+
expect(htmxAjaxMock).toHaveBeenCalledWith(
273+
'GET',
274+
expect.stringContaining('/admin/a2a/partial'),
275+
expect.objectContaining({
276+
target: '#agents-table', // targetSelector from PANEL_SEARCH_CONFIG, not #a2a-agents-table
277+
swap: 'outerHTML'
278+
})
279+
);
280+
});
244281
});

0 commit comments

Comments
 (0)