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

react_people-table-advanced #1127

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

TetianaMD
Copy link

Copy link

@mateacademy-ai-mentor mateacademy-ai-mentor left a comment

Choose a reason for hiding this comment

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


Great job on implementing the task requirements! 🎉 Your code meets the core functionality and constraints, effectively handling filtering and sorting with URL parameters. While there are some minor improvements suggested, such as optimizing the findPersonByName function and simplifying the useEffect logic, these do not critically impact the functionality. Keep up the good work, and consider the feedback for future enhancements! 😊

✨ Please rate this review in the Platform's notification center. I will be grateful for your feedback! ✨

Comment on lines 6 to 10
useEffect(() => {
if (selectCenturies) {
setSelectCenturies(selectCenturies);
}
}, [selectCenturies]);

Choose a reason for hiding this comment

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

The useEffect hook here is redundant and potentially problematic. It sets selectCenturies to itself whenever it changes, which can cause an infinite loop of updates. Consider removing this useEffect unless there's a specific reason for its presence that isn't clear from the current code.

<p data-cy="noPeopleMessage">There are no people on the server</p>

<p>There are no people matching the current search criteria</p>
{isLoading && <Loader />}

Choose a reason for hiding this comment

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

The loading state is already handled at the beginning of the component with a return statement. Therefore, the check for isLoading here is redundant and can be removed to simplify the code.

Comment on lines +32 to +35
const findPersonByName = (name: string | undefined | null): Person | null =>
name
? people.find(p => p.name.toLowerCase() === name.toLowerCase()) || null
: null;

Choose a reason for hiding this comment

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

The findPersonByName function is called multiple times for each person in the table, which can be inefficient. Consider optimizing this by creating a map of names to Person objects outside of the map function to reduce redundant lookups.

</td>
</tr>
{filteredPeople.map(person => (
<tr

Choose a reason for hiding this comment

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

Consider using a React.Fragment (<>...</>) instead of an empty tag (<>) for consistency and readability.

path: string,
) => {
e.preventDefault();
navigate(`${path}${location.search}`);

Choose a reason for hiding this comment

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

The location object is not imported or defined in this component. You should use searchParams directly instead of location.search to ensure the correct query string is appended to the navigation path.

Comment on lines 26 to 28
className={classNames('is-active', {
'is-active': filterBySex === 'all',
})}

Choose a reason for hiding this comment

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

The className logic for determining the active state is redundant. The classNames function is called with 'is-active' twice. You can simplify this by directly using filterBySex === 'all' without wrapping it in classNames.

Comment on lines 35 to 37
className={classNames('is-active', {
'is-active': filterBySex === 'm',
})}

Choose a reason for hiding this comment

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

Similar to the previous comment, the className logic for the 'Male' filter is redundant. Simplify by directly using filterBySex === 'm'.

Comment on lines 44 to 46
className={classNames('is-active', {
'is-active': filterBySex === 'f',
})}

Choose a reason for hiding this comment

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

Similarly, simplify the className logic for the 'Female' filter by directly using filterBySex === 'f'.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants