Skip to content

Commit 992ab40

Browse files
committed
cloud filesystem bucket location selection -- include cities and searchability of them
- this is for consistency with compute servers
1 parent c130634 commit 992ab40

File tree

2 files changed

+55
-19
lines changed

2 files changed

+55
-19
lines changed

src/packages/frontend/compute/cloud-filesystem/bucket.tsx

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { getDataStoragePriceRange } from "./util";
1+
import { getCity, getDataStoragePriceRange } from "./util";
22
import { Alert, Checkbox, Select, Spin } from "antd";
33
import {
44
GOOGLE_CLOUD_BUCKET_STORAGE_CLASSES,
@@ -14,6 +14,7 @@ import { getRecentRegions } from "./regions";
1414
import { currency } from "@cocalc/util//misc";
1515
import { markup } from "@cocalc/util/compute/cloud/google-cloud/compute-cost";
1616
import { useGoogleCloudPriceData } from "@cocalc/frontend/compute/api";
17+
import { filterOption } from "@cocalc/frontend/compute/util";
1718

1819
export function BucketStorageClass({ configuration, setConfiguration }) {
1920
const [priceData] = useGoogleCloudPriceData();
@@ -68,7 +69,7 @@ export function BucketStorageClass({ configuration, setConfiguration }) {
6869
(bucket_storage_class) => {
6970
const { min, max } = getDataStoragePriceRange({
7071
...configuration,
71-
prices: priceData,
72+
priceData,
7273
bucket_storage_class,
7374
});
7475
return {
@@ -176,25 +177,34 @@ export function BucketLocation({ configuration, setConfiguration }) {
176177
let location;
177178
const { min, max } = getDataStoragePriceRange({
178179
...configuration,
179-
prices: priceData,
180+
priceData,
180181
bucket_location: region,
181182
});
182183
if (multiregion) {
183184
location = `${region.toUpperCase()} (Multiregion)`;
184185
} else {
185186
location = region;
186187
}
188+
const city = getCity({ region, priceData });
187189
const label = (
188190
<div style={{ display: "flex" }}>
189-
<div style={{ flex: 0.5 }}>{location}</div>
191+
<div style={{ flex: 0.6 }}>
192+
{location} ({city})
193+
</div>
190194
<div style={{ flex: 1, fontFamily: "monospace" }}>
191195
{min ? currency(min, 5) : null}
192196
{min != max && min && max ? ` - ${currency(max, 5)}` : null}
193-
{min && max ? " per GB per month at rest" : null}
197+
{min && max ? " / GB / month at rest" : null}
194198
</div>
195199
</div>
196200
);
197-
return { value: region, label, key: region, price: { min, max } };
201+
return {
202+
value: region,
203+
label,
204+
key: region,
205+
price: { min, max },
206+
search: `${city} ${location}`,
207+
};
198208
});
199209
if (!multiregion && (recentRegions?.length ?? 0) > 0) {
200210
const z = new Set(recentRegions);
@@ -242,6 +252,8 @@ export function BucketLocation({ configuration, setConfiguration }) {
242252
setConfiguration({ ...configuration, bucket_location });
243253
setMultiregion(!bucket_location?.includes("-"));
244254
}}
255+
optionFilterProp="children"
256+
filterOption={filterOption}
245257
/>
246258
<div
247259
style={{
Lines changed: 37 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { capitalize } from "@cocalc/util//misc";
2+
import { markup } from "@cocalc/util/compute/cloud/google-cloud/compute-cost";
23

34
export function editModalStyle(cloudFilesystem) {
45
return {
@@ -10,51 +11,74 @@ export function editModalStyle(cloudFilesystem) {
1011
};
1112
}
1213

14+
// Price returned from this includes markup
1315
export function getDataStoragePriceRange({
14-
prices,
16+
priceData,
1517
bucket_location,
1618
bucket_storage_class,
1719
}): { min: number | null; max: number | null } {
18-
if (prices == null) {
20+
if (priceData == null) {
1921
return { min: null, max: null };
2022
}
2123
if (bucket_storage_class.startsWith("autoclass")) {
2224
const min = getDataStoragePrice({
23-
prices,
25+
priceData,
2426
bucket_location,
2527
bucket_storage_class: bucket_storage_class.split("-")[1],
2628
});
2729
const max = getDataStoragePrice({
28-
prices,
30+
priceData,
2931
bucket_location,
3032
bucket_storage_class: "standard",
3133
});
3234
return { min, max };
3335
} else {
3436
const price = getDataStoragePrice({
35-
prices,
37+
priceData,
3638
bucket_location,
3739
bucket_storage_class,
3840
});
3941
return { min: price, max: price };
4042
}
4143
}
4244

45+
// Price returned from this includes markup
4346
export function getDataStoragePrice({
44-
prices,
47+
priceData,
4548
bucket_location,
4649
bucket_storage_class,
4750
}): number | null {
48-
if (prices == null) {
51+
if (priceData == null) {
4952
return null;
5053
}
54+
let cost;
5155
if (!bucket_location.includes("-")) {
52-
return prices.storage?.atRest?.multiRegions?.[bucket_location]?.[
53-
capitalize(bucket_storage_class)
54-
];
56+
cost =
57+
priceData.storage?.atRest?.multiRegions?.[bucket_location]?.[
58+
capitalize(bucket_storage_class)
59+
];
5560
} else {
56-
return prices.storage?.atRest?.regions?.[bucket_location]?.[
57-
capitalize(bucket_storage_class)
58-
];
61+
cost =
62+
priceData.storage?.atRest?.regions?.[bucket_location]?.[
63+
capitalize(bucket_storage_class)
64+
];
5965
}
66+
return markup({
67+
cost,
68+
priceData,
69+
});
70+
}
71+
72+
const alpha = "abcdefghijklmnopqrstuvwxyz".split("");
73+
export function getCity({ region, priceData }) {
74+
if (priceData?.zones == null) {
75+
return "";
76+
}
77+
for (const x of alpha) {
78+
const z = priceData.zones[`${region}-${x}`];
79+
if (z != null) {
80+
return z.location.split(",")[1].trim();
81+
}
82+
}
83+
return "";
6084
}

0 commit comments

Comments
 (0)