Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

portico-team: Rework repository on team page

afeefuddina41c39db26cf
diff --git a/templates/corporate/team.html b/templates/corporate/team.html
index ce228391d4a..998b857f200 100644
--- a/templates/corporate/team.html
+++ b/templates/corporate/team.html
@@ -167,11 +167,13 @@ contributors, and more than 75 with 100+ commits." %}
<script type="text/template" id="count-template">
<p class="contributor-count">
- <%= contributor_count %> contributors to
- <a href="<%= repo_url %>" target="_blank" rel="noopener noreferrer">
- zulip/<%= repo_name %>
+ <%= contributor_count %> contributors
+ (<%= hundred_plus_contributor_count %> with 100+ commits) to
+ <% repo_list.forEach(function(repo_name, index) { %>
+ <a href="<%= repo_url_list[index] %>" target="_blank" rel="noopener noreferrer">
+ zulip/<%= repo_name %><% if (index < repo_list.length - 1) { %>, <% } %>
</a>
- (<%= hundred_plus_contributor_count %> with 100+ commits)
+ <% }); %>
</p>
</script>
diff --git a/web/src/portico/team.ts b/web/src/portico/team.ts
index d05c2e2f080..81ed8f91057 100644
--- a/web/src/portico/team.ts
+++ b/web/src/portico/team.ts
@@ -17,19 +17,30 @@ const all_repository_names = [
"zulip-terminal",
"zulip-ios-legacy",
"zulip-android",
+ "zulip-flutter",
+] as const;
+
+const all_tab_names = [
+ "server",
+ "desktop",
+ "mobile",
+ "zulip-js",
+ "python-zulip-api",
+ "zulipbot",
+ "terminal",
] as const;
-type RepositoryName = (typeof all_repository_names)[number];
-const repo_name_to_tab_name: Record<RepositoryName, string> = {
- zulip: "server",
- "zulip-desktop": "desktop",
- "zulip-mobile": "mobile",
- "python-zulip-api": "python-zulip-api",
- "zulip-js": "zulip-js",
- zulipbot: "zulipbot",
- "zulip-terminal": "terminal",
- "zulip-ios-legacy": "",
- "zulip-android": "",
+type RepositoryName = (typeof all_repository_names)[number];
+type TabName = (typeof all_tab_names)[number];
+
+const tab_name_to_repo_list: Record<TabName, RepositoryName[]> = {
+ server: ["zulip"],
+ desktop: ["zulip-desktop"],
+ mobile: ["zulip-mobile", "zulip-flutter", "zulip-ios-legacy", "zulip-android"],
+ "zulip-js": ["zulip-js"],
+ "python-zulip-api": ["python-zulip-api"],
+ zulipbot: ["zulipbot"],
+ terminal: ["zulip-terminal"],
};
export type Contributor = {
@@ -40,10 +51,17 @@ export type Contributor = {
} & {
[K in RepositoryName]?: number;
};
+type ContributorData = {
+ avatar: string;
+ email?: string;
+ github_username?: string;
+ name: string;
+ total_commits: number;
+};
// Remember the loaded repositories so that HTML is not redundantly edited
// if a user leaves and then revisits the same tab.
-const loaded_repos: string[] = [];
+const loaded_tabs: string[] = [];
function calculate_total_commits(contributor: Contributor): number {
let commits = 0;
@@ -67,7 +85,7 @@ function get_profile_url(contributor: Contributor, tab_name?: string): string |
return `https://github.com/zulip/${tab_name}/commits?author=${email}`;
}
- for (const repo_name in repo_name_to_tab_name) {
+ for (const repo_name of all_repository_names) {
if (repo_name in contributor) {
return `https://github.com/zulip/${repo_name}/commits?author=${email}`;
}
@@ -122,21 +140,33 @@ export default function render_tabs(contributors: Contributor[]): void {
}),
);
- for (const repo_name of all_repository_names) {
- const tab_name = repo_name_to_tab_name[repo_name];
- if (!tab_name) {
+ for (const tab_name of all_tab_names) {
+ const repo_list = tab_name_to_repo_list[tab_name];
+ if (!repo_list) {
continue;
}
// Set as the loading template for now, and load when clicked.
$(`#tab-${CSS.escape(tab_name)} .contributors-grid`).html($("#loading-template").html());
$(`#${CSS.escape(tab_name)}`).on("click", () => {
- if (!loaded_repos.includes(repo_name)) {
- const filtered_by_repo = contributors_list.filter((c) => c[repo_name] ?? 0);
- const html = filtered_by_repo
+ if (!loaded_tabs.includes(tab_name)) {
+ const filtered_by_tab: ContributorData[] = contributors_list
+ .filter((c: Contributor) =>
+ repo_list.some((repo_name: RepositoryName) => c[repo_name] !== undefined),
+ )
+ .map((c: Contributor) => ({
+ ..._.pick(c, "avatar", "email", "name", "github_username"),
+ total_commits: repo_list.reduce(
+ (commits: number, repo_name: RepositoryName) =>
+ commits + (c[repo_name] ?? 0),
+ 0,
+ ),
+ }));
+
+ const html = filtered_by_tab
.sort((a, b) => {
- const a_commits = a[repo_name] ?? 0;
- const b_commits = b[repo_name] ?? 0;
+ const a_commits = a.total_commits;
+ const b_commits = b.total_commits;
return a_commits < b_commits ? 1 : a_commits > b_commits ? -1 : 0;
})
.map((c) =>
@@ -145,28 +175,30 @@ export default function render_tabs(contributors: Contributor[]): void {
github_username: c.github_username,
avatar: c.avatar,
profile_url: get_profile_url(c, tab_name),
- commits: c[repo_name],
+ commits: c.total_commits,
}),
)
.join("");
$(`#tab-${CSS.escape(tab_name)} .contributors-grid`).html(html);
- const contributor_count = filtered_by_repo.length;
- const hundred_plus_contributor_count = filtered_by_repo.filter((c) => {
- const commits = c[repo_name] ?? 0;
+ const contributor_count = filtered_by_tab.length;
+ const hundred_plus_contributor_count = filtered_by_tab.filter((c) => {
+ const commits = c.total_commits;
return commits >= 100;
}).length;
- const repo_url = `https://github.com/zulip/${repo_name}`;
+ const repo_url_list = repo_list.map(
+ (repo_name) => `https://github.com/zulip/${repo_name}`,
+ );
$(`#tab-${CSS.escape(tab_name)}`).prepend(
count_template({
contributor_count,
- repo_name,
- repo_url,
+ repo_list,
+ repo_url_list,
hundred_plus_contributor_count,
}),
);
- loaded_repos.push(repo_name);
+ loaded_tabs.push(tab_name);
}
});
}