Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitf8b0c87

Browse files
fix: langs_count overflow when hide is set (anuraghazra#989)
1 parent7a096ac commitf8b0c87

File tree

5 files changed

+27
-21
lines changed

5 files changed

+27
-21
lines changed

‎api/top-langs.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ module.exports = async (req, res) => {
4646
try{
4747
topLangs=awaitfetchTopLanguages(
4848
username,
49-
langs_count,
5049
parseArray(exclude_repo),
5150
parseArray(hide),
5251
);
@@ -71,6 +70,7 @@ module.exports = async (req, res) => {
7170
bg_color,
7271
theme,
7372
layout,
73+
langs_count,
7474
border_radius,
7575
border_color,
7676
locale:locale ?locale.toLowerCase() :null,

‎src/cards/top-languages-card.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
constCard=require("../common/Card");
2-
const{ getCardColors, FlexLayout}=require("../common/utils");
2+
const{clampValue,getCardColors, FlexLayout}=require("../common/utils");
33
const{ createProgressNode}=require("../common/createProgressNode");
44
const{ langCardLocales}=require("../translations");
55
constI18n=require("../common/I18n");
@@ -73,8 +73,9 @@ const renderTopLanguages = (topLangs, options = {}) => {
7373
layout,
7474
custom_title,
7575
locale,
76+
langs_count=5,
7677
border_radius,
77-
border_color,
78+
border_color
7879
}=options;
7980

8081
consti18n=newI18n({
@@ -85,6 +86,8 @@ const renderTopLanguages = (topLangs, options = {}) => {
8586
letlangs=Object.values(topLangs);
8687
letlangsToHide={};
8788

89+
langsCount=clampValue(parseInt(langs_count),1,10);
90+
8891
// populate langsToHide map for quick lookup
8992
// while filtering out
9093
if(hide){
@@ -98,7 +101,8 @@ const renderTopLanguages = (topLangs, options = {}) => {
98101
.sort((a,b)=>b.size-a.size)
99102
.filter((lang)=>{
100103
return!langsToHide[lowercaseTrim(lang.name)];
101-
});
104+
})
105+
.slice(0,langsCount);
102106

103107
consttotalLanguageSize=langs.reduce((acc,curr)=>{
104108
returnacc+curr.size;

‎src/fetchers/top-languages-fetcher.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,10 @@ const fetcher = (variables, token) => {
3636

3737
asyncfunctionfetchTopLanguages(
3838
username,
39-
langsCount=5,
4039
exclude_repo=[],
4140
hide=[],
4241
){
4342
if(!username)throwError("Invalid username");
44-
langsCount=parseInt(langsCount)+hide.length;
45-
langsCount=clampValue(langsCount,1,10+hide.length);
4643

4744
constres=awaitretryer(fetcher,{login:username});
4845

@@ -97,7 +94,6 @@ async function fetchTopLanguages(
9794

9895
consttopLangs=Object.keys(repoNodes)
9996
.sort((a,b)=>repoNodes[b].size-repoNodes[a].size)
100-
.slice(0,langsCount)
10197
.reduce((result,key)=>{
10298
result[key]=repoNodes[key];
10399
returnresult;

‎tests/fetchTopLanguages.test.js

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -74,19 +74,6 @@ describe("FetchTopLanguages", () => {
7474
});
7575
});
7676

77-
it("should fetch langs with specified langs_count",async()=>{
78-
mock.onPost("https://api.github.com/graphql").reply(200,data_langs);
79-
80-
letrepo=awaitfetchTopLanguages("anuraghazra",1);
81-
expect(repo).toStrictEqual({
82-
javascript:{
83-
color:"#0ff",
84-
name:"javascript",
85-
size:200,
86-
},
87-
});
88-
});
89-
9077
it("should throw error",async()=>{
9178
mock.onPost("https://api.github.com/graphql").reply(200,error);
9279

‎tests/renderTopLanguages.test.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
require("@testing-library/jest-dom");
22
constcssToObject=require("css-to-object");
3+
constfetchTopLanguages=require("../src/fetchers/top-languages-fetcher");
34
constrenderTopLanguages=require("../src/cards/top-languages-card");
45

56
const{ queryByTestId, queryAllByTestId}=require("@testing-library/dom");
@@ -230,4 +231,22 @@ describe("Test renderTopLanguages", () => {
230231
document.body.innerHTML=renderTopLanguages(langs,{});
231232
expect(document.querySelector("rect")).toHaveAttribute("rx","4.5");
232233
});
234+
235+
it("should render langs with specified langs_count",async()=>{
236+
options={
237+
langs_count:1
238+
}
239+
document.body.innerHTML=renderTopLanguages(langs,{ ...options});
240+
expect(queryAllByTestId(document.body,"lang-name").length).toBe(options.langs_count)
241+
});
242+
243+
it("should render langs with specified langs_count even when hide is set",async()=>{
244+
options={
245+
hide:["HTML"],
246+
langs_count:2
247+
}
248+
document.body.innerHTML=renderTopLanguages(langs,{ ...options});
249+
expect(queryAllByTestId(document.body,"lang-name").length).toBe(options.langs_count)
250+
});
251+
233252
});

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp