fix(account): keep Unclaim and Unlink disabled until the list reloads (#2440)

Follow-up to #2430, covering the two points from @efiten's re-review.

- **Unclaim and Unlink stay disabled until the list reloads.** Both
click handlers now return the list reload from the DELETE's `.then`
(`public/account.js`), so the button is re-enabled only after the
redrawn list has replaced it. Before, a click between the DELETE's
answer and the list GET's answer sent a second DELETE.
- **The dropped-from-node-list note shows in every state.**
`repeaterHealth` adds "no longer in the node list" whenever `r.inactive`
is set, so an inactive repeater that was heard recently or whose prefix
still relays is marked too, not only a silent one.

Tests (`tests/unit/test-user-management-ui.js`, 103/103):
- For both Unclaim and Unlink, the button stays disabled while the list
GET after the DELETE is pending, and a click in that window sends no
second DELETE.
- An inactive repeater carries the note when active, uncertain, stale
and never heard, and none of those rows links to a node page.

`tests/e2e/test-lint-network-calls.js` 47/47.

Co-authored-by: Adam <196335+anieto@users.noreply.github.com>
This commit is contained in:
AdamandAdam authored and GitHub committed 2026-11-21 22:26:28 +01:00
1 parent 9a57b2fca6
commit 01d2bbbbfd
2 files changed
+63 -5

No files matched your search

+10 -5
View File
@@ -169,7 +169,14 @@
// use (getNodeStatus from roles.js: silent past the repeater threshold is
// stale; a silent one whose prefix still relays is uncertain). fns carries
// getNodeStatus and timeAgo so tests can pass the real ones in.
// An inactive repeater (retention dropped it from the node list, which is
// also why its row has no node page to link to) says so in every state.
function repeaterHealth(r, fns) {
var h = repeaterHealthBase(r, fns);
if (r.inactive && r.known) h.text += ' · no longer in the node list';
return h;
}
function repeaterHealthBase(r, fns) {
if (!r.known) return { state: 'gone', rank: 0, text: 'no longer in the database' };
if (!r.lastHeard) return { state: 'stale', rank: 1, text: 'never heard' };
var node = { role: r.role || 'repeater', last_heard: r.lastHeard, last_relayed: r.lastRelayed || null };
@@ -177,9 +184,7 @@
var when = fns.timeAgo(r.lastHeard);
if (state === 'active') return { state: state, rank: 3, text: 'heard ' + when };
if (state === 'uncertain') return { state: state, rank: 2, text: 'last heard ' + when + ', its prefix still relays' };
// inactive: retention dropped it from the node list, which is also why
// its row has no node page to link to.
return { state: 'stale', rank: 1, text: 'silent, last heard ' + when + (r.inactive ? ' · no longer in the node list' : '') };
return { state: 'stale', rank: 1, text: 'silent, last heard ' + when };
}
var HEALTH_CHIP = { active: 'um-status-active', uncertain: 'um-status-pending', stale: 'um-status-disabled', gone: 'um-chip-unsubscribed' };
@@ -508,7 +513,7 @@
btn.disabled = true; // a second click while the DELETE runs would 404 over the success message
return CSAuth.request('DELETE', '/api/account/companions/' + encodeURIComponent(pk)).then(function (r) {
CSAuth.say('compMsg', r.ok ? 'Companion unlinked.' : CSAuth.errText(r), r.ok);
loadCompanions();
return loadCompanions(); // the button stays disabled until the list is redrawn
}).catch(function () { CSAuth.say('compMsg', 'Network error, try again.', false); })
.then(function () { btn.disabled = false; });
});
@@ -530,7 +535,7 @@
btn.disabled = true; // a second click while the DELETE runs would 404 over the success message
return CSAuth.request('DELETE', '/api/repeaters/' + encodeURIComponent(pk) + '/claim').then(function (r) {
CSAuth.say('myRepMsg', r.ok ? 'Repeater unclaimed.' : CSAuth.errText(r), r.ok);
loadMyRepeaters();
return loadMyRepeaters(); // the button stays disabled until the list is redrawn
}).catch(function () { CSAuth.say('myRepMsg', 'Network error, try again.', false); })
.then(function () { btn.disabled = false; });
});
+53
View File
@@ -510,6 +510,59 @@ test('my repeaters: Unclaim is disabled while its DELETE runs, so a double click
assert.strictEqual(btn.disabled, false, 'button stays disabled after the DELETE');
});
// Unclaim and Unlink keep their button disabled until the list GET after the
// DELETE has answered: the old button is still on screen until then.
for (const c of [
{ name: 'Unclaim', list: 'myRepList', msg: 'myRepMsg', attr: 'data-unclaim', get: '/api/account/repeaters',
empty: { repeaters: [] }, done: 'Repeater unclaimed.' },
{ name: 'Unlink', list: 'compList', msg: 'compMsg', attr: 'data-unlink', get: '/api/account/companions',
empty: [], done: 'Companion unlinked.' }]) {
test(c.name + ' stays disabled until the reloaded list is in', async () => {
const pk = 'ab'.repeat(32);
let releaseList = null;
let deleted = false;
const env = loadAccount('#/account', () => ({ ok: true, status: 200, data: c.empty }), { confirm: () => true });
env.setRequest((method, p) => {
if (method === 'DELETE') { deleted = true; return Promise.resolve({ ok: true, status: 200, data: {} }); }
if (p === c.get && deleted) return new Promise((r) => { releaseList = () => r({ ok: true, status: 200, data: c.empty }); });
if (p === c.get) return Promise.resolve({ ok: true, status: 200, data: c.empty });
return Promise.resolve({ ok: true, status: 200, data: [] });
});
env.user.current = { id: 1, email: 'a@b.c', displayName: 'Ann', role: 'user' };
env.t.views.profile({ set innerHTML(v) {} });
await new Promise((r) => setTimeout(r, 5));
const btn = { getAttribute: (a) => (a === c.attr ? pk : null) };
const first = env.els[c.list].handlers.click({ target: btn });
await new Promise((r) => setTimeout(r, 5));
assert(releaseList, 'list not reloaded after the DELETE');
assert.strictEqual(env.els[c.msg].textContent, c.done);
assert.strictEqual(btn.disabled, true, 'button enabled again while the list GET runs');
env.els[c.list].handlers.click({ target: btn });
assert.strictEqual(env.calls.filter((x) => x.method === 'DELETE').length, 1, 'a click before the reload sent another DELETE');
releaseList();
await first;
assert.strictEqual(btn.disabled, false, 'button stays disabled after the reload');
});
}
test('an inactive repeater carries the dropped note in every health state', () => {
const env = loadAccount('#/account', () => ({}));
const fns = { getNodeStatus: realGetNodeStatus(), timeAgo: () => 'AGO' };
const recent = new Date(Date.now() - 3600 * 1000).toISOString();
const old = new Date(Date.now() - 10 * 86400 * 1000).toISOString();
const base = { known: true, inactive: true, role: 'repeater', name: 'X', claimedAt: '2026-11-01T00:00:00Z', status: null, comaintainers: [] };
const h = env.t.myRepeatersHtml([
Object.assign({ pubkey: '11'.repeat(32), lastHeard: recent }, base),
Object.assign({ pubkey: '22'.repeat(32), lastHeard: old, lastRelayed: recent }, base),
Object.assign({ pubkey: '33'.repeat(32), lastHeard: old }, base),
Object.assign({ pubkey: '44'.repeat(32), lastHeard: null }, base)], fns);
for (const [pk, state] of [['11', 'active'], ['22', 'uncertain'], ['33', 'stale'], ['44', 'stale']]) {
assert(h.indexOf('data-pubkey="' + pk.repeat(32) + '" data-health="' + state + '"') !== -1, pk + ' not ' + state + ': ' + h);
}
assert.strictEqual((h.match(/no longer in the node list/g) || []).length, 4, 'note missing on a state: ' + h);
assert.strictEqual((h.match(/href="#\/nodes\//g) || []).length, 0, 'inactive row links to a node page');
});
test('my repeaters empty state explains how to claim', () => {
const env = loadAccount('#/account', () => ({}));
for (const list of [[], null, undefined]) {