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

Bai 1641 sort files tab by different fields #2122

Draft
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

IR96334
Copy link
Member

@IR96334 IR96334 commented Apr 3, 2025

No description provided.

@IR96334 IR96334 marked this pull request as draft April 3, 2025 14:42
@IR96334 IR96334 added enhancement New feature or request javascript Pull requests that update Javascript code labels Apr 3, 2025
const menuOpen = Boolean(anchorEl)
const [orderByValue, setOrderByValue] = useState('createdAt')
const [orderByButtonTitle, setOrderByButtonTitle] = useState('Order by')
const [ASCorDESC, setASCorDESC] = useState('DESC')
Copy link
Member

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

[orderByValue],
)

function handleMenuButtonClick(event: React.MouseEvent<HTMLButtonElement>) {
Copy link
Member

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

<Box ml='auto'>
<Stack direction={'row'}>
<Button
variant='text'
Copy link
Member

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

endIcon={anchorEl ? <ExpandLess /> : <ExpandMore />}
>
<Stack sx={{ minWidth: '150px' }} direction={'row'} spacing={2} justifyContent={'space-evenly'}>
{ASCorDESC === 'ASC' ? (
Copy link
Member

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

setOrderByValue(value)
setOrderByButtonTitle(title)
}}
sx={{ paddingX: '8px' }}
Copy link
Member

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.

onClick={() => {
setASCorDESC('ASC')
}}
sx={{ paddingX: '8px' }}
Copy link
Member

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>

onClick={() => {
setASCorDESC('DESC')
}}
sx={{ paddingX: '8px' }}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See earlier comment

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request javascript Pull requests that update Javascript code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants