diff --git a/apps/sim/app/workspace/[workspaceId]/w/components/sidebar/components-new/usage-indicator/usage-indicator.tsx b/apps/sim/app/workspace/[workspaceId]/w/components/sidebar/components-new/usage-indicator/usage-indicator.tsx index c0f824df67..2ed700f9d6 100644 --- a/apps/sim/app/workspace/[workspaceId]/w/components/sidebar/components-new/usage-indicator/usage-indicator.tsx +++ b/apps/sim/app/workspace/[workspaceId]/w/components/sidebar/components-new/usage-indicator/usage-indicator.tsx @@ -1,22 +1,32 @@ 'use client' -import { useEffect } from 'react' -import { Badge, Progress, Skeleton } from '@/components/ui' +import { useEffect, useMemo } from 'react' +import { Button } from '@/components/emcn' +import { Skeleton } from '@/components/ui' import { createLogger } from '@/lib/logs/console/logger' -import { cn } from '@/lib/utils' +import { MIN_SIDEBAR_WIDTH, useSidebarStore } from '@/stores/sidebar/store' import { useSubscriptionStore } from '@/stores/subscription/store' -// Constants for reusable styles -const GRADIENT_BADGE_STYLES = - 'gradient-text h-[1.125rem] rounded-[6px] border-gradient-primary/20 bg-gradient-to-b from-gradient-primary via-gradient-secondary to-gradient-primary px-2 py-0 font-medium text-xs' -const GRADIENT_TEXT_STYLES = - 'gradient-text bg-gradient-to-b from-gradient-primary via-gradient-secondary to-gradient-primary' -const CONTAINER_STYLES = - 'pointer-events-auto flex-shrink-0 rounded-[10px] border bg-background px-3 py-2.5 shadow-xs cursor-pointer transition-colors hover:bg-muted/50' - const logger = createLogger('UsageIndicator') -// Plan name mapping +/** + * Minimum number of pills to display (at minimum sidebar width) + */ +const MIN_PILL_COUNT = 6 + +/** + * Maximum number of pills to display + */ +const MAX_PILL_COUNT = 8 + +/** + * Width increase (in pixels) required to add one additional pill + */ +const WIDTH_PER_PILL = 50 + +/** + * Plan name mapping + */ const PLAN_NAMES = { enterprise: 'Enterprise', team: 'Team', @@ -30,26 +40,40 @@ interface UsageIndicatorProps { export function UsageIndicator({ onClick }: UsageIndicatorProps) { const { getUsage, getSubscriptionStatus, isLoading } = useSubscriptionStore() + const sidebarWidth = useSidebarStore((state) => state.sidebarWidth) useEffect(() => { useSubscriptionStore.getState().loadData() }, []) + /** + * Calculate pill count based on sidebar width + * Starts at MIN_PILL_COUNT at minimum width, adds 1 pill per WIDTH_PER_PILL increase + */ + const pillCount = useMemo(() => { + const widthDelta = sidebarWidth - MIN_SIDEBAR_WIDTH + const additionalPills = Math.floor(widthDelta / WIDTH_PER_PILL) + const calculatedCount = MIN_PILL_COUNT + additionalPills + return Math.max(MIN_PILL_COUNT, Math.min(MAX_PILL_COUNT, calculatedCount)) + }, [sidebarWidth]) + const usage = getUsage() const subscription = getSubscriptionStatus() if (isLoading) { return ( -