mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-08-17 12:42:21 +03:00
refactor(dashboard): shed QuotaCard complexity to baseline + type useQuotaVisibility settings fetch (#7251 CI green)
This commit is contained in:
@@ -9,6 +9,9 @@ import {
|
||||
worstStatus,
|
||||
filterQuotasByVisibility,
|
||||
getHiddenQuotaRows,
|
||||
computeCanEditCutoff,
|
||||
computeCanRedeemResetCredit,
|
||||
hasQuotaCutoffOverrides,
|
||||
type CardStatus,
|
||||
} from "./utils";
|
||||
import QuotaCardHeader from "./parts/QuotaCardHeader";
|
||||
@@ -104,14 +107,11 @@ export default function QuotaCard({
|
||||
[connection, emailsVisible]
|
||||
);
|
||||
|
||||
const overrides = (connection.quotaWindowThresholds as Record<string, number> | null) || null;
|
||||
const hasOverrides = !!overrides && Object.keys(overrides).length > 0;
|
||||
const hasOverrides = hasQuotaCutoffOverrides(connection);
|
||||
const hasStaleData = !!quota?.stale;
|
||||
const displayRefreshedAt = quota?.stale?.since || refreshedAt;
|
||||
const canEditCutoff = quotas.some((q: any) => q && typeof q.name === "string" && !q.isCredits);
|
||||
const canRedeemResetCredit =
|
||||
connection.provider === "codex" &&
|
||||
quotas.some((q: any) => q?.isResetCredits && Number(q.creditCount ?? q.remaining ?? 0) > 0);
|
||||
const canEditCutoff = computeCanEditCutoff(quotas);
|
||||
const canRedeemResetCredit = computeCanRedeemResetCredit(connection.provider, quotas);
|
||||
|
||||
return (
|
||||
<Card
|
||||
|
||||
@@ -29,7 +29,7 @@ export function useQuotaVisibility(tr: Translate, notify: NotifyLike) {
|
||||
let alive = true;
|
||||
fetch("/api/settings", { cache: "no-store" })
|
||||
.then((r) => (r.ok ? r.json() : {}))
|
||||
.then((s) => {
|
||||
.then((s: { quotaVisibility?: QuotaVisibilityMap }) => {
|
||||
if (alive) setQuotaVisibility(s?.quotaVisibility || {});
|
||||
})
|
||||
.catch(() => {});
|
||||
|
||||
@@ -304,6 +304,25 @@ export function normalizePlanTier(plan) {
|
||||
|
||||
// === Card Grid Helpers (T7) =================================================
|
||||
|
||||
// Card action-availability derivations. Extracted from QuotaCard so its
|
||||
// `.some(...)` predicate branches don't count against the component's
|
||||
// cyclomatic-complexity budget.
|
||||
export function computeCanEditCutoff(quotas: any[]): boolean {
|
||||
return quotas.some((q: any) => q && typeof q.name === "string" && !q.isCredits);
|
||||
}
|
||||
|
||||
export function computeCanRedeemResetCredit(provider: string, quotas: any[]): boolean {
|
||||
return (
|
||||
provider === "codex" &&
|
||||
quotas.some((q: any) => q?.isResetCredits && Number(q.creditCount ?? q.remaining ?? 0) > 0)
|
||||
);
|
||||
}
|
||||
|
||||
export function hasQuotaCutoffOverrides(connection: any): boolean {
|
||||
const overrides = (connection.quotaWindowThresholds as Record<string, number> | null) || null;
|
||||
return !!overrides && Object.keys(overrides).length > 0;
|
||||
}
|
||||
|
||||
export const STATUS_EMOJI = {
|
||||
critical: "🔴",
|
||||
alert: "🟡",
|
||||
|
||||
Reference in New Issue
Block a user