Skip to content

Commit 03755be

Browse files
committed
Limit badges column to 3 badges in users table
1 parent 8666bec commit 03755be

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

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)