-
Notifications
You must be signed in to change notification settings - Fork 428
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat(sidebar): sort safes by name and recently used [SW-307] (#4458)
* Feat: add option to sort by recently visited and by name * tests: add new properties to unit tests * fix: make order by preference persist * feat: sort sub account items by name and recently visited * refactor: fix incorrect variable names and remove console log
- Loading branch information
Showing
14 changed files
with
504 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import { useState } from 'react' | ||
import { Button, ListItemText, MenuItem, SvgIcon } from '@mui/material' | ||
import ContextMenu from '@/components/common/ContextMenu' | ||
import TransactionsIcon from '@/public/images/transactions/transactions.svg' | ||
import CheckIcon from '@/public/images/common/check.svg' | ||
import { OrderByOption } from '@/store/orderByPreferenceSlice' | ||
|
||
type OrderByButtonProps = { | ||
orderBy: OrderByOption | ||
onOrderByChange: (orderBy: OrderByOption) => void | ||
} | ||
|
||
const OrderByButton = ({ orderBy: orderBy, onOrderByChange: onOrderByChange }: OrderByButtonProps) => { | ||
const [anchorEl, setAnchorEl] = useState<HTMLElement | undefined>() | ||
|
||
const handleClick = (event: React.MouseEvent<HTMLButtonElement>) => { | ||
setAnchorEl(event.currentTarget) | ||
} | ||
|
||
const handleClose = () => { | ||
setAnchorEl(undefined) | ||
} | ||
|
||
const handleOrderByChange = (newOrderBy: OrderByOption) => { | ||
onOrderByChange(newOrderBy) | ||
handleClose() | ||
} | ||
|
||
return ( | ||
<> | ||
<Button | ||
onClick={handleClick} | ||
startIcon={<SvgIcon component={TransactionsIcon} inheritViewBox />} | ||
sx={{ color: 'text.secondary' }} | ||
size="small" | ||
> | ||
Sort | ||
</Button> | ||
|
||
<ContextMenu | ||
anchorEl={anchorEl} | ||
open={!!anchorEl} | ||
onClose={handleClose} | ||
sx={{ | ||
'& .MuiPaper-root': { minWidth: '250px' }, | ||
'& .Mui-selected, & .Mui-selected:hover': { | ||
backgroundColor: `background.paper`, | ||
}, | ||
}} | ||
> | ||
<MenuItem disabled> | ||
<ListItemText>Sort by</ListItemText> | ||
</MenuItem> | ||
<MenuItem | ||
sx={{ borderRadius: 0 }} | ||
onClick={() => handleOrderByChange(OrderByOption.LAST_VISITED)} | ||
selected={orderBy === OrderByOption.LAST_VISITED} | ||
> | ||
<ListItemText sx={{ mr: 2 }}>Most recent</ListItemText> | ||
{orderBy === OrderByOption.LAST_VISITED && <CheckIcon sx={{ ml: 1 }} />} | ||
</MenuItem> | ||
<MenuItem onClick={() => handleOrderByChange(OrderByOption.NAME)} selected={orderBy === OrderByOption.NAME}> | ||
<ListItemText>Name</ListItemText> | ||
{orderBy === OrderByOption.NAME && <CheckIcon sx={{ ml: 1 }} />} | ||
</MenuItem> | ||
</ContextMenu> | ||
</> | ||
) | ||
} | ||
|
||
export default OrderByButton |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.