-
Notifications
You must be signed in to change notification settings - Fork 16
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
Bai 1641 sort files tab by different fields #2122
base: main
Are you sure you want to change the base?
Conversation
frontend/src/entry/model/Files.tsx
Outdated
const menuOpen = Boolean(anchorEl) | ||
const [orderByValue, setOrderByValue] = useState('createdAt') | ||
const [orderByButtonTitle, setOrderByButtonTitle] = useState('Order by') | ||
const [ASCorDESC, setASCorDESC] = useState('DESC') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should type this:
export const SortingDirection= {
ASC: 'ascending',
DESC: 'descending',
} as const
export type SortingDirectionKeys = (typeof SortingDirection)[keyof typeof SortingDirection]
That way, we can use it like so:
const [ascOrDesc, setAscOrDesc] = useState<SortingDirectionKeys>(SortingDirection.DESC)
In the above I also changed ASCorDESC
to ascOrDesc
as the casing is more consistent
frontend/src/entry/model/Files.tsx
Outdated
[orderByValue], | ||
) | ||
|
||
function handleMenuButtonClick(event: React.MouseEvent<HTMLButtonElement>) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change to
(event: MouseEvent<HTMLButtonElement>)
And import MouseEvent
from react
frontend/src/entry/model/Files.tsx
Outdated
<Box ml='auto'> | ||
<Stack direction={'row'}> | ||
<Button | ||
variant='text' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
text
is the default value for the variant
prop so it can be removed
frontend/src/entry/model/Files.tsx
Outdated
endIcon={anchorEl ? <ExpandLess /> : <ExpandMore />} | ||
> | ||
<Stack sx={{ minWidth: '150px' }} direction={'row'} spacing={2} justifyContent={'space-evenly'}> | ||
{ASCorDESC === 'ASC' ? ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After doing the type change for SortingDirection
then you should be able to do:
ascOrDesc === SortingDirection.ASC
frontend/src/entry/model/Files.tsx
Outdated
setOrderByValue(value) | ||
setOrderByButtonTitle(title) | ||
}} | ||
sx={{ paddingX: '8px' }} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
paddingX
can be shortened to px
and of defining pixels, we can just use numbers, like: px: 2
(obviously change the number to match what you need! Essentially, each number corresponds to a set number of pixels specified in our app (although we could well be using the default value). For example, if 1
corresponds to 5px
then 2
would be 10px
etc.
frontend/src/entry/model/Files.tsx
Outdated
onClick={() => { | ||
setASCorDESC('ASC') | ||
}} | ||
sx={{ paddingX: '8px' }} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See earlier comment about setting to px: <number>
frontend/src/entry/model/Files.tsx
Outdated
onClick={() => { | ||
setASCorDESC('DESC') | ||
}} | ||
sx={{ paddingX: '8px' }} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See earlier comment
No description provided.