Skip to content

Commit

Permalink
wrap label into function
Browse files Browse the repository at this point in the history
  • Loading branch information
vzsky committed Jan 25, 2024
1 parent 4c3629b commit b60aa8f
Showing 1 changed file with 22 additions and 14 deletions.
36 changes: 22 additions & 14 deletions src/cards/stats-card.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,20 @@ const getStyles = ({
`;
};

/**
* Return the label for commits according to the selected options
*
* @param {boolean} include_all_commits Option to include all years
* @param {number|undefined} commits_year Option to include only selected year
* @returns {string} The label corresponding to the options.
*/
const getTotalCommitsYearLabel = (include_all_commits, commits_year) =>
include_all_commits
? ""
: commits_year
? ` (${commits_year})`
: ` (last year)`;

/**
* @typedef {import('../fetchers/types').StatsData} StatsData
* @typedef {import('./types').StatCardOptions} StatCardOptions
Expand Down Expand Up @@ -274,13 +288,10 @@ const renderStatsCard = (stats, options = {}) => {
};
STATS.commits = {
icon: icons.commits,
label: `${i18n.t("statcard.commits")}${
include_all_commits
? ""
: commits_year
? ` (${commits_year})`
: ` (last year)`
}`,
label: `${i18n.t("statcard.commits")}${getTotalCommitsYearLabel(
include_all_commits,
commits_year,
)}`,
value: totalCommits,
id: "commits",
};
Expand Down Expand Up @@ -521,13 +532,10 @@ const renderStatsCard = (stats, options = {}) => {
.filter((key) => !hide.includes(key))
.map((key) => {
if (key === "commits") {
return `${i18n.t("statcard.commits")} ${
include_all_commits
? ""
: commits_year
? ` (${commits_year})`
: ` (last year)`
} : ${totalStars}`;
return `${i18n.t("statcard.commits")} ${getTotalCommitsYearLabel(
include_all_commits,
commits_year,
)} : ${totalStars}`;
}
return `${STATS[key].label}: ${STATS[key].value}`;
})
Expand Down

0 comments on commit b60aa8f

Please sign in to comment.