Skip to content

Commit d5dc90a

Browse files
pull[bot]qimolinrickstaa
authored
[pull] master from anuraghazra:master (#80)
* feat: add min width languages card (anuraghazra#1953) * Add min width to languages card * Add test for min width languages card * feat: increase lang card min width Co-authored-by: Rick Staa <[email protected]> * ci: add top-issues-dashboard action This commit adds the top issues dashboard action which creates a issue displaying the top issues of the week. * ci: fix title of top-issues action Co-authored-by: Qi Mo Lin <[email protected]> Co-authored-by: Rick Staa <[email protected]>
1 parent 8d5f2da commit d5dc90a

File tree

3 files changed

+48
-7
lines changed

3 files changed

+48
-7
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
name: Update top issues dashboard
2+
on:
3+
schedule:
4+
- cron: "0 0 */7 * *"
5+
6+
jobs:
7+
showAndLabelTopIssues:
8+
name: Update top issues Dashboard.
9+
runs-on: ubuntu-latest
10+
steps:
11+
- name: Run top issues action
12+
uses: rickstaa/top-issues-action@v1
13+
env:
14+
github_token: ${{ secrets.GITHUB_TOKEN }}
15+
label: false
16+
dashboard: true
17+
top_issues: true
18+
top_bugs: true
19+
top_features: true
20+
top_pull_requests: true

src/cards/top-languages-card.js

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ const {
1313
} = require("../common/utils");
1414

1515
const DEFAULT_CARD_WIDTH = 300;
16+
const MIN_CARD_WIDTH = 230;
1617
const DEFAULT_LANGS_COUNT = 5;
1718
const DEFAULT_LANG_COLOR = "#858585";
1819
const CARD_PADDING = 25;
@@ -24,12 +25,12 @@ const CARD_PADDING = 25;
2425
/**
2526
* @param {Lang[]} arr
2627
*/
27-
const getLongestLang = (arr) =>
28-
arr.reduce(
29-
(savedLang, lang) =>
30-
lang.name.length > savedLang.name.length ? lang : savedLang,
31-
{ name: "", size: null, color: "" },
32-
);
28+
const getLongestLang = (arr) =>
29+
arr.reduce(
30+
(savedLang, lang) =>
31+
lang.name.length > savedLang.name.length ? lang : savedLang,
32+
{ name: "", size: null, color: "" },
33+
);
3334

3435
/**
3536
* @param {{
@@ -261,7 +262,11 @@ const renderTopLanguages = (topLangs, options = {}) => {
261262
String(langs_count),
262263
);
263264

264-
let width = isNaN(card_width) ? DEFAULT_CARD_WIDTH : card_width;
265+
let width = isNaN(card_width)
266+
? DEFAULT_CARD_WIDTH
267+
: card_width < MIN_CARD_WIDTH
268+
? MIN_CARD_WIDTH
269+
: card_width;
265270
let height = calculateNormalLayoutHeight(langs.length);
266271

267272
let finalLayout = "";
@@ -307,3 +312,4 @@ const renderTopLanguages = (topLangs, options = {}) => {
307312
};
308313

309314
module.exports = renderTopLanguages;
315+
module.exports.MIN_CARD_WIDTH = MIN_CARD_WIDTH;

tests/renderTopLanguages.test.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,21 @@ describe("Test renderTopLanguages", () => {
103103
expect(document.querySelector("svg")).toHaveAttribute("width", "400");
104104
});
105105

106+
it("should render with min width", () => {
107+
document.body.innerHTML = renderTopLanguages(langs, { card_width: 190 });
108+
109+
expect(document.querySelector("svg")).toHaveAttribute(
110+
"width",
111+
renderTopLanguages.MIN_CARD_WIDTH.toString(),
112+
);
113+
114+
document.body.innerHTML = renderTopLanguages(langs, { card_width: 100 });
115+
expect(document.querySelector("svg")).toHaveAttribute(
116+
"width",
117+
renderTopLanguages.MIN_CARD_WIDTH.toString(),
118+
);
119+
});
120+
106121
it("should render default colors properly", () => {
107122
document.body.innerHTML = renderTopLanguages(langs);
108123

0 commit comments

Comments
 (0)