improvement(billing): move credit usage period filter into the URL · simstudioai/sim@73679b1 · GitHub
Skip to content

Commit 73679b1

Browse files
committed
improvement(billing): move credit usage period filter into the URL
/cleanup pass (nuqs rule, react-query-best-practices, emcn review): - period was a plain useState, but it's exactly the kind of shareable list filter sim-url-state.md calls out for nuqs — migrated to billingParsers/useQueryStates so the selection deep-links, survives reload, and matches every sibling settings section (recently-deleted, inbox, teammates). Derives its literal values from usageLogPeriodSchema instead of a fourth copy of the same union. - Removed an unjustified showSelectedCheck={false} on the period ChipDropdown — the one other usage in the codebase is a one-shot action menu with no persistent selection; this is a real filter and should show the check like the default intends. - Added placeholderData: keepPreviousData to useUsageLogs — period is a variable query key, so without it switching periods flashed the loading empty-state instead of smoothly transitioning. Verified live: deep-link with ?period=7d pre-selects and loads correctly, switching periods updates the URL, and the selection survives a hard reload.
1 parent 9d6dd83 commit 73679b1

3 files changed

Lines changed: 32 additions & 6 deletions

File tree

apps/sim/app/workspace/[workspaceId]/settings/components/billing/components/credit-usage-section/credit-usage-section.tsx

Lines changed: 7 additions & 4 deletions
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { parseAsStringLiteral } from 'nuqs/server'
2+
import { usageLogPeriodSchema } from '@/lib/api/contracts/user'
3+
4+
/**
5+
* Co-located, typed URL query-param definitions for the Billing settings
6+
* view.
7+
*
8+
* - `period` is the Credit usage section's time-window filter, sharing its
9+
* literal values with {@link usageLogPeriodSchema} so the URL parser can
10+
* never drift from the API contract it filters.
11+
*/
12+
export const billingParsers = {
13+
period: parseAsStringLiteral(usageLogPeriodSchema.options).withDefault('30d'),
14+
} as const
15+
16+
/** Filter view-state: clean URLs, no back-stack churn. */
17+
export const billingUrlKeys = {
18+
history: 'replace',
19+
shallow: true,
20+
clearOnDefault: true,
21+
} as const

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

Lines changed: 4 additions & 2 deletions

0 commit comments

Comments
 (0)