From ab9b748ee3af2d0526b3c56860aa2c4f568d0d67 Mon Sep 17 00:00:00 2001 From: afeefuddin Date: Mon, 15 Jul 2024 18:56:59 +0530 Subject: [PATCH] base_page_params: Update contributors schema in team_params_schema. --- web/src/base_page_params.ts | 16 +++++++++++++++- web/src/portico/team.ts | 14 ++++++++------ 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/web/src/base_page_params.ts b/web/src/base_page_params.ts index 81797da23b..bd163cd568 100644 --- a/web/src/base_page_params.ts +++ b/web/src/base_page_params.ts @@ -72,7 +72,21 @@ const stats_params_schema = default_params_schema.extend({ // Sync this with corporate.views.portico.team_view. const team_params_schema = default_params_schema.extend({ page_type: z.literal("team"), - contributors: z.unknown(), + contributors: z.optional( + z.array( + z + .object({ + avatar: z.string(), + github_username: z.optional(z.string()), + email: z.optional(z.string()), + name: z.optional(z.string()), + }) + // Repository names may change or increase over time, + // so we use this to parse the contributions of the user in + // the given repository instead of typing every name. + .catchall(z.number()), + ), + ), }); // Sync this with corporate.lib.stripe.UpgradePageParams. diff --git a/web/src/portico/team.ts b/web/src/portico/team.ts index db61d045e1..55e6e512cd 100644 --- a/web/src/portico/team.ts +++ b/web/src/portico/team.ts @@ -1,5 +1,6 @@ import $ from "jquery"; import _ from "lodash"; +import assert from "minimalistic-assert"; // The list of repository names is duplicated here in order to provide // a clear type for Contributor objects. @@ -70,17 +71,17 @@ const tab_name_to_repo_list: Record = { export type Contributor = { avatar: string; - email?: string; - github_username?: string; - name: string; + email?: string | undefined; + github_username?: string | undefined; + name?: string | undefined; } & { [K in RepositoryName]?: number; }; type ContributorData = { avatar: string; - email?: string; - github_username?: string; - name: string; + email?: string | undefined; + github_username?: string | undefined; + name?: string | undefined; total_commits: number; }; @@ -123,6 +124,7 @@ function get_display_name(contributor: Contributor): string { if (contributor.github_username) { return "@" + contributor.github_username; } + assert(contributor.name !== undefined); return contributor.name; }