SizeAndCounts.tsx 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. import { dailyUsageToDataPoints } from './Usage.utils'
  2. import UsageSection from './UsageSection/UsageSection'
  3. import { DataPoint } from '@/data/analytics/constants'
  4. import { PricingMetric, type OrgDailyUsageResponse } from '@/data/analytics/org-daily-stats-query'
  5. import type { OrgSubscription } from '@/data/subscriptions/types'
  6. export interface SizeAndCountsProps {
  7. orgSlug: string
  8. projectRef?: string | null
  9. subscription: OrgSubscription | undefined
  10. currentBillingCycleSelected: boolean
  11. orgDailyStats: OrgDailyUsageResponse | undefined
  12. isLoadingOrgDailyStats: boolean
  13. startDate: string | undefined
  14. endDate: string | undefined
  15. }
  16. const SizeAndCounts = ({
  17. orgSlug,
  18. projectRef,
  19. subscription,
  20. currentBillingCycleSelected,
  21. orgDailyStats,
  22. isLoadingOrgDailyStats,
  23. startDate,
  24. endDate,
  25. }: SizeAndCountsProps) => {
  26. const chartMeta: {
  27. [key: string]: { data: DataPoint[]; margin: number; isLoading: boolean }
  28. } = {
  29. [PricingMetric.STORAGE_SIZE]: {
  30. isLoading: isLoadingOrgDailyStats,
  31. margin: 14,
  32. data: dailyUsageToDataPoints(
  33. orgDailyStats,
  34. (metric) => metric === PricingMetric.STORAGE_SIZE
  35. ),
  36. },
  37. [PricingMetric.DATABASE_SIZE]: {
  38. isLoading: isLoadingOrgDailyStats,
  39. margin: 14,
  40. data: dailyUsageToDataPoints(
  41. orgDailyStats,
  42. (metric) => metric === PricingMetric.DATABASE_SIZE
  43. ),
  44. },
  45. }
  46. return (
  47. <UsageSection
  48. orgSlug={orgSlug}
  49. projectRef={projectRef}
  50. categoryKey="sizeCount"
  51. chartMeta={chartMeta}
  52. subscription={subscription}
  53. currentBillingCycleSelected={currentBillingCycleSelected}
  54. startDate={startDate}
  55. endDate={endDate}
  56. />
  57. )
  58. }
  59. export default SizeAndCounts