mirror of
https://github.com/block/buzz.git
synced 2026-08-18 06:50:31 +02:00
refactor(agent-usage): move usage-ingress wiring into the feature hook
main's file-size ratchet (#3352) replaced the static per-file override map with a git-diff base comparison, dropping the 1025-line ceiling that UserProfilePanel.tsx had been living under. The 7-day ingress query was agent-usage logic sitting in a profile file; moving it home puts the panel back under the 1000-line limit with no behavior change. Co-authored-by: Will Pfleger <pfleger.will@gmail.com> Signed-off-by: Will Pfleger <pfleger.will@gmail.com>
This commit is contained in:
co-authored by
Will Pfleger
parent
0bd3b7d0a3
commit
25f7dfe138
@@ -8,6 +8,7 @@ import {
|
||||
} from "@/shared/api/tauriArchive";
|
||||
import {
|
||||
buildLocalDayBoundaries,
|
||||
deriveUsageIngressTrailing,
|
||||
msUntilNextLocalMidnight,
|
||||
type UsageWindowDays,
|
||||
} from "./lib/agentUsage";
|
||||
@@ -100,3 +101,25 @@ export function useAgentUsageSeries({
|
||||
gcTime: 5 * 60_000,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Trailing text for the profile Info tab's usage ingress row (plan:328).
|
||||
*
|
||||
* Owns its own 7-day window deliberately: the row summarises recent usage
|
||||
* independently of the focused view's 7d/30d selector, so the two must not
|
||||
* share a query. Returns `undefined` while the query is disabled or still
|
||||
* loading, which the row renders as no trailing text at all.
|
||||
*
|
||||
* `enabled` gates the query off entirely when the row won't render.
|
||||
*/
|
||||
export function useUsageIngress(
|
||||
agentPubkey: string | null,
|
||||
enabled: boolean,
|
||||
): string | undefined {
|
||||
const query = useAgentUsageSeries({
|
||||
agentPubkey: agentPubkey ?? undefined,
|
||||
days: 7,
|
||||
enabled,
|
||||
});
|
||||
return query.data ? deriveUsageIngressTrailing(query.data) : undefined;
|
||||
}
|
||||
|
||||
@@ -68,8 +68,7 @@ import {
|
||||
} from "@/features/profile/ui/UserProfilePanelSections";
|
||||
import { AgentConfigurationFocusedView } from "@/features/profile/ui/UserProfilePanelAgentDetails";
|
||||
import { AgentUsageFocusedView } from "@/features/agent-usage/ui/AgentUsageFocusedView";
|
||||
import { useAgentUsageSeries } from "@/features/agent-usage/hooks";
|
||||
import { deriveUsageIngressTrailing } from "@/features/agent-usage/lib/agentUsage";
|
||||
import { useUsageIngress } from "@/features/agent-usage/hooks";
|
||||
import { UserProfileAgentSettingsMenuSlot } from "@/features/profile/ui/UserProfileAgentActions";
|
||||
import { useProfileAgentDeletion } from "@/features/profile/ui/UserProfilePanelDeletion";
|
||||
import { useProfileFieldBuckets } from "@/features/profile/ui/UserProfilePanelFields";
|
||||
@@ -342,17 +341,7 @@ export function UserProfilePanel({
|
||||
Boolean(effectivePubkey) &&
|
||||
canOpenAgentActivity(effectivePubkey);
|
||||
const canViewUsage = viewerIsOwner && isBot && Boolean(effectivePubkey);
|
||||
// Info-tab ingress row's trailing text (plan:328) needs its own 7-day
|
||||
// query — independent of the focused view's own 7d/30d selector, and
|
||||
// gated off entirely when the row won't render.
|
||||
const usageIngressQuery = useAgentUsageSeries({
|
||||
agentPubkey: effectivePubkey ?? undefined,
|
||||
days: 7,
|
||||
enabled: canViewUsage,
|
||||
});
|
||||
const usageIngressTrailing = usageIngressQuery.data
|
||||
? deriveUsageIngressTrailing(usageIngressQuery.data)
|
||||
: undefined;
|
||||
const usageIngressTrailing = useUsageIngress(effectivePubkey, canViewUsage);
|
||||
const canOpenAgentLogs =
|
||||
isOwner === true && managedAgent?.backend.type === "local";
|
||||
const canInstantiateAgent =
|
||||
|
||||
Reference in New Issue
Block a user