feat(i18n): localize Settings → Integrations → GitHub connection and auth (#2155)
Co-authored-by: Kandev Agent <agent@kandev.dev> Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -6,11 +6,16 @@ import { IconAlertTriangle } from "@tabler/icons-react";
|
||||
import { Alert, AlertDescription } from "@kandev/ui/alert";
|
||||
import type { GitHubRateLimitInfo, GitHubRateLimitSnapshot } from "@/lib/types/github";
|
||||
import { GitHubAccessHelp } from "./github-access-help";
|
||||
import { useTranslation } from "react-i18next";
|
||||
// Locale-aware digit grouping; `toLocaleString("en-US")` pinned it to English.
|
||||
import { formatNumber } from "@/lib/i18n/formats";
|
||||
|
||||
const RESOURCE_LABELS: Record<string, { label: string; unit: string }> = {
|
||||
core: { label: "API rate limit", unit: "requests" },
|
||||
graphql: { label: "GraphQL query limit", unit: "points" },
|
||||
search: { label: "Search limit", unit: "requests" },
|
||||
// Keyed by GitHub's rate-limit resource name, which is wire data. Catalog keys
|
||||
// rather than `t()` calls, because this is module scope (see docs/i18n.md).
|
||||
const RESOURCE_LABELS: Record<string, { labelKey: string; unitKey: string }> = {
|
||||
core: { labelKey: "github:apiRateLimit", unitKey: "github:rateLimitUnitRequests" },
|
||||
graphql: { labelKey: "github:graphqlQueryLimit", unitKey: "github:rateLimitUnitPoints" },
|
||||
search: { labelKey: "github:searchLimit", unitKey: "github:rateLimitUnitRequests" },
|
||||
};
|
||||
|
||||
// useTickNow re-renders every intervalMs and exposes a stable now-value so the
|
||||
@@ -55,6 +60,7 @@ function snapshotsFromInfo(info: GitHubRateLimitInfo): GitHubRateLimitSnapshot[]
|
||||
}
|
||||
|
||||
export function GitHubRateLimitDisplay({ info }: { info?: GitHubRateLimitInfo }) {
|
||||
const { t } = useTranslation();
|
||||
const now = useTickNow(30_000);
|
||||
if (!info) return null;
|
||||
const snapshots = snapshotsFromInfo(info);
|
||||
@@ -63,9 +69,9 @@ export function GitHubRateLimitDisplay({ info }: { info?: GitHubRateLimitInfo })
|
||||
|
||||
return (
|
||||
<GitHubAccessHelp
|
||||
label="Show GitHub API limits"
|
||||
title="GitHub API limits"
|
||||
description="Current GitHub API rate and query limits for this workspace connection."
|
||||
label={t("github:showGithubApiLimits")}
|
||||
title={t("github:githubApiLimits")}
|
||||
description={t("github:currentGithubApiRateAndQuery")}
|
||||
content={<RateLimitDetails snapshots={snapshots} exhausted={exhausted} />}
|
||||
/>
|
||||
);
|
||||
@@ -78,34 +84,44 @@ function RateLimitDetails({
|
||||
snapshots: GitHubRateLimitSnapshot[];
|
||||
exhausted: GitHubRateLimitSnapshot[];
|
||||
}) {
|
||||
const { t } = useTranslation();
|
||||
return (
|
||||
<div className="space-y-2" data-testid="github-rate-limit-display">
|
||||
{exhausted.length > 0 && (
|
||||
<Alert variant="destructive" data-testid="github-rate-limit-exhausted">
|
||||
<IconAlertTriangle className="h-4 w-4" />
|
||||
<AlertDescription className="text-xs">
|
||||
GitHub API access is exhausted for{" "}
|
||||
{exhausted
|
||||
.map((snapshot) => RESOURCE_LABELS[snapshot.resource]?.label ?? snapshot.resource)
|
||||
.join(", ")}
|
||||
. Background PR and issue checks are paused until the last limit resets{" "}
|
||||
{formatReset(latestReset(exhausted))}.
|
||||
{t("github:githubApiAccessIsExhaustedFor", {
|
||||
resources: exhausted
|
||||
.map((snapshot) =>
|
||||
RESOURCE_LABELS[snapshot.resource]
|
||||
? t(RESOURCE_LABELS[snapshot.resource].labelKey)
|
||||
: snapshot.resource,
|
||||
)
|
||||
.join(", "),
|
||||
reset: formatReset(latestReset(exhausted)),
|
||||
})}
|
||||
</AlertDescription>
|
||||
</Alert>
|
||||
)}
|
||||
<div className="space-y-1 text-xs text-muted-foreground">
|
||||
{snapshots.map((snapshot) => {
|
||||
const resource = RESOURCE_LABELS[snapshot.resource] ?? {
|
||||
label: snapshot.resource,
|
||||
unit: "requests",
|
||||
};
|
||||
const limit = snapshot.limit > 0 ? snapshot.limit.toLocaleString("en-US") : "unknown";
|
||||
const resource = RESOURCE_LABELS[snapshot.resource];
|
||||
// An unknown resource name is wire data, so it is shown verbatim.
|
||||
const label = resource ? t(resource.labelKey) : snapshot.resource;
|
||||
const unit = t(resource?.unitKey ?? "github:rateLimitUnitRequests");
|
||||
const limit =
|
||||
snapshot.limit > 0 ? formatNumber(snapshot.limit) : t("github:rateLimitUnknown");
|
||||
const reset = formatReset(snapshot);
|
||||
return (
|
||||
<p key={snapshot.resource} data-testid={`github-rate-limit-${snapshot.resource}`}>
|
||||
<span className="font-medium text-foreground">{resource.label}:</span>{" "}
|
||||
{snapshot.remaining.toLocaleString("en-US")} of {limit} {resource.unit} remaining
|
||||
{reset ? ` · resets ${reset}` : ""}
|
||||
<span className="font-medium text-foreground">{label}:</span>{" "}
|
||||
{t("github:rateLimitRemaining", {
|
||||
remaining: formatNumber(snapshot.remaining),
|
||||
limit,
|
||||
unit,
|
||||
})}
|
||||
{reset ? t("github:resets", { reset }) : ""}
|
||||
</p>
|
||||
);
|
||||
})}
|
||||
|
||||
Reference in New Issue
Block a user