forked from code/member-dashboard
keys chart: chart the keys that HAVE usage, not the ones with metadata
The first cut built a row per key in the metadata list and attached usage to it. Live, an account with three keys that had spent real money (homebot $11.84, office-pi $0.19, base-pi $0.19) came back with an EMPTY key list and four usage rows, so the chart drew one bar — the chat key — and quietly dropped the rest. Exactly the kind of "listing" this chart exists to compare. Now the usage rows are the authoritative set: every row gets a bar, metadata is attached when we have it, and a key with no usage still gets a zero row so a key you own is never invisible. The harness pins all three cases.
This commit is contained in:
1 parent
ffd42a2045
commit
b5b0703f0c
2 files changed
+121
-5
No files matched your search
+25
-5
@@ -1681,14 +1681,34 @@ function renderKeys(keys, keySpend) {
|
||||
const el = $('keys');
|
||||
keys = keys || []; keySpend = keySpend || [];
|
||||
keyRowsData = { keys: keys, spend: keySpend };
|
||||
const rows = keys.map(k => {
|
||||
const s = keySpend.find(x => !x.is_chat && x.name === k.name) || {};
|
||||
return {
|
||||
// One row per key that HAS usage, not per key in the metadata list: the usage
|
||||
// rows are the authoritative set (a live account had three keys with spend and
|
||||
// an empty key list, so charting only the intersection showed one bar out of
|
||||
// four). Metadata is attached when we have it; keys without usage still get a
|
||||
// row, so a key you own is never invisible.
|
||||
const metaFor = {};
|
||||
keys.forEach(k => { metaFor[k.name] = k; });
|
||||
const rows = [];
|
||||
const seen = {};
|
||||
keySpend.forEach(sp => {
|
||||
if (sp.is_chat) return;
|
||||
seen[sp.name] = true;
|
||||
const k = metaFor[sp.name] || {};
|
||||
rows.push({
|
||||
name: sp.name, chat: false,
|
||||
meta: (k.created_at ? 'created ' + k.created_at.slice(0, 10) : '') +
|
||||
(k.fingerprint ? ' · ends …' + k.fingerprint : ''),
|
||||
spend: Number(sp.spend) || 0, requests: Number(sp.requests) || 0
|
||||
});
|
||||
});
|
||||
keys.forEach(k => {
|
||||
if (seen[k.name]) return;
|
||||
rows.push({
|
||||
name: k.name, chat: false,
|
||||
meta: (k.created_at ? 'created ' + k.created_at.slice(0, 10) : '') +
|
||||
(k.fingerprint ? ' · ends …' + k.fingerprint : ''),
|
||||
spend: Number(s.spend) || 0, requests: Number(s.requests) || 0
|
||||
};
|
||||
spend: 0, requests: 0
|
||||
});
|
||||
});
|
||||
const chat = keySpend.find(x => x.is_chat);
|
||||
if (chat) {
|
||||
|
||||
Reference in new issue
Block a user