One-time `prettier --write` across the 22 source files not already touched
by the preceding tooling commit (b5ceedc). Pure formatting — no behaviour
change, no logic change. Reviewable as "all whitespace/reflow".
From here the lint-staged pre-commit hook keeps new and edited code
consistent automatically.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
58 lines
1.9 KiB
TypeScript
58 lines
1.9 KiB
TypeScript
import { api } from './client';
|
|
|
|
export interface DashboardDeviceRow {
|
|
deviceId: string;
|
|
deviceName: string;
|
|
siteName: string | null;
|
|
kwh: number;
|
|
peakKw: number | null;
|
|
lastSeen: string | null;
|
|
cost: number | null;
|
|
}
|
|
|
|
export interface DashboardChartPoint {
|
|
time: string;
|
|
totalKw: number;
|
|
}
|
|
|
|
export interface DashboardSummary {
|
|
totalKwh: number;
|
|
currentActivePowerKw: number | null;
|
|
activeDeviceCount: number;
|
|
totalCost: number | null;
|
|
devices: DashboardDeviceRow[];
|
|
chart: DashboardChartPoint[];
|
|
}
|
|
|
|
export async function fetchDashboardSummary(
|
|
fromUtc: string,
|
|
toUtc: string,
|
|
): Promise<DashboardSummary> {
|
|
const { data } = await api.get<DashboardSummary>('/dashboard/summary', {
|
|
params: { from: fromUtc, to: toUtc },
|
|
});
|
|
return data;
|
|
}
|
|
|
|
// Trigger a browser download. Same-origin → cookie travels automatically.
|
|
// We use window.location rather than axios+blob since the file is the user's
|
|
// intent (a download), not an in-page resource we need to manipulate.
|
|
export function downloadDashboardSummaryXlsx(fromUtc: string, toUtc: string) {
|
|
const params = new URLSearchParams({ from: fromUtc, to: toUtc });
|
|
window.location.href = `/api/dashboard/summary/export.xlsx?${params.toString()}`;
|
|
}
|
|
|
|
export function downloadRawMeasurementsXlsx(fromUtc: string, toUtc: string, rowCap = 100_000) {
|
|
const params = new URLSearchParams({ from: fromUtc, to: toUtc, rowCap: String(rowCap) });
|
|
window.location.href = `/api/dashboard/measurements/export.xlsx?${params.toString()}`;
|
|
}
|
|
|
|
export function downloadFleetDashboardXlsx() {
|
|
window.location.href = `/api/fleet/dashboard/export.xlsx`;
|
|
}
|
|
|
|
export function downloadFleetCustomerCostXlsx(customerId: string, fromUtc: string, toUtc: string) {
|
|
const params = new URLSearchParams({ from: fromUtc, to: toUtc });
|
|
window.location.href = `/api/fleet/customers/${encodeURIComponent(customerId)}/cost/export.xlsx?${params.toString()}`;
|
|
}
|