fix(admin-ui): keep dashboard totals from stats summary
Fetch stats summary first and tolerate trend/recurrence failures with Promise.allSettled so KPI totals no longer fall back to the 500-row incidents list cap.
This commit is contained in:
1 parent
5fede9ddd9
commit
228d97db78
1 file changed
+27
-4
@@ -127,21 +127,44 @@ export function aggregateIncidentKpisFromSummary(
|
||||
|
||||
export async function fetchOperationalStats(): Promise<OperationalStatsResult> {
|
||||
if (!_apiBase()) {
|
||||
return { ok: false, message: "API não configurada." };
|
||||
return { ok: false, message: "API nao configurada." };
|
||||
}
|
||||
|
||||
try {
|
||||
const [summary, trendDay, trendHour, recurrence] = await Promise.all([
|
||||
_fetchJson<StatsSummaryPayload>("/v1/stats/summary"),
|
||||
const summary = await _fetchJson<StatsSummaryPayload>("/v1/stats/summary");
|
||||
|
||||
const [trendDayRes, trendHourRes, recurrenceRes] = await Promise.allSettled([
|
||||
_fetchJson<TrendDayPayload>("/v1/stats/trend?granularity=day&days=14"),
|
||||
_fetchJson<TrendHourPayload>("/v1/stats/trend?granularity=hour&hours=24"),
|
||||
_fetchJson<RecurrencePayload>("/v1/stats/recurrence?days=7&limit=12"),
|
||||
]);
|
||||
|
||||
const trendDay: TrendDayPayload =
|
||||
trendDayRes.status === "fulfilled"
|
||||
? trendDayRes.value
|
||||
: { granularity: "day", dates: [], series: {} };
|
||||
|
||||
const trendHour: TrendHourPayload =
|
||||
trendHourRes.status === "fulfilled"
|
||||
? trendHourRes.value
|
||||
: { granularity: "hour", hours: [], series: {} };
|
||||
|
||||
const recurrence: RecurrencePayload =
|
||||
recurrenceRes.status === "fulfilled"
|
||||
? recurrenceRes.value
|
||||
: {
|
||||
windowDays: 7,
|
||||
rangeStart: "",
|
||||
rangeEndExclusive: "",
|
||||
top: [],
|
||||
};
|
||||
|
||||
return { ok: true, summary, trendDay, trendHour, recurrence };
|
||||
} catch (_e) {
|
||||
const _msg = _e instanceof Error ? _e.message : "fetch failed";
|
||||
return {
|
||||
ok: false,
|
||||
message: `Não foi possível carregar estatísticas (${_msg}).`,
|
||||
message: `Nao foi possivel carregar estatisticas (${_msg}).`,
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user