mirror of https://github.com/zulip/zulip.git
gear_menu: Extract version_display_string into a util library.
This will keep changes to a minimum when we migrate gear menu to use tippy module.
This commit is contained in:
parent
8d42fa3960
commit
f91236f917
|
@ -2,7 +2,7 @@ import $ from "jquery";
|
|||
|
||||
import render_gear_menu from "../templates/gear_menu.hbs";
|
||||
|
||||
import {$t} from "./i18n";
|
||||
import * as gear_menu_util from "./gear_menu_util";
|
||||
import {page_params} from "./page_params";
|
||||
import * as settings_data from "./settings_data";
|
||||
|
||||
|
@ -79,37 +79,6 @@ The click handler uses "[data-overlay-trigger]" as
|
|||
the selector and then calls browser_history.go_to_location.
|
||||
*/
|
||||
|
||||
export function version_display_string(): string {
|
||||
const version = page_params.zulip_version;
|
||||
const is_fork = page_params.zulip_merge_base && page_params.zulip_merge_base !== version;
|
||||
|
||||
if (page_params.zulip_version.endsWith("-dev+git")) {
|
||||
// The development environment uses this version string format.
|
||||
return $t({defaultMessage: "Zulip Server dev environment"});
|
||||
}
|
||||
|
||||
if (is_fork) {
|
||||
// For forks, we want to describe the Zulip version this was
|
||||
// forked from, and that it was modified.
|
||||
const display_version = page_params.zulip_merge_base
|
||||
.replace(/\+git.*/, "")
|
||||
.replace(/-dev.*/, "-dev");
|
||||
return $t({defaultMessage: "Zulip Server {display_version} (modified)"}, {display_version});
|
||||
}
|
||||
|
||||
// The below cases are all for official versions; either a
|
||||
// release, or Git commit from one of Zulip's official branches.
|
||||
|
||||
if (version.includes("+git")) {
|
||||
// A version from a Zulip official maintenance branch such as 5.x.
|
||||
const display_version = version.replace(/\+git.*/, "");
|
||||
return $t({defaultMessage: "Zulip Server {display_version} (patched)"}, {display_version});
|
||||
}
|
||||
|
||||
const display_version = version.replace(/\+git.*/, "").replace(/-dev.*/, "-dev");
|
||||
return $t({defaultMessage: "Zulip Server {display_version}"}, {display_version});
|
||||
}
|
||||
|
||||
export function initialize(): void {
|
||||
const rendered_gear_menu = render_gear_menu({
|
||||
realm_name: page_params.realm_name,
|
||||
|
@ -124,7 +93,7 @@ export function initialize(): void {
|
|||
is_education_org: page_params.realm_org_type === 30 || page_params.realm_org_type === 35,
|
||||
standard_plan_name: "Zulip Cloud Standard",
|
||||
server_needs_upgrade: page_params.server_needs_upgrade,
|
||||
version_display_string: version_display_string(),
|
||||
version_display_string: gear_menu_util.version_display_string(),
|
||||
apps_page_url: page_params.apps_page_url,
|
||||
can_create_multiuse_invite: settings_data.user_can_create_multiuse_invite(),
|
||||
can_invite_users_by_email: settings_data.user_can_invite_users_by_email(),
|
||||
|
|
|
@ -0,0 +1,33 @@
|
|||
import {$t} from "./i18n";
|
||||
import {page_params} from "./page_params";
|
||||
|
||||
export function version_display_string(): string {
|
||||
const version = page_params.zulip_version;
|
||||
const is_fork = page_params.zulip_merge_base && page_params.zulip_merge_base !== version;
|
||||
|
||||
if (page_params.zulip_version.endsWith("-dev+git")) {
|
||||
// The development environment uses this version string format.
|
||||
return $t({defaultMessage: "Zulip Server dev environment"});
|
||||
}
|
||||
|
||||
if (is_fork) {
|
||||
// For forks, we want to describe the Zulip version this was
|
||||
// forked from, and that it was modified.
|
||||
const display_version = page_params.zulip_merge_base
|
||||
.replace(/\+git.*/, "")
|
||||
.replace(/-dev.*/, "-dev");
|
||||
return $t({defaultMessage: "Zulip Server {display_version} (modified)"}, {display_version});
|
||||
}
|
||||
|
||||
// The below cases are all for official versions; either a
|
||||
// release, or Git commit from one of Zulip's official branches.
|
||||
|
||||
if (version.includes("+git")) {
|
||||
// A version from a Zulip official maintenance branch such as 5.x.
|
||||
const display_version = version.replace(/\+git.*/, "");
|
||||
return $t({defaultMessage: "Zulip Server {display_version} (patched)"}, {display_version});
|
||||
}
|
||||
|
||||
const display_version = version.replace(/\+git.*/, "").replace(/-dev.*/, "-dev");
|
||||
return $t({defaultMessage: "Zulip Server {display_version}"}, {display_version});
|
||||
}
|
|
@ -6,7 +6,7 @@ const {zrequire} = require("./lib/namespace");
|
|||
const {run_test} = require("./lib/test");
|
||||
const {page_params} = require("./lib/zpage_params");
|
||||
|
||||
const gear_menu = zrequire("gear_menu");
|
||||
const gear_menu_util = zrequire("gear_menu_util");
|
||||
|
||||
run_test("version_display_string", () => {
|
||||
let expected_version_display_string;
|
||||
|
@ -15,53 +15,53 @@ run_test("version_display_string", () => {
|
|||
page_params.zulip_version = "5.6";
|
||||
page_params.zulip_merge_base = "5.6";
|
||||
expected_version_display_string = "translated: Zulip Server 5.6";
|
||||
assert.equal(gear_menu.version_display_string(), expected_version_display_string);
|
||||
assert.equal(gear_menu_util.version_display_string(), expected_version_display_string);
|
||||
|
||||
// An official beta
|
||||
page_params.zulip_version = "6.0-beta1";
|
||||
page_params.zulip_merge_base = "6.0-beta1";
|
||||
expected_version_display_string = "translated: Zulip Server 6.0-beta1";
|
||||
assert.equal(gear_menu.version_display_string(), expected_version_display_string);
|
||||
assert.equal(gear_menu_util.version_display_string(), expected_version_display_string);
|
||||
|
||||
// An official release candidate
|
||||
page_params.zulip_version = "6.0-rc1";
|
||||
page_params.zulip_merge_base = "6.0-rc1";
|
||||
expected_version_display_string = "translated: Zulip Server 6.0-rc1";
|
||||
assert.equal(gear_menu.version_display_string(), expected_version_display_string);
|
||||
assert.equal(gear_menu_util.version_display_string(), expected_version_display_string);
|
||||
|
||||
// The Zulip development environment
|
||||
page_params.zulip_version = "6.0-dev+git";
|
||||
page_params.zulip_merge_base = "6.0-dev+git";
|
||||
expected_version_display_string = "translated: Zulip Server dev environment";
|
||||
assert.equal(gear_menu.version_display_string(), expected_version_display_string);
|
||||
assert.equal(gear_menu_util.version_display_string(), expected_version_display_string);
|
||||
|
||||
// A commit on Zulip's main branch.
|
||||
page_params.zulip_version = "6.0-dev-1976-g4bb381fc80";
|
||||
page_params.zulip_merge_base = "6.0-dev-1976-g4bb381fc80";
|
||||
expected_version_display_string = "translated: Zulip Server 6.0-dev";
|
||||
assert.equal(gear_menu.version_display_string(), expected_version_display_string);
|
||||
assert.equal(gear_menu_util.version_display_string(), expected_version_display_string);
|
||||
|
||||
// A fork with 18 commits beyond Zulip's main branch.
|
||||
page_params.zulip_version = "6.0-dev-1994-g93730766b0";
|
||||
page_params.zulip_merge_base = "6.0-dev-1976-g4bb381fc80";
|
||||
expected_version_display_string = "translated: Zulip Server 6.0-dev (modified)";
|
||||
assert.equal(gear_menu.version_display_string(), expected_version_display_string);
|
||||
assert.equal(gear_menu_util.version_display_string(), expected_version_display_string);
|
||||
|
||||
// A commit from the Zulip 5.x branch
|
||||
page_params.zulip_version = "5.6+git-4-g385a408be5";
|
||||
page_params.zulip_merge_base = "5.6+git-4-g385a408be5";
|
||||
expected_version_display_string = "translated: Zulip Server 5.6 (patched)";
|
||||
assert.equal(gear_menu.version_display_string(), expected_version_display_string);
|
||||
assert.equal(gear_menu_util.version_display_string(), expected_version_display_string);
|
||||
|
||||
// A fork with 3 commits beyond the Zulip 5.x branch.
|
||||
page_params.zulip_version = "5.6+git-4-g385a408be5";
|
||||
page_params.zulip_merge_base = "5.6+git-7-abcda4235c2";
|
||||
expected_version_display_string = "translated: Zulip Server 5.6 (modified)";
|
||||
assert.equal(gear_menu.version_display_string(), expected_version_display_string);
|
||||
assert.equal(gear_menu_util.version_display_string(), expected_version_display_string);
|
||||
|
||||
// A fork of a Zulip release commit, not on 5.x branch.
|
||||
page_params.zulip_version = "5.3-1-g7ed896c0db";
|
||||
page_params.zulip_merge_base = "5.3";
|
||||
expected_version_display_string = "translated: Zulip Server 5.3 (modified)";
|
||||
assert.equal(gear_menu.version_display_string(), expected_version_display_string);
|
||||
assert.equal(gear_menu_util.version_display_string(), expected_version_display_string);
|
||||
});
|
Loading…
Reference in New Issue