fix: langs_count overflow when hide is set (#989)

This commit is contained in:
Florian Bussmann
2021-05-07 00:31:04 +05:30
committed by GitHub
parent 7a096acf66
commit f8b0c8767e
5 changed files with 27 additions and 21 deletions
+7 -3
View File
@@ -1,5 +1,5 @@
const Card = require("../common/Card");
const { getCardColors, FlexLayout } = require("../common/utils");
const { clampValue, getCardColors, FlexLayout } = require("../common/utils");
const { createProgressNode } = require("../common/createProgressNode");
const { langCardLocales } = require("../translations");
const I18n = require("../common/I18n");
@@ -73,8 +73,9 @@ const renderTopLanguages = (topLangs, options = {}) => {
layout,
custom_title,
locale,
langs_count = 5,
border_radius,
border_color,
border_color
} = options;
const i18n = new I18n({
@@ -85,6 +86,8 @@ const renderTopLanguages = (topLangs, options = {}) => {
let langs = Object.values(topLangs);
let langsToHide = {};
langsCount = clampValue(parseInt(langs_count), 1, 10);
// populate langsToHide map for quick lookup
// while filtering out
if (hide) {
@@ -98,7 +101,8 @@ const renderTopLanguages = (topLangs, options = {}) => {
.sort((a, b) => b.size - a.size)
.filter((lang) => {
return !langsToHide[lowercaseTrim(lang.name)];
});
})
.slice(0, langsCount);
const totalLanguageSize = langs.reduce((acc, curr) => {
return acc + curr.size;