Skip to content

Commit

Permalink
Make a dictionary of sorting options
Browse files Browse the repository at this point in the history
  • Loading branch information
tianrunhe committed Aug 21, 2024
1 parent 57c8b05 commit 33b6b8a
Showing 1 changed file with 24 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,23 +26,18 @@ interface Props {
queryRef: PreloadedQuery<OrgMembersQuery>
}

const sortOptions = {
'lastSeenAt-desc': 'Last Seen ▼',
'lastSeenAt-asc': 'Last Seen ▲',
'preferredName-asc': 'Name ▲',
'preferredName-desc': 'Name ▼',
'email-asc': 'Email ▲',
'email-desc': 'Email ▼'
}

const getSortLabel = (sortBy: string, sortDirection: string) => {
switch (`${sortBy}-${sortDirection}`) {
case 'lastSeenAt-desc':
return 'Last Seen ▼'
case 'lastSeenAt-asc':
return 'Last Seen ▲'
case 'preferredName-asc':
return 'Name ▲'
case 'preferredName-desc':
return 'Name ▼'
case 'email-asc':
return 'Email ▲'
case 'email-desc':
return 'Email ▼'
default:
return 'Last Seen ▼'
}
const key = `${sortBy}-${sortDirection}` as keyof typeof sortOptions
return sortOptions[key] || 'Last Seen ▼'
}

const SortDropdown = ({
Expand Down Expand Up @@ -76,12 +71,19 @@ const SortDropdown = ({
</button>
{menuPortal(
<Menu ariaLabel='Sort options' {...menuProps}>
<MenuItem label='Last Seen ▲' onClick={() => handleSort('lastSeenAt', 'asc')} />
<MenuItem label='Last Seen ▼' onClick={() => handleSort('lastSeenAt', 'desc')} />
<MenuItem label='Name ▲' onClick={() => handleSort('preferredName', 'asc')} />
<MenuItem label='Name ▼' onClick={() => handleSort('preferredName', 'desc')} />
<MenuItem label='Email ▲' onClick={() => handleSort('email', 'asc')} />
<MenuItem label='Email ▼' onClick={() => handleSort('email', 'desc')} />
{Object.entries(sortOptions).map(([key, label]) => {
const [newSortBy, newSortDirection] = key.split('-') as [
typeof sortBy,
typeof sortDirection
]
return (
<MenuItem
key={key}
label={label}
onClick={() => handleSort(newSortBy, newSortDirection)}
/>
)
})}
</Menu>
)}
</>
Expand Down

0 comments on commit 33b6b8a

Please sign in to comment.