Skip to content

Commit

Permalink
fix: fix commit stats time frame description #1053
Browse files Browse the repository at this point in the history
This commit makes sure the last year label is shown when
`include_all_commits` or `year` is not provided. See #1053 for more
information.
  • Loading branch information
rickstaa committed Oct 16, 2022
1 parent af6553e commit de4cefa
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 8 deletions.
11 changes: 4 additions & 7 deletions src/cards/stats-card.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,7 @@ const renderStatsCard = (stats = {}, options = { hide: [] }) => {
commits: {
icon: icons.commits,
label: `${i18n.t("statcard.commits")}${
include_all_commits
? ""
: year
? ` (${year})`
: ` (${new Date().getFullYear()})`
include_all_commits ? "" : year ? ` (${year})` : ` (last year)`
}`,
value: totalCommits,
id: "commits",
Expand Down Expand Up @@ -188,7 +184,8 @@ const renderStatsCard = (stats = {}, options = { hide: [] }) => {
index,
showIcons: show_icons,
shiftValuePos:
(!include_all_commits ? 50 : 35) + (isLongLocale ? 50 : 0),
(include_all_commits ? 35 : year ? 50 : 80.22) +
(isLongLocale ? 50 : 0),
bold: text_bold,
}),
);
Expand Down Expand Up @@ -296,7 +293,7 @@ const renderStatsCard = (stats = {}, options = { hide: [] }) => {
.map((key) => {
if (key === "commits") {
return `${i18n.t("statcard.commits")} ${
include_all_commits ? "" : `in ${new Date().getFullYear()}`
include_all_commits ? "" : year ? ` (${year})` : ` (last year)`
} : ${totalStars}`;
}
return `${STATS[key].label}: ${STATS[key].value}`;
Expand Down
2 changes: 1 addition & 1 deletion tests/renderStatsCard.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ describe("Test renderStatsCard", () => {
document.querySelector(
'g[transform="translate(0, 25)"]>.stagger>.stat.bold',
).textContent,
).toMatchInlineSnapshot(`"累计提交数(commit) (2022):"`);
).toMatchInlineSnapshot(`"累计提交数(commit) (last year):"`);
expect(
document.querySelector(
'g[transform="translate(0, 50)"]>.stagger>.stat.bold',
Expand Down

0 comments on commit de4cefa

Please sign in to comment.