fix: restore GitHub rate limit indicator (#2664)
This commit is contained in:
@@ -19,14 +19,20 @@ export function GitHubAccessHelp({
|
||||
title,
|
||||
description,
|
||||
content,
|
||||
onOpen,
|
||||
}: {
|
||||
label: string;
|
||||
title: string;
|
||||
description: string;
|
||||
content?: ReactNode;
|
||||
onOpen?: () => void;
|
||||
}) {
|
||||
const usesTouchDrawer = useTouchDrawer();
|
||||
const [open, setOpen] = useState(false);
|
||||
const handleDrawerOpenChange = (nextOpen: boolean) => {
|
||||
setOpen(nextOpen);
|
||||
if (nextOpen) onOpen?.();
|
||||
};
|
||||
const button = (
|
||||
<Button
|
||||
type="button"
|
||||
@@ -43,7 +49,7 @@ export function GitHubAccessHelp({
|
||||
const trigger = usesTouchDrawer ? (
|
||||
<DrawerTrigger asChild>{button}</DrawerTrigger>
|
||||
) : (
|
||||
<Tooltip>
|
||||
<Tooltip onOpenChange={(nextOpen) => nextOpen && onOpen?.()}>
|
||||
<TooltipTrigger asChild>{button}</TooltipTrigger>
|
||||
<TooltipContent side="top" align="start" className="max-w-[320px] text-xs leading-relaxed">
|
||||
{content ?? description}
|
||||
@@ -52,7 +58,7 @@ export function GitHubAccessHelp({
|
||||
);
|
||||
|
||||
return (
|
||||
<Drawer open={open} onOpenChange={setOpen}>
|
||||
<Drawer open={open} onOpenChange={handleDrawerOpenChange}>
|
||||
{trigger}
|
||||
<DrawerContent>
|
||||
<DrawerHeader>
|
||||
|
||||
@@ -58,12 +58,16 @@ function snapshotsFromInfo(info: GitHubRateLimitInfo): GitHubRateLimitSnapshot[]
|
||||
return out;
|
||||
}
|
||||
|
||||
export function GitHubRateLimitDisplay({ info }: { info?: GitHubRateLimitInfo }) {
|
||||
export function GitHubRateLimitDisplay({
|
||||
info,
|
||||
onOpen,
|
||||
}: {
|
||||
info?: GitHubRateLimitInfo;
|
||||
onOpen?: () => void;
|
||||
}) {
|
||||
const { t } = useTranslation();
|
||||
const now = useTickNow(30_000);
|
||||
if (!info) return null;
|
||||
const snapshots = snapshotsFromInfo(info);
|
||||
if (snapshots.length === 0) return null;
|
||||
const snapshots = info ? snapshotsFromInfo(info) : [];
|
||||
const exhausted = snapshots.filter((s) => isExhausted(s, now));
|
||||
|
||||
return (
|
||||
@@ -71,7 +75,12 @@ export function GitHubRateLimitDisplay({ info }: { info?: GitHubRateLimitInfo })
|
||||
label={t("github:showGithubApiLimits")}
|
||||
title={t("github:githubApiLimits")}
|
||||
description={t("github:currentGithubApiRateAndQuery")}
|
||||
content={<RateLimitDetails snapshots={snapshots} exhausted={exhausted} />}
|
||||
content={
|
||||
snapshots.length > 0 ? (
|
||||
<RateLimitDetails snapshots={snapshots} exhausted={exhausted} />
|
||||
) : undefined
|
||||
}
|
||||
onOpen={onOpen}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -69,7 +69,13 @@ function automationActor(status: GitHubStatus): string | null {
|
||||
return status.automation?.actor?.login ?? null;
|
||||
}
|
||||
|
||||
function StatusLine({ status }: { status: GitHubStatus }) {
|
||||
function StatusLine({
|
||||
status,
|
||||
onRateLimitOpen,
|
||||
}: {
|
||||
status: GitHubStatus;
|
||||
onRateLimitOpen: () => void;
|
||||
}) {
|
||||
const { t } = useTranslation();
|
||||
const connection = status.automation;
|
||||
if (!connection) {
|
||||
@@ -99,7 +105,7 @@ function StatusLine({ status }: { status: GitHubStatus }) {
|
||||
{t(sourceLabelKeys[connection.source])}
|
||||
</Badge>
|
||||
{connection.status !== "active" && <Badge variant="outline">{connection.status}</Badge>}
|
||||
<GitHubRateLimitDisplay info={status.rate_limit} />
|
||||
<GitHubRateLimitDisplay info={status.rate_limit} onOpen={onRateLimitOpen} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -120,15 +126,17 @@ function AutomationStatusSummary({
|
||||
status,
|
||||
app,
|
||||
taskAccess,
|
||||
onRateLimitOpen,
|
||||
}: {
|
||||
status: GitHubStatus;
|
||||
app?: GitHubAppRegistrationCatalogItem;
|
||||
taskAccess: Omit<TaskGitCredentialsState, "save">;
|
||||
onRateLimitOpen: () => void;
|
||||
}) {
|
||||
const appAutomation = status.automation?.source === "github_app_installation";
|
||||
return (
|
||||
<div className="min-w-0 space-y-1">
|
||||
<StatusLine status={status} />
|
||||
<StatusLine status={status} onRateLimitOpen={onRateLimitOpen} />
|
||||
<AutomationActorExplanation status={status} appAutomation={appAutomation} />
|
||||
{appAutomation && <AppRegistrationDetails app={app} />}
|
||||
<AutomationError status={status} />
|
||||
@@ -280,7 +288,12 @@ export function GitHubAutomationSettings({ workspaceId }: { workspaceId: string
|
||||
className="flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between"
|
||||
data-testid="github-workspace-automation"
|
||||
>
|
||||
<AutomationStatusSummary status={status} app={activeApp} taskAccess={taskAccess} />
|
||||
<AutomationStatusSummary
|
||||
status={status}
|
||||
app={activeApp}
|
||||
taskAccess={taskAccess}
|
||||
onRateLimitOpen={refresh}
|
||||
/>
|
||||
<AutomationActions
|
||||
status={status}
|
||||
workspaceId={workspaceId}
|
||||
|
||||
Reference in New Issue
Block a user