Use base10 for sizes in frontend (#1133)

* Use base10 for sizes in frontend

* Simplify renderSize
This commit is contained in:
Tessa Walsh 2023-09-05 21:35:20 -04:00 committed by GitHub
parent 6dca2f1c03
commit 93573d0bfe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 29 deletions

View File

@ -95,35 +95,13 @@ export class ConfigDetails extends LiteElement {
>`; >`;
} }
}; };
const renderSize = (valueBytes?: number | null) => {
const renderSize = (valueBytes?: number | null, fallbackValue?: number) => {
const bytesPerGB = 1073741824;
// Eventually we will want to set this to the selected locale // Eventually we will want to set this to the selected locale
const formatter = new Intl.NumberFormat(undefined, {
style: "unit",
unit: "gigabyte",
unitDisplay: "narrow",
});
if (valueBytes) { if (valueBytes) {
const sizeGB = Math.floor(valueBytes / bytesPerGB); return html`<sl-format-bytes
return formatter.format(sizeGB); value=${valueBytes}
} display="narrow"
></sl-format-bytes>`;
if (typeof fallbackValue === "number") {
let value = "";
if (fallbackValue === Infinity) {
value = msg("Unlimited");
} else if (fallbackValue === 0) {
value = formatter.format(0);
} else {
const sizeGB = Math.floor(fallbackValue / bytesPerGB);
value = formatter.format(sizeGB);
}
return html`<span class="text-neutral-400"
>${value} ${msg("(default)")}</span
>`;
} }
return html`<span class="text-neutral-400" return html`<span class="text-neutral-400"
@ -205,7 +183,7 @@ export class ConfigDetails extends LiteElement {
)} )}
${this.renderSetting( ${this.renderSetting(
msg("Crawl Size Limit"), msg("Crawl Size Limit"),
renderSize(crawlConfig?.maxCrawlSize, Infinity) renderSize(crawlConfig?.maxCrawlSize)
)} )}
${this.renderSetting(msg("Crawler Instances"), crawlConfig?.scale)} ${this.renderSetting(msg("Crawler Instances"), crawlConfig?.scale)}
</btrix-desc-list> </btrix-desc-list>

View File

@ -215,7 +215,7 @@ const DEFAULT_BEHAVIORS = [
"autofetch", "autofetch",
"siteSpecific", "siteSpecific",
]; ];
const BYTES_PER_GB = 1073741824; const BYTES_PER_GB = 1e9;
@localized() @localized()
export class CrawlConfigEditor extends LiteElement { export class CrawlConfigEditor extends LiteElement {