improvement(insights): clarify unassigned usage and refresh usage cha… · simstudioai/sim@c8e39fb · GitHub
Skip to content

Commit c8e39fb

Browse files
authored
improvement(insights): clarify unassigned usage and refresh usage charts (#9265)
* improvement(insights): clarify unassigned usage and refresh usage charts * fix(insights): preserve sub-credit activity in the usage heatmap
1 parent 19f2475 commit c8e39fb

20 files changed

Lines changed: 586 additions & 147 deletions

File tree

‎apps/docs/content/docs/platform/enterprise/usage-tracking.mdx‎

Lines changed: 4 additions & 2 deletions
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { getOrganizationUsageCalendarContract } from '@/lib/api/contracts/organization-usage'
2+
import {
3+
defineInternalJsonRoute,
4+
internalRateLimits,
5+
internalSessionAuth,
6+
} from '@/lib/api/server/routes'
7+
import { getOrganizationUsageCalendar } from '@/lib/billing/application/organization-usage/get-organization-usage-calendar'
8+
import { organizationUsageOperations } from '@/lib/billing/application/organization-usage/operations'
9+
import { organizationUsageErrorPolicy } from '@/app/api/organizations/[id]/usage/error-policy'
10+
11+
export const dynamic = 'force-dynamic'
12+
13+
export const GET = defineInternalJsonRoute({
14+
contract: getOrganizationUsageCalendarContract,
15+
auth: internalSessionAuth,
16+
operation: organizationUsageOperations.readCalendar,
17+
rateLimit: internalRateLimits.none({
18+
reason:
19+
'Authenticated org-admin settings read, gated on enterprise entitlement and billing authority',
20+
}),
21+
errorPolicy: organizationUsageErrorPolicy,
22+
mapInput: ({ params, query }) => ({
23+
organizationId: params.id,
24+
workspaceId: query.workspaceId,
25+
timezone: query.timezone,
26+
}),
27+
useCase: getOrganizationUsageCalendar,
28+
present: (result) => result,
29+
})

‎apps/sim/ee/organization-usage/components/activity-summary.tsx‎

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,12 @@ import type { OrganizationUsageWindowKey } from '@/hooks/queries/utils/organizat
2525
const CHART_HEIGHT = 180
2626

2727
/**
28-
* Outcome layers, bottom-up. Failed is the status red and sits on the stack where a
29-
* spike reads at a glance; Other (cancelled, paused, unfinished) stays neutral, in a
30-
* gray whose lightness keeps it apart from the red for color-vision deficiency.
28+
* Outcome layers, bottom-up. Failed stays red; cancelled, paused and unfinished
29+
* runs share the neutral remainder.
3130
*/
3231
const OUTCOMES = [
33-
{ id: 'completed', label: 'Completed', color: 'var(--brand-blue)' },
34-
{ id: 'failed', label: 'Failed', color: 'var(--text-error)' },
32+
{ id: 'completed', label: 'Completed', color: 'var(--usage-workflow)' },
33+
{ id: 'failed', label: 'Failed', color: 'var(--usage-failed)' },
3534
{ id: 'other', label: 'Other', color: USAGE_OTHER_COLOR },
3635
] as const
3736

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
'use client'
2+
3+
import { ChartFrame } from '@sim/emcn'
4+
import { SettingsSection } from '@/app/workspace/[workspaceId]/settings/components/settings-section/settings-section'
5+
import { UsageHeatmap } from '@/ee/organization-usage/components/usage-heatmap'
6+
import { useOrganizationUsageCalendar } from '@/hooks/queries/organization-usage'
7+
8+
interface UsageCalendarProps {
9+
organizationId: string
10+
timezone: string
11+
workspaceId?: string
12+
}
13+
14+
/** Loads the year separately so its history cannot delay the selected period's chart. */
15+
export function UsageCalendar({ organizationId, timezone, workspaceId }: UsageCalendarProps) {
16+
const calendar = useOrganizationUsageCalendar(organizationId, timezone, workspaceId)
17+
return (
18+
<SettingsSection
19+
label='Usage heatmap'
20+
action={<span className='text-[var(--text-muted)] text-small'>Last 365 days</span>}
21+
>
22+
{calendar.isError || !calendar.data ? (
23+
<ChartFrame
24+
height={172}
25+
loading={calendar.isLoading}
26+
error={calendar.isError ? 'Could not load daily usage' : undefined}
27+
onRetry={() => void calendar.refetch()}
28+
>
29+
{null}
30+
</ChartFrame>
31+
) : (
32+
<UsageHeatmap days={calendar.data.days} />
33+
)}
34+
</SettingsSection>
35+
)
36+
}

‎apps/sim/ee/organization-usage/components/usage-consumers.tsx‎

Lines changed: 64 additions & 5 deletions

0 commit comments

Comments
 (0)