Home tiles read each module's stats contract; drop Compass's contract tiles

Since the split every module answers GET /api/v1/stats (dredd-core 0.23.0). The home screen asks
that first and falls back to the old dashboard mapping only for a module without it. Compass's
mapping (contracts, analyses, registry) pointed at routes that no longer exist.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-14 10:46:40 +01:00
co-authored by Claude Opus 5.5
parent 91c83ce233
commit 1ed348d2bd
+18 -13
View File
@@ -4073,28 +4073,33 @@ const MODULE_STATS = {
{ label: 'Otwarte szkice', value: (d.cards || {}).open_drafts, inner: 'drafts' },
{ label: 'Projekty', value: (d.cards || {}).projects, inner: '' },
],
compass: (d) => {
const c = d.cards || {}, r = d.registry || {};
return [
{ label: 'Czeka na mnie', value: c.waiting_for_me, inner: 'contracts', warn: c.waiting_for_me > 0 },
{ label: 'Do podpisu prawnika', value: c.awaiting_signoff, inner: 'analyses' },
{ label: 'Wygasa w 60 dni', value: r.expiring_60, inner: 'contracts?expiring_within=60', warn: r.expiring_7 > 0 },
{ label: 'Obowiązujące umowy', value: r.in_force, inner: 'contracts' },
];
},
};
async function loadModuleStats() {
const mods = state.launcher.filter((m) => m.has_access && embeddable(m) && MODULE_STATS[m.slug]);
const mods = state.launcher.filter((m) => m.has_access && embeddable(m));
if (!mods.length) return;
const got = await Promise.all(mods.map(async (m) => {
const ctl = new AbortController();
const t = setTimeout(() => ctl.abort(), 4000);
try {
const base = new URL('api/v1/', m.url.replace(/\/?$/, '/')).pathname;
const r = await fetch(base + 'dashboard', { credentials: 'same-origin', headers: { Accept: 'application/json' }, signal: ctl.signal });
if (!r.ok) return null;
const tiles = MODULE_STATS[m.slug](await r.json()).filter((x) => x.value !== undefined && x.value !== null);
const opts = { credentials: 'same-origin', headers: { Accept: 'application/json' }, signal: ctl.signal };
// dredd-core's stats contract first (every module since the Compass split): tiles counted for
// the caller, each equal to the list its link opens. A module without it falls back to the
// dashboard mapping above, if it has one.
let tiles = null;
const st = await fetch(base + 'stats', opts);
if (st.ok) {
const d = await st.json();
if (d && Array.isArray(d.tiles)) tiles = d.tiles.map((x) => ({ label: x.label, value: x.count, inner: x.link }));
}
if (!tiles && MODULE_STATS[m.slug]) {
const r = await fetch(base + 'dashboard', opts);
if (!r.ok) return null;
tiles = MODULE_STATS[m.slug](await r.json());
}
if (!tiles) return null;
tiles = tiles.filter((x) => x.value !== undefined && x.value !== null);
return tiles.length ? { m, tiles } : null;
} catch { return null; } finally { clearTimeout(t); }
}));