Files
Kevin Grüneberg 9de6ee58b1 feat(orb): support new usage stats (#28208)
- Add new metric Disk Size GB-Hrs (only exposed to paid plans on Orb)
- Adjusted some texts as preparation of new billing plans
- Fixed some visual bugs with the usage summary grid
- Project allocations in tooltips are now sorted by usage (descending)
- Project allocations with too little usage (<0.01) now display "<0.01" instead of just "0"
- Usage formatter supports usage that is broken down to hours
- Stop showing percentages when the usage is 0 (previously showed "<1%"

This change is backwards compatible and can be merged. Note that there will be full overhaul in the feature of the entire usage page, this is just the least invasive change to make the transition work.
2024-07-30 14:37:54 +08:00

82 lines
2.1 KiB
TypeScript

import { PricingMetric } from 'data/analytics/org-daily-stats-query'
const pricingMetricBytes = [
PricingMetric.DATABASE_SIZE,
PricingMetric.EGRESS,
PricingMetric.STORAGE_SIZE,
]
export const formatUsage = (
pricingMetric: PricingMetric,
allocation: { usage: number; hours?: number }
) => {
if (allocation.hours) {
return (
allocation.usage.toLocaleString() +
' (' +
Math.round(allocation.usage / allocation.hours).toLocaleString() +
'x' +
allocation.hours.toLocaleString() +
' hours)'
)
}
if (pricingMetricBytes.includes(pricingMetric)) {
const formattedUsage = +(allocation.usage / 1e9).toFixed(2).toLocaleString()
// To avoid very low usage displaying as "0", we will show "<0.01" instead
if (allocation.usage > 0 && formattedUsage === 0) {
return '<0.01'
} else {
return formattedUsage
}
} else {
return allocation.usage.toLocaleString()
}
}
export const billingMetricUnit = (pricingMetric: PricingMetric) => {
if (pricingMetricBytes.includes(pricingMetric)) {
return 'GB'
} else if (
pricingMetric.startsWith('COMPUTE_HOURS') ||
[
PricingMetric.CUSTOM_DOMAIN,
PricingMetric.IPV4,
PricingMetric.PITR_7,
PricingMetric.PITR_14,
PricingMetric.PITR_28,
].includes(pricingMetric)
) {
return 'Hours'
} else {
return null
}
}
export const generateUpgradeReasons = (originalPlan?: string, upgradedPlan?: string) => {
const reasons = [
'Current plan limits are not enough for me',
'I want better customer support from Supabase',
'I am migrating from a previous project',
]
if (originalPlan === undefined || upgradedPlan === undefined) {
reasons.push('None of the above')
return reasons
}
if (originalPlan === 'free' && upgradedPlan === 'pro') {
reasons.push('Need more compute')
reasons.push(
'I want access to additional features like branching, daily backups, custom domain and PITR'
)
} else if (upgradedPlan === 'team') {
reasons.push('I want access to SOC2 and HIPAA compliance')
}
reasons.push('None of the above')
return reasons
}