mirror of
https://github.com/zulip/zulip.git
synced 2025-11-06 15:03:34 +00:00
page_params: Split out state data for realm.
For spectators, the chunk of page_params that originates from do_events_register isn’t assigned until ui_init.js. That means the TypeScript type of page_params is mostly a lie during module load time: reading a parameter too early silently results in undefined rather than the declared type, with unpredictable results later on. We want to make such an early read into an immediate runtime error, for both users and spectators consistently, and pave the way for runtime validation of the page_params type. As a second step, split out the subset of fields that pertain to the entire realm. Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
committed by
Tim Abbott
parent
e96ede0ef6
commit
b9e62c7af8
@@ -10,8 +10,8 @@ import * as dialog_widget from "./dialog_widget";
|
||||
import {$t, $t_html} from "./i18n";
|
||||
import * as ListWidget from "./list_widget";
|
||||
import * as loading from "./loading";
|
||||
import {page_params} from "./page_params";
|
||||
import * as scroll_util from "./scroll_util";
|
||||
import {realm} from "./state_data";
|
||||
import * as timerender from "./timerender";
|
||||
import * as ui_report from "./ui_report";
|
||||
|
||||
@@ -71,20 +71,20 @@ export function bytes_to_size(bytes: number, kb_with_1024_bytes = false): string
|
||||
}
|
||||
|
||||
export function percentage_used_space(uploads_size: number): string | null {
|
||||
if (page_params.realm_upload_quota_mib === null) {
|
||||
if (realm.realm_upload_quota_mib === null) {
|
||||
return null;
|
||||
}
|
||||
return ((100 * uploads_size) / page_params.realm_upload_quota_mib).toFixed(1);
|
||||
return ((100 * uploads_size) / realm.realm_upload_quota_mib).toFixed(1);
|
||||
}
|
||||
|
||||
function set_upload_space_stats(): void {
|
||||
if (page_params.realm_upload_quota_mib === null) {
|
||||
if (realm.realm_upload_quota_mib === null) {
|
||||
return;
|
||||
}
|
||||
const args = {
|
||||
show_upgrade_message: page_params.realm_plan_type === 2,
|
||||
show_upgrade_message: realm.realm_plan_type === 2,
|
||||
percent_used: percentage_used_space(upload_space_used),
|
||||
upload_quota: bytes_to_size(page_params.realm_upload_quota_mib, true),
|
||||
upload_quota: bytes_to_size(realm.realm_upload_quota_mib, true),
|
||||
};
|
||||
const rendered_upload_stats_html = render_settings_upload_space_stats(args);
|
||||
$("#attachment-stats-holder").html(rendered_upload_stats_html);
|
||||
|
||||
Reference in New Issue
Block a user