Skip to content

Commit b9af6e5

Browse files
committed
next/store: make disk space preset tags dynamic based on min/max
1 parent b7709f5 commit b9af6e5

File tree

3 files changed

+35
-8
lines changed

3 files changed

+35
-8
lines changed

src/packages/next/components/store/quota-config-presets.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { ReactNode } from "react";
77

88
import { IconName } from "@cocalc/frontend/components/icon";
99
import { Uptime } from "@cocalc/util/consts/site-license";
10+
import { MAX_DISK_GB } from "@cocalc/util/upgrades/consts";
1011
import { Paragraph } from "components/misc";
1112
import A from "components/misc/A";
1213
import { STANDARD_DISK } from "@cocalc/util/consts/billing";
@@ -150,7 +151,7 @@ export const SITE_LICENSE: PresetEntries = {
150151
),
151152
cpu: 1,
152153
ram: 2 * STANDARD_RAM,
153-
disk: Math.max(15, 4 * STANDARD_DISK),
154+
disk: Math.min(Math.max(15, 4 * STANDARD_DISK), MAX_DISK_GB),
154155
uptime: "medium",
155156
member: true,
156157
},
@@ -193,7 +194,7 @@ export const SITE_LICENSE: PresetEntries = {
193194
),
194195
cpu: 2,
195196
ram: 2 * STANDARD_RAM,
196-
disk: Math.max(15, 4 * STANDARD_DISK),
197+
disk: Math.min(Math.max(15, 4 * STANDARD_DISK), MAX_DISK_GB),
197198
uptime: "day",
198199
member: true,
199200
},
@@ -247,7 +248,7 @@ export const COURSE = {
247248
),
248249
cpu: 1,
249250
ram: 8,
250-
disk: 2 * STANDARD_DISK,
251+
disk: Math.min(2 * STANDARD_DISK, MAX_DISK_GB),
251252
uptime: "medium",
252253
member: true,
253254
},

src/packages/next/components/store/quota-config.tsx

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,13 @@ import { HelpIcon } from "@cocalc/frontend/components/help-icon";
2222
import { Icon } from "@cocalc/frontend/components/icon";
2323
import { displaySiteLicense } from "@cocalc/util/consts/site-license";
2424
import { plural, unreachable } from "@cocalc/util/misc";
25-
import { BOOST, DISK_DEFAULT_GB, REGULAR } from "@cocalc/util/upgrades/consts";
25+
import {
26+
BOOST,
27+
DISK_DEFAULT_GB,
28+
MAX_DISK_GB,
29+
MIN_DISK_GB,
30+
REGULAR,
31+
} from "@cocalc/util/upgrades/consts";
2632
import type { LicenseSource } from "@cocalc/util/upgrades/shopping";
2733

2834
import PricingItem, { Line } from "components/landing/pricing-item";
@@ -281,8 +287,29 @@ export const QuotaConfig: React.FC<Props> = (props: Props) => {
281287
);
282288
}
283289

290+
function generateDiskPresets(min: number, max: number): number[] {
291+
if (min >= max) return [min];
292+
293+
const range = max - min;
294+
const presets = [min]; // Always include minimum
295+
296+
// Create 3-4 evenly spaced values
297+
const step = Math.ceil(range / 4);
298+
let current = min + step;
299+
while (current < max) {
300+
presets.push(current);
301+
current += step;
302+
}
303+
304+
presets.push(max); // Always include maximum
305+
return [...new Set(presets)].sort((a, b) => a - b); // Remove duplicates and sort
306+
}
307+
284308
function disk() {
285-
// 2022-06: price increase "version 2": minimum disk we sell (also the free quota) is 3gb, not 1gb
309+
// Generate dynamic presets based on MIN_DISK_GB and MAX_DISK_GB
310+
const presets = boost
311+
? [0, ...generateDiskPresets(MIN_DISK_GB, PARAMS.disk.max).slice(0, 3)] // For boost, include 0 and limit to 3 additional values
312+
: generateDiskPresets(MIN_DISK_GB, MAX_DISK_GB);
286313
return (
287314
<Form.Item
288315
label="Disk space"
@@ -314,9 +341,7 @@ export const QuotaConfig: React.FC<Props> = (props: Props) => {
314341
onChange();
315342
}}
316343
units={"G Disk"}
317-
presets={
318-
boost ? [0, 3, 6, PARAMS.disk.max] : [3, 5, 10, PARAMS.disk.max]
319-
}
344+
presets={presets}
320345
/>
321346
</Form.Item>
322347
);

src/packages/util/upgrades/consts.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export const DEFAULT_CPU = 1;
1717
export const MAX_CPU = upgrades.max_per_project.cores;
1818

1919
// DISK
20+
// TODO (Aug 2025): increase this once the new file server is released
2021
export const MAX_DISK_GB = 15;
2122
// Aug 2025: in anticipation of the new file server, the minimum and standard is increased
2223
export const DISK_DEFAULT_GB = STANDARD_DISK;

0 commit comments

Comments
 (0)