-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
add task solution #1147
base: master
Are you sure you want to change the base?
add task solution #1147
Conversation
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.
Thank you for your hard work on this pull request! Your implementation is quite comprehensive and meets many of the task requirements. However, there are a few critical issues that need to be addressed before we can approve the changes:
-
Typo in Function Name: The function
peopleWithPerents
has a typo in its name. It should be corrected topeopleWithParents
to maintain clarity and consistency with naming conventions. -
Sort Icon Logic: The class name for the sort icon should accurately reflect the current
sortOrder
. Ensure thatsortOrder
is properly initialized and updated, and consider using a default icon state whensortOrder
is null to avoid confusion. -
Sorting Logic for Null/Undefined Values: The current sorting logic returns 0 if either
aValue
orbValue
is null or undefined, which can lead to unexpected behavior. Consider explicitly handling these cases by placing null or undefined values at the end of the sorted list. -
Sort Order Logic: The
sortOrder
logic currently reverses the array ifsortOrder
is truthy, which might not behave as expected ifsortOrder
is not explicitly set to 'asc' or 'desc'. Ensure that specific values are checked to apply the intended sort order. -
Century Filter Update: The
toggleCenturyFilter
function might not correctly update theparams
in theSearchLink
component. Store the result in a variable before passing it toparams
to ensure the state is correctly updated.
Once these issues are resolved, your code will be in great shape! Keep up the excellent work, and feel free to reach out if you have any questions or need further clarification. 😊
✨ Please rate this review in the Platform's notification center. I will be grateful for your feedback! ✨
🔄 Fix the issues, commit the changes, and then re-request my review using the Re-request review
button in the Reviewers tab.
const toggleCenturyFilter = (century: string) => { | ||
return centuries.includes(century) | ||
? centuries.filter(cent => cent !== century) | ||
: [...centuries, century]; | ||
}; |
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.
The toggleCenturyFilter
function is designed to toggle the presence of a century in the centuries
array. However, when updating the params
in the SearchLink
component (line 88), it might not correctly reflect the toggled state because it directly uses the return value of toggleCenturyFilter
. Consider storing the result in a variable before passing it to params
to ensure the state is correctly updated.
src/components/PeoplePage.tsx
Outdated
if (sortOrder) { | ||
filteredPeople.reverse(); | ||
} |
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.
The sortOrder
logic currently reverses the array if sortOrder
is truthy. This could lead to unexpected behavior if sortOrder
is not explicitly set to a meaningful value (e.g., 'asc' or 'desc'). Consider checking for specific values to ensure the sort order is applied as intended.
src/components/PeopleTable.tsx
Outdated
if ( | ||
aValue === null || | ||
aValue === undefined || | ||
bValue === null || | ||
bValue === undefined | ||
) { | ||
return 0; |
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.
The sorting logic currently returns 0 if either aValue
or bValue
is null or undefined. This could lead to unexpected sorting behavior. Consider handling these cases more explicitly, perhaps by placing null or undefined values at the end of the sorted list.
src/components/PeopleTable.tsx
Outdated
<span className="icon"> | ||
<i className="fas fa-sort" /> | ||
<i | ||
className={`fas fa-sort-${sortOrder === 'asc' ? 'up' : 'down'}`} |
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.
The class name for the sort icon is determined by the sortOrder
. Ensure that the icon correctly reflects the current sort order by verifying that sortOrder
is properly initialized and updated. Consider using a default icon state when sortOrder
is null.
src/utils/PeopleWithParents.ts
Outdated
@@ -0,0 +1,27 @@ | |||
import { Person } from '../types'; | |||
|
|||
export const peopleWithPerents = (peopleFromServer: Person[]): Person[] => { |
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.
There is a typo in the function name peopleWithPerents
. It should be corrected to peopleWithParents
to match the intended meaning and maintain consistency with the naming conventions.
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.
Your code has been reviewed and is approved! 🎉 While there are some areas for improvement, such as handling null or undefined values in sorting, ensuring consistent navigation with react-router-dom
, and refining the toggleCenturyFilter
logic, you've made significant progress. Addressing these issues will enhance your code's robustness and maintainability. Keep up the great work, and continue learning from these experiences to refine your skills further!
✨ Please rate this review in the Platform's notification center. I will be grateful for your feedback! ✨
const toggleCenturyFilter = (century: string) => { | ||
return centuries.includes(century) | ||
? centuries.filter(cent => cent !== century) | ||
: [...centuries, century]; |
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.
The toggleCenturyFilter
function currently returns a new array of centuries but does not update the search parameters directly. Consider updating the search parameters within this function or ensure that the returned value is used to update the state elsewhere.
16 | ||
</a> | ||
{centuriesList.map(century => { | ||
const updatedCenturies = toggleCenturyFilter(century); |
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.
The toggleCenturyFilter
function is called here, but its result is not used to update the search parameters. Ensure that the updated centuries list is passed to the params
prop of SearchLink
to reflect changes in the URL.
<a className="button is-link is-outlined is-fullwidth" href="#/people"> | ||
<SearchLink | ||
className="button is-link is-outlined is-fullwidth" | ||
onClick={resetFilters} |
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.
The onClick
handler for SearchLink
does not need to be used here since SearchLink
will automatically handle navigation based on the params
prop. Consider removing the onClick
handler to avoid potential conflicts.
import { getPeople } from '../api'; | ||
import { useSearchParams, useParams } from 'react-router-dom'; | ||
import { SortBy } from '../types/SortBy'; | ||
import { peopleWithParents } from '../utils/PeopleWithParents'; |
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.
There is a typo in the function name peopleWithParents
. It should be corrected to peopleWithParents
to maintain clarity and consistency with naming conventions.
if (sortBy && sortMethods[sortBy]) { | ||
filteredPeople.sort(sortMethods[sortBy]); |
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.
The sorting logic does not handle null or undefined values explicitly. Consider placing null or undefined values at the end of the sorted list to avoid unexpected behavior.
const sex = searchParams.get('sex') || ''; | ||
const centuries = searchParams.getAll('centuries') || []; | ||
const sortBy = searchParams.get('sort') as SortBy | null; | ||
const sortOrder = searchParams.get('order'); |
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.
The sortOrder
logic currently reverses the array if sortOrder
is 'desc'. Ensure that specific values are checked to apply the intended sort order, and consider initializing sortOrder
to a default value if it's null.
sort: 'name', | ||
order: sortOrder === 'asc' ? 'desc' : 'asc', | ||
}} | ||
onClick={() => handleSort('name')} |
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.
The onClick
handler for SearchLink
is redundant since SearchLink
will automatically handle navigation based on the params
prop. Consider removing the onClick
handler to avoid potential conflicts.
const aValue = a[sortField as keyof Person]; | ||
const bValue = b[sortField as keyof Person]; |
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.
The sorting logic for aValue
and bValue
should ensure that both values are comparable. Consider adding a check to handle cases where aValue
or bValue
might not be directly comparable, such as when they are objects or other non-primitive types.
> | ||
<td> | ||
<a | ||
href={`#/people/${person.slug}`} |
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.
Using href
with a hash (#
) for navigation might not be ideal if you are using react-router-dom
. Consider using Link
from react-router-dom
for navigation to ensure consistency with the rest of the application.
mother: parentsMap.mothers[person.motherName || ''] || null, | ||
father: parentsMap.fathers[person.fatherName || ''] || null, |
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.
The use of person.motherName || ''
and person.fatherName || ''
is a bit redundant since parentsMap
keys are strings. Consider directly using person.motherName
and person.fatherName
without the fallback to an empty string, as the map will handle undefined keys by returning undefined
, which is then correctly defaulted to null
.
DEMO LINK