Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhance/table styles #420

Merged
merged 10 commits into from
Mar 16, 2023
6 changes: 3 additions & 3 deletions cypress/e2e/organizations/badges.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,13 @@ describe('Organization page', () => {
cy.visit('/organizations/1')

cy.get('[data-cy=org-members-table]')
.find('tbody tr:nth-child(6) td:nth-child(3)')
.find('tbody tr:nth-child(6) td:nth-child(2)')
.contains('Badge 002')
cy.get('[data-cy=org-members-table]')
.find('tbody tr:nth-child(6) td:nth-child(3)')
.find('tbody tr:nth-child(6) td:nth-child(2)')
.contains('Badge 003')
cy.get('[data-cy=org-members-table]')
.find('tbody tr:nth-child(10) td:nth-child(3)')
.find('tbody tr:nth-child(10) td:nth-child(2)')
.contains('Badge 005')
})
})
1 change: 1 addition & 0 deletions public/static/osmcha-logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion src/components/badge.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export default function Badge({ color, dot, children }) {
color={color}
bg={`rgba(${hexToRgb(color)}, 0.125)`}
size='sm'
borderRadius={'full'}
borderRadius={dot ? 'full' : 'sm'}
boxShadow={`0 0 0 1px rgba(${hexToRgb(color)}, 0.25)`}
mr={2}
overflow='hidden'
Expand Down
3 changes: 2 additions & 1 deletion src/components/external-profile-button.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const ExternalProfileButton = ({ type, userId }) => {
title = 'View profile on OSMCha'
label = 'OSMCha'
altText = 'OSMCha Logo'
logoImg = 'icon-osmcha-logo.svg'
logoImg = 'osmcha-logo.svg'
break
default:
return null
Expand All @@ -60,6 +60,7 @@ const ExternalProfileButton = ({ type, userId }) => {
target='_blank'
title={title}
size='sm'
bg='white'
variant='ghost'
>
<img
Expand Down
77 changes: 64 additions & 13 deletions src/components/tables/members-table.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ import Table from './table'
import join from 'url-join'
import { useState } from 'react'
import {
Button,
Flex,
Menu,
MenuButton,
MenuList,
MenuItem,
useToken,
Text,
IconButton,
} from '@chakra-ui/react'

import Pagination from '../pagination'
Expand All @@ -21,6 +22,9 @@ import ExternalProfileButton from '../external-profile-button'
import Badge from '../badge'
import { makeTitleCase } from '../../../app/lib/utils'
import { includes, map, prop, insert, append, contains } from 'ramda'
import { IoEllipsisHorizontal } from 'react-icons/io5'
import { InfoOutlineIcon } from '@chakra-ui/icons'

const SCOREBOARD_URL = process.env.SCOREBOARD_URL
const HDYC_URL = process.env.HDYC_URL
const APP_URL = process.env.APP_URL
Expand Down Expand Up @@ -100,12 +104,34 @@ function MembersTable({
key: 'name',
sortable: true,
render: (user) => (
<Button size='md' variant='link' onClick={() => onUsernameClick(user)}>
{user.name}
</Button>
<Flex flexDir='column'>
<Text
fontWeight='bold'
fontFamily={'body'}
as='a'
display='flex'
gap={1}
onClick={() => onUsernameClick(user)}
_hover={{ cursor: 'pointer' }}
title='Display user profile'
data-component-name='username'
>
{user.name}
<InfoOutlineIcon
opacity={0}
transition='opacity 0.12s ease-in'
sx={{
'[data-component-name="username"]:hover &': {
opacity: 'initial',
},
}}
alignSelf='center'
/>
</Text>
<Text color='blackAlpha.600'>{user.id}</Text>
</Flex>
),
},
{ key: 'id', sortable: true },
{
key: 'role',
label: 'role',
Expand All @@ -118,15 +144,34 @@ function MembersTable({
{
key: 'External Profiles',
render: ({ id, name }) => (
<Flex>
<ExternalProfileButton type='osm-profile' userId={name} />
<Flex gap={1} justifyContent='center'>
<ExternalProfileButton
type='osm-profile'
userId={name}
title='Visit OSM profile'
/>
{SCOREBOARD_URL && (
<ExternalProfileButton type='scoreboard' userId={id} />
<ExternalProfileButton
type='scoreboard'
userId={id}
title='Visit Scoreboard profile'
/>
)}
{HDYC_URL && (
<ExternalProfileButton
type='hdyc'
userId={name}
title='Visit HDYC profile'
/>
)}
{HDYC_URL && <ExternalProfileButton type='hdyc' userId={name} />}
<ExternalProfileButton type='osmcha' userId={name} />
<ExternalProfileButton
type='osmcha'
userId={name}
title='Visit OSMCha profile'
/>
</Flex>
),
alignment: 'center',
},
]

Expand Down Expand Up @@ -195,9 +240,14 @@ function MembersTable({
}
return (
<Menu>
<MenuButton as={Button} size='sm' variant='outline'>
</MenuButton>
<MenuButton
as={IconButton}
size='sm'
variant='ghost'
aria-label='User actions menu'
title='Display user actions menu'
icon={<IoEllipsisHorizontal />}
/>
<MenuList>
{actions.map((action) => {
return (
Expand All @@ -214,6 +264,7 @@ function MembersTable({
</Menu>
)
},
alignment: 'center',
}

if (displayBadges) {
Expand Down
53 changes: 35 additions & 18 deletions src/components/tables/table.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ function TableHead({ dataCy, columns, sort, setSort, onClick }) {
return (
<Thead>
<Tr>
{columns.map(({ sortable, label, key }) => {
{columns.map(({ sortable, label, key, alignment }) => {
const isSorted = sortable && sort.key === key
const currentSortDirection = (isSorted && sort.direction) || 'none'
const nextSortDirection =
Expand Down Expand Up @@ -49,7 +49,7 @@ function TableHead({ dataCy, columns, sort, setSort, onClick }) {
verticalAlign='middle'
position='relative'
textTransform='uppercase'
textAlign='left'
textAlign={alignment ? alignment : 'left'}
fontFamily='mono'
fontWeight='base'
fontSize='sm'
Expand All @@ -58,15 +58,21 @@ function TableHead({ dataCy, columns, sort, setSort, onClick }) {
borderBottom='4px solid var(--chakra-colors-brand-600)'
cursor={sortable && 'pointer'}
_hover={sortable && { fontWeight: 'bold', color: 'brand.500' }}
_first={[
null,
{
_first={{
base: {
position: 'sticky',
left: '0',
zIndex: '2',
background: 'brand.50',
borderRight: '2px solid var(--chakra-colors-brand-100)',
},
]}
md: {
position: 'initial',
left: 'initial',
zIndex: 'initial',
borderRight: 'none',
},
}}
>
{label || key}
{sortable && sortIcon}
Expand All @@ -87,7 +93,7 @@ function Row({ columns, row, index, onRowClick, showRowNumber }) {
}}
role='group'
>
{columns.map(({ key, render }) => {
{columns.map(({ key, render, alignment }) => {
let item =
typeof render === 'function' ? render(row, index, columns) : row[key]
if (showRowNumber && key === ' ') {
Expand All @@ -97,26 +103,31 @@ function Row({ columns, row, index, onRowClick, showRowNumber }) {
<Td
width={showRowNumber && key === ' ' && '1rem'}
padding='0.875rem'
borderBottom={1}
borderColor='brand.800'
boxShadow='inset 0 -1px 0 0 var(--chakra-colors-brand-50)'
fontSize='0.9rem'
textAlign={alignment ? alignment : 'left'}
_groupHover={
onRowClick && {
cursor: 'pointer',
background: 'brand.50',
color: 'brand.500',
}
}
_first={[
null,
{
_first={{
base: {
position: 'sticky',
left: '0',
background: 'white',
zIndex: '2',
bg: 'white',
borderRight: '2px solid var(--chakra-colors-brand-100)',
},
]}
md: {
position: 'initial',
left: 'initial',
zIndex: 'initial',
borderRight: 'none',
},
}}
key={`row-${index}-key-${key}`}
>
{item}
Expand Down Expand Up @@ -185,11 +196,17 @@ export default function Table({
>
<BaseTable
data-cy={dataCy}
borderCollapse={['collapse', 'separate']}
borderSpacing='0'
marginBottom={2}
tableLayout='fixed'
whiteSpace='pre'
layout='fixed'
size='sm'
width='initial'
sx={{
base: {
borderSpacing: '0',
borderCollapse: 'separate',
},
md: { borderCollapse: 'collapse' },
}}
>
<TableHead
dataCy={dataCy}
Expand Down
Loading