Skip to content

Commit 6c461ee

Browse files
authored
Merge pull request #386 from developmentseed/limit-badges-column
Limit badges column to 3 badges in users table
2 parents 8666bec + fca635f commit 6c461ee

File tree

3 files changed

+32
-14
lines changed

3 files changed

+32
-14
lines changed

cypress/e2e/organizations/badges.cy.js

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,11 @@ const BADGES_COUNT = 30
2828
const org1Badges = generateSequenceArray(BADGES_COUNT, 1).map((i) => ({
2929
id: i,
3030
name: `Badge ${addZeroPadding(i, 3)}`,
31-
color: `rgba(255,0,0,${i / BADGES_COUNT})`,
31+
color: `rgba(255,0,0,${1 - i / BADGES_COUNT})`,
3232
}))
3333

34-
const [org1Badge1, org1Badge2, org1Badge3] = org1Badges
34+
const [org1Badge1, org1Badge2, org1Badge3, org1Badge4, org1Badge5, org1Badge6] =
35+
org1Badges
3536

3637
describe('Organization page', () => {
3738
before(() => {
@@ -59,21 +60,29 @@ describe('Organization page', () => {
5960
badges: org1Badges,
6061
})
6162

62-
// Assign badge 1 to the first five users
63+
// Assign badges to overlapping groups of users
6364
cy.task('db:seed:assign-badge-to-users', {
6465
badgeId: org1Badge1.id,
6566
users: org1Team1Members.slice(0, 4),
6667
})
67-
68-
// Assign badge 2 to five users, starting at user 3
6968
cy.task('db:seed:assign-badge-to-users', {
7069
badgeId: org1Badge2.id,
7170
users: org1Team1Members.slice(2, 7),
7271
})
73-
74-
// Assign badge 3 to five users, starting at user 5
7572
cy.task('db:seed:assign-badge-to-users', {
7673
badgeId: org1Badge3.id,
74+
users: org1Team1Members.slice(2, 7),
75+
})
76+
cy.task('db:seed:assign-badge-to-users', {
77+
badgeId: org1Badge4.id,
78+
users: org1Team1Members.slice(2, 7),
79+
})
80+
cy.task('db:seed:assign-badge-to-users', {
81+
badgeId: org1Badge5.id,
82+
users: org1Team1Members.slice(4, 9),
83+
})
84+
cy.task('db:seed:assign-badge-to-users', {
85+
badgeId: org1Badge6.id,
7786
users: org1Team1Members.slice(4, 9),
7887
})
7988
})
@@ -91,6 +100,6 @@ describe('Organization page', () => {
91100
.contains('Badge 003')
92101
cy.get('[data-cy=org-members-table]')
93102
.find('tbody tr:nth-child(10) td:nth-child(3)')
94-
.contains('Badge 003')
103+
.contains('Badge 005')
95104
})
96105
})

src/components/badge.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,12 @@ const hexToRgb = (hex) =>
1212
.map((x) => parseInt(x, 16))
1313
.join()
1414

15-
export default function Badge({ name, color, children }) {
15+
export default function Badge({ name, color, dot, children }) {
16+
let classes = [`badge`]
17+
if (dot) classes.push('dot')
18+
let classNames = classes.join(' ')
1619
return (
17-
<span className='badge'>
20+
<span className={classNames}>
1821
{children}
1922
{name}
2023
<style jsx>
@@ -30,10 +33,11 @@ export default function Badge({ name, color, children }) {
3033
font-size: 12px;
3134
white-space: nowrap;
3235
margin-right: 4px;
36+
line-height: initial;
3337
position: relative;
3438
overflow: hidden;
3539
}
36-
.badge::before {
40+
.badge.dot::before {
3741
content: '';
3842
background-color: ${color};
3943
box-shadow: 0 0 0 1px ${theme.colors.primaryLite};

src/components/tables/users.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ function UsersTable({ type, orgId, onRowClick, isSearchable }) {
1515
key: 'name',
1616
direction: 'asc',
1717
})
18-
18+
const MAX_BADGES_COLUMN = 3
1919
let apiBasePath
2020
let emptyMessage
2121
let columns
@@ -39,11 +39,16 @@ function UsersTable({ type, orgId, onRowClick, isSearchable }) {
3939
render: ({ badges }) => (
4040
<>
4141
{badges?.length > 0 &&
42-
badges.map((b) => (
43-
<Badge color={b.color} key={b.id}>
42+
badges.slice(0, MAX_BADGES_COLUMN).map((b) => (
43+
<Badge dot color={b.color} key={b.id}>
4444
{b.name}
4545
</Badge>
4646
))}
47+
{badges?.length > MAX_BADGES_COLUMN && (
48+
<Badge color='#222'>
49+
+{badges.slice(MAX_BADGES_COLUMN).length}
50+
</Badge>
51+
)}
4752
</>
4853
),
4954
},

0 commit comments

Comments
 (0)