diff --git a/nerdlets/maintainer-dashboard/index.js b/nerdlets/maintainer-dashboard/index.js index 38ef388..84d4a61 100644 --- a/nerdlets/maintainer-dashboard/index.js +++ b/nerdlets/maintainer-dashboard/index.js @@ -24,7 +24,8 @@ import { Button, Tabs, TabsItem, - BillboardChart + BillboardChart, + BlockText } from 'nr1'; import PullRequestLogo from './img/git-pull-request-16.svg'; import IssueLogo from './img/issue-opened-16.svg'; @@ -36,6 +37,20 @@ const RELICS = Object.values(NewRelicUsers) const STALE_TIME = 1000 * 60 * 60 * 24 * 14; // 2 weeks in ms +const KNOWN_LABEL_COLORS = new Map([ + ['bug', 'd73a4a'], + ['documentation', '0075ca'], + ['duplicate', 'cfd3d7'], + ['enhancement', 'a2eeef'], + ['good first issue', '7057ff'], + ['help wanted', '008672'], + ['invalid', 'e4e669'], + ['question', 'd876e3'], + ['wontfix', 'ffffff'], + ['dependencies', '0366d6'], + ['repolinter', 'fbca04'] +]) + const REPOS = [ 'newrelic/go-agent', 'newrelic/infrastructure-agent', @@ -101,6 +116,12 @@ fragment GetIssueInfo on Issue { name url } + labels(first: 100 orderBy: {field: NAME, direction: ASC}) { + nodes { + name + color + } + } number url createdAt @@ -117,6 +138,12 @@ fragment GetPRInfo on PullRequest { name url } + labels(first: 100 orderBy: {field: NAME, direction: ASC}) { + nodes { + name + color + } + } number url createdAt @@ -194,6 +221,16 @@ query SearchResults($queryDefStale: String! $queryMaybeStale: String! $timeSince ${PR_FRAGMENT} ${ISSUE_FRAGMENT}`; +// stolen from https://stackoverflow.com/questions/3942878/how-to-decide-font-color-in-white-or-black-depending-on-background-color +function pickTextColorBasedOnBgColor(bgColor, lightColor, darkColor) { + const color = (bgColor.charAt(0) === '#') ? bgColor.substring(1, 7) : bgColor; + const r = parseInt(color.substring(0, 2), 16); // hexToR + const g = parseInt(color.substring(2, 4), 16); // hexToG + const b = parseInt(color.substring(4, 6), 16); // hexToB + return (((r * 0.299) + (g * 0.587) + (b * 0.114)) > 186) ? + darkColor : lightColor; +} + function makeNewSearch(users, repos) { return `${repos.map(r => `repo:${r}`).join(' ')} ${users.map(u => `-author:${u} -commenter:${u}`).join(' ')} is:open` } @@ -264,6 +301,11 @@ class IssueTable extends React.Component { onClick={(e, s) => this._onClickTableHeaderCell('column_4', e, s)}> User + item.labels.nodes.map(l => l.name).join(' ')} + width="fit-content"> + Labels + item.title}> Title @@ -286,6 +328,33 @@ class IssueTable extends React.Component { humanizeDuration(Date.now() - new Date(item.createdAt).getTime(), { largest: 1 }) } {item.author.login} + { + item.labels.nodes.map(({name, color}) => { + const bgColor = KNOWN_LABEL_COLORS.has(name) ? KNOWN_LABEL_COLORS.get(name) : color; + return ( + + + {name} + + + )} + ) + } {item.title} )}