Skip to content

Commit 1405b45

Browse files
authored
improvement(usage): show up to 50 rows per tab (#7410)
* improvement(usage): show up to 50 rows per tab * improvement(usage): allow expanded views up to 100 rows
1 parent a663c4e commit 1405b45

4 files changed

Lines changed: 37 additions & 9 deletions

File tree

apps/sim/ee/organization-usage/constants.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import type { ComboboxOption } from '@sim/emcn'
22
import {
3+
ORGANIZATION_USAGE_BREAKDOWN_DEFAULT_LIMIT,
4+
ORGANIZATION_USAGE_BREAKDOWN_MAX_LIMIT,
35
USAGE_WINDOW_PRESETS,
46
type UsageBreakdownDimension,
57
type UsageWindowPreset,
@@ -78,13 +80,12 @@ export const USAGE_TAB_EMPTY_COPY: Record<UsageBreakdownDimension, string> = {
7880
/**
7981
* Rows per breakdown before and after the `Other` row is expanded.
8082
*
81-
* The collapsed count keeps a tab to one screen; the expanded one is the contract's
82-
* own ceiling (`usageLimitSchema(50, 10)`), so asking for more would be refused. A
83-
* dimension with more than {@link EXPANDED_ROW_COUNT} distinct rows still shows an
84-
* `Other` row after expanding, which is the honest result rather than a bug.
83+
* Each tab shows the contract default immediately, then can request the contract
84+
* ceiling by expanding `Other`. A dimension with more than
85+
* {@link EXPANDED_ROW_COUNT} distinct rows still shows a remainder after expanding.
8586
*/
86-
export const COLLAPSED_ROW_COUNT = 10
87-
export const EXPANDED_ROW_COUNT = 50
87+
export const COLLAPSED_ROW_COUNT = ORGANIZATION_USAGE_BREAKDOWN_DEFAULT_LIMIT
88+
export const EXPANDED_ROW_COUNT = ORGANIZATION_USAGE_BREAKDOWN_MAX_LIMIT
8889

8990
export const DEFAULT_USAGE_PRESET = 'current-period' as const
9091
export const DEFAULT_USAGE_TAB = USAGE_OVERVIEW_TAB

apps/sim/hooks/queries/organization-usage.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
getOrganizationUsageBreakdownContract,
77
getOrganizationUsageSummaryContract,
88
listOrganizationUsageEventsContract,
9+
ORGANIZATION_USAGE_BREAKDOWN_DEFAULT_LIMIT,
910
type OrganizationUsageBreakdown,
1011
type OrganizationUsageEventPage,
1112
type OrganizationUsageSummary,
@@ -96,7 +97,7 @@ export function useOrganizationUsageBreakdown(
9697
dimension: UsageBreakdownDimension,
9798
options: UseBreakdownOptions = {}
9899
) {
99-
const limit = options.limit ?? 10
100+
const limit = options.limit ?? ORGANIZATION_USAGE_BREAKDOWN_DEFAULT_LIMIT
100101
const { workspaceId } = options
101102
const queryKey = organizationUsageKeys.breakdown(
102103
organizationId ?? '',

apps/sim/lib/api/contracts/organization-usage.test.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22
* @vitest-environment node
33
*/
44
import { describe, expect, it } from 'vitest'
5-
import { organizationUsageEventsQuerySchema } from '@/lib/api/contracts/organization-usage'
5+
import {
6+
organizationUsageBreakdownQuerySchema,
7+
organizationUsageEventsQuerySchema,
8+
} from '@/lib/api/contracts/organization-usage'
69

710
/** The shared window fields every usage contract extends, exercised through one of them. */
811
function parseWindow(input: Record<string, unknown>) {
@@ -68,3 +71,20 @@ describe('organization usage window contract', () => {
6871
expect(parseWindow({ timezone: 'Mars/Olympus_Mons' }).success).toBe(false)
6972
})
7073
})
74+
75+
describe('organization usage breakdown contract', () => {
76+
const baseQuery = { dimension: 'workspace' as const }
77+
78+
it('defaults to 50 rows', () => {
79+
expect(organizationUsageBreakdownQuerySchema.parse(baseQuery).limit).toBe(50)
80+
})
81+
82+
it('allows expansion to 100 rows and refuses larger requests', () => {
83+
expect(
84+
organizationUsageBreakdownQuerySchema.safeParse({ ...baseQuery, limit: 100 }).success
85+
).toBe(true)
86+
expect(
87+
organizationUsageBreakdownQuerySchema.safeParse({ ...baseQuery, limit: 101 }).success
88+
).toBe(false)
89+
})
90+
})

apps/sim/lib/api/contracts/organization-usage.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ export type UsageBreakdownDimension = z.output<typeof usageBreakdownDimensionSch
4040
*/
4141
export const MAX_CUSTOM_RANGE_DAYS = 92
4242

43+
export const ORGANIZATION_USAGE_BREAKDOWN_DEFAULT_LIMIT = 50
44+
export const ORGANIZATION_USAGE_BREAKDOWN_MAX_LIMIT = 100
45+
4346
/**
4447
* A bare `YYYY-MM-DD` calendar date, and nothing else.
4548
*
@@ -144,7 +147,10 @@ export type OrganizationUsageSummaryQuery = z.input<typeof organizationUsageSumm
144147
export const organizationUsageBreakdownQuerySchema = organizationUsageWindowQuerySchema.extend({
145148
...usageWorkspaceScopeShape,
146149
dimension: usageBreakdownDimensionSchema,
147-
limit: usageLimitSchema(50, 10),
150+
limit: usageLimitSchema(
151+
ORGANIZATION_USAGE_BREAKDOWN_MAX_LIMIT,
152+
ORGANIZATION_USAGE_BREAKDOWN_DEFAULT_LIMIT
153+
),
148154
})
149155
export type OrganizationUsageBreakdownQuery = z.input<typeof organizationUsageBreakdownQuerySchema>
150156

0 commit comments

Comments
 (0)