Skip to content

Commit d015a00

Browse files
committed
fix(ui): apply Select All count display consistently across all init*Select functions
Extend the Select All button count fix from initToolSelect to initResourceSelect, initPromptSelect, and initGatewaySelect for consistency. Remove stale originalText + setTimeout pattern from all three sibling functions. Update Playwright assertions to match new button text format and add JS unit tests for count display behavior. Closes #3833 Signed-off-by: Mihai Criveti <crivetimihai@gmail.com>
1 parent eb26bb6 commit d015a00

3 files changed

Lines changed: 327 additions & 31 deletions

File tree

mcpgateway/static/admin.js

Lines changed: 41 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10316,6 +10316,18 @@ function initResourceSelect(
1031610316
} else {
1031710317
warnBox.textContent = "";
1031810318
}
10319+
10320+
// Update the Select All button text to show count
10321+
if (selectBtnId) {
10322+
const currentSelectBtn = document.getElementById(selectBtnId);
10323+
if (currentSelectBtn) {
10324+
if (count > 0) {
10325+
currentSelectBtn.textContent = `Select All (${count})`;
10326+
} else {
10327+
currentSelectBtn.textContent = "Select All";
10328+
}
10329+
}
10330+
}
1031910331
} catch (error) {
1032010332
console.error("Error updating resource select:", error);
1032110333
}
@@ -10362,7 +10374,6 @@ function initResourceSelect(
1036210374
selectBtn.parentNode.replaceChild(newSelectBtn, selectBtn);
1036310375

1036410376
newSelectBtn.addEventListener("click", async () => {
10365-
const originalText = newSelectBtn.textContent;
1036610377
newSelectBtn.disabled = true;
1036710378
newSelectBtn.textContent = "Selecting all resources...";
1036810379

@@ -10445,14 +10456,11 @@ function initResourceSelect(
1044510456
allIds.forEach((id) => editSel.add(String(id)));
1044610457

1044710458
update();
10448-
10449-
newSelectBtn.textContent = `✓ All ${allIds.length} resources selected`;
10450-
setTimeout(() => {
10451-
newSelectBtn.textContent = originalText;
10452-
}, 2000);
1045310459
} catch (error) {
1045410460
console.error("Error selecting all resources:", error);
1045510461
alert("Failed to select all resources. Please try again.");
10462+
newSelectBtn.disabled = false;
10463+
update(); // Reset button text via update()
1045610464
} finally {
1045710465
newSelectBtn.disabled = false;
1045810466
}
@@ -10731,6 +10739,18 @@ function initPromptSelect(
1073110739
} else {
1073210740
warnBox.textContent = "";
1073310741
}
10742+
10743+
// Update the Select All button text to show count
10744+
if (selectBtnId) {
10745+
const currentSelectBtn = document.getElementById(selectBtnId);
10746+
if (currentSelectBtn) {
10747+
if (count > 0) {
10748+
currentSelectBtn.textContent = `Select All (${count})`;
10749+
} else {
10750+
currentSelectBtn.textContent = "Select All";
10751+
}
10752+
}
10753+
}
1073410754
} catch (error) {
1073510755
console.error("Error updating prompt select:", error);
1073610756
}
@@ -10776,7 +10796,6 @@ function initPromptSelect(
1077610796
newSelectBtn.dataset.listenerAttached = "true";
1077710797
selectBtn.parentNode.replaceChild(newSelectBtn, selectBtn);
1077810798
newSelectBtn.addEventListener("click", async () => {
10779-
const originalText = newSelectBtn.textContent;
1078010799
newSelectBtn.disabled = true;
1078110800
newSelectBtn.textContent = "Selecting all prompts...";
1078210801

@@ -10859,14 +10878,11 @@ function initPromptSelect(
1085910878
allIds.forEach((id) => editSel.add(String(id)));
1086010879

1086110880
update();
10862-
10863-
newSelectBtn.textContent = `✓ All ${allIds.length} prompts selected`;
10864-
setTimeout(() => {
10865-
newSelectBtn.textContent = originalText;
10866-
}, 2000);
1086710881
} catch (error) {
1086810882
console.error("Error selecting all prompts:", error);
1086910883
alert("Failed to select all prompts. Please try again.");
10884+
newSelectBtn.disabled = false;
10885+
update(); // Reset button text via update()
1087010886
} finally {
1087110887
newSelectBtn.disabled = false;
1087210888
}
@@ -11125,6 +11141,18 @@ function initGatewaySelect(
1112511141
} else {
1112611142
warnBox.textContent = "";
1112711143
}
11144+
11145+
// Update the Select All button text to show count
11146+
if (selectBtnId) {
11147+
const currentSelectBtn = document.getElementById(selectBtnId);
11148+
if (currentSelectBtn) {
11149+
if (count > 0) {
11150+
currentSelectBtn.textContent = `Select All (${count})`;
11151+
} else {
11152+
currentSelectBtn.textContent = "Select All";
11153+
}
11154+
}
11155+
}
1112811156
} catch (error) {
1112911157
console.error("Error updating gateway select:", error);
1113011158
}
@@ -11172,7 +11200,6 @@ function initGatewaySelect(
1117211200

1117311201
newSelectBtn.addEventListener("click", async () => {
1117411202
// Disable button and show loading state
11175-
const originalText = newSelectBtn.textContent;
1117611203
newSelectBtn.disabled = true;
1117711204
newSelectBtn.textContent = "Selecting all gateways...";
1117811205

@@ -11265,18 +11292,13 @@ function initGatewaySelect(
1126511292

1126611293
update();
1126711294

11268-
newSelectBtn.textContent = `✓ All ${allGatewayIds.length} gateways selected`;
11269-
setTimeout(() => {
11270-
newSelectBtn.textContent = originalText;
11271-
}, 2000);
11272-
1127311295
// Reload associated items after selecting all
1127411296
reloadAssociatedItems();
1127511297
} catch (error) {
1127611298
console.error("Error in Select All:", error);
1127711299
alert("Failed to select all gateways. Please try again.");
1127811300
newSelectBtn.disabled = false;
11279-
newSelectBtn.textContent = originalText;
11301+
update(); // Reset button text via update()
1128011302
} finally {
1128111303
newSelectBtn.disabled = false;
1128211304
}

0 commit comments

Comments
 (0)