-
Notifications
You must be signed in to change notification settings - Fork 170
Expand file tree
/
Copy pathutils.ts
More file actions
65 lines (55 loc) · 1.99 KB
/
utils.ts
File metadata and controls
65 lines (55 loc) · 1.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import { formatMemorySize } from "@rilldata/web-common/lib/number-formatting/memory-size";
import { DateTime } from "luxon";
import { writable } from "svelte/store";
export function formatUsageVsQuota(
usageInBytes: number,
storageLimitBytesPerDeployment: string,
): string {
const quota = Number(storageLimitBytesPerDeployment);
if (Number.isNaN(quota) || storageLimitBytesPerDeployment === "-1") return "";
const formattedUsage = formatMemorySize(usageInBytes);
const formattedQuota = formatMemorySize(quota);
const percent =
usageInBytes > quota
? "100+"
: Math.round((usageInBytes * 100) / quota) + "";
return `${formattedUsage} of ${formattedQuota} (${percent}%)`;
}
// Mapping of externalID/planName to a type.
// Used in deciding banner message and to show different billing module in frontend.
// Make sure to update admin/billing/orb.go::getPlanType if this is updated
export function isTrialPlan(planName: string) {
return planName === "free_trial";
}
export function isTeamPlan(planName: string) {
return planName === "team";
}
export function isManagedPlan(planName: string) {
return planName === "managed";
}
export function isFreePlan(planName: string) {
return planName === "free_plan";
}
export function isProPlan(planName: string) {
return planName === "pro_plan";
}
export function isEnterprisePlan(planName: string) {
return (
!isTrialPlan(planName) &&
!isTeamPlan(planName) &&
!isManagedPlan(planName) &&
!isFreePlan(planName) &&
!isProPlan(planName)
);
}
export function getSubscriptionResumedText(endDate: string) {
const date = DateTime.fromJSDate(new Date(endDate));
if (!date.isValid || date.toMillis() < Date.now()) {
return "today";
}
const resumeDate = date.plus({ day: 1 });
return "on " + resumeDate.toLocaleString(DateTime.DATE_MED);
}
// Since this could be triggered in a route that could be navigated from,
// we add a global and show it in org route's layout
export const showWelcomeToRillDialog = writable(false);