Skip to content

react_people-table-advanced#1818

Open
valerij0412 wants to merge 2 commits into
mate-academy:masterfrom
valerij0412:develop
Open

react_people-table-advanced#1818
valerij0412 wants to merge 2 commits into
mate-academy:masterfrom
valerij0412:develop

Conversation

@valerij0412

Copy link
Copy Markdown

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

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Review Summary

I am requesting changes because there are still a few critical, behavior‑breaking issues around URL handling and filtering/sorting logic.

Blocking issues that must be fixed:

  1. In multiple places (e.g. src/components/PeopleFilters.tsx for handleQueryChange and src/components/PeopleTable.tsx for handleSort), you call setSearchParams(getSearchWith(...)), but setSearchParams expects a URLSearchParams instance or an init object, not a raw string. This can cause runtime errors and broken updates to sort, order, and filter params; wrap the result in new URLSearchParams(...) or switch to passing an object instead.
  2. The sex filter is written to the URL in PeopleFilters, but in src/components/PeoplePage.tsx you never use searchParams.get('sex') to actually filter visiblePeople, so the UI control doesn’t affect the data. You need to add a sex-based filter step (e.g., only include people whose sex matches the sex param) before applying sorting.
  3. In PeoplePage.tsx, you treat sort as a generic keyof Person, which means any arbitrary sort value in the URL will be used; per requirements, only name, sex, born, and died should be valid. Add a small validation step (e.g., check against an allowed array of fields) and ignore unsupported values so unexpected params don’t change sorting.

Minor but recommended improvements: you can tighten the type of the field parameter in handleSort to 'name' | 'sex' | 'born' | 'died' for clarity, and ensure that when switching columns you clear any stale order so the first click is always treated as ascending with order removed. Once you address the setSearchParams misuse, apply the sex filter, and validate the sort field, your solution should fully match the task requirements—your routing, century and query filters, and general URL‑based state handling are otherwise on the right track.


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

Important

Fix the issues, commit the changes, and then re-request my review using the Re-request review button2 in the Reviewers tab.

Tip

If you have any comments about this review, please leave a message in the Add a comment section below and mention me with the @mateacademy-ai-mentor tag3.
I will read your message during my next review of your pull request. Please do not reply directly to my comments, as that feature is not supported yet.

Caution

Do not close the pull request until the review is complete. Closing it early can lead to unexpected behavior and disrupt the review process.

Footnotes

  1. Rate AI review example

  2. Re-request AI review example

  3. Add AI review comments example

Comment thread src/components/PeopleFilters.tsx Outdated
const handleQueryChange = (e: React.ChangeEvent<HTMLInputElement>) => {
const value = e.target.value;

setSearchParams(getSearchWith(searchParams, { query: value || null }));

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

setSearchParams expects either a URLSearchParams instance or an init object; here you’re passing the string returned by getSearchWith, which can cause runtime issues. Consider wrapping this into a URLSearchParams (or using setSearchParams with an object) instead of passing the raw string.

Comment thread src/components/PeoplePage.tsx Outdated
Comment on lines +60 to +66
if (sortField) {
visiblePeople.sort((a, b) => {
const aValue = a[sortField as keyof Person] || '';
const bValue = b[sortField as keyof Person] || '';

if (aValue < bValue) {
return order === 'desc' ? 1 : -1;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The current handleSort does not implement the required three-step behavior (asc → desc → disabled). On the first click you should set sort to this field and leave order unset (ascending by default), on the second click toggle order to 'desc', and on the third click clear both sort and order so sorting is disabled (per checklist items #10–13, #20–22).

Comment thread src/components/PeoplePage.tsx Outdated
Comment on lines +60 to +75
if (sortField) {
visiblePeople.sort((a, b) => {
const aValue = a[sortField as keyof Person] || '';
const bValue = b[sortField as keyof Person] || '';

if (aValue < bValue) {
return order === 'desc' ? 1 : -1;
}

if (aValue > bValue) {
return order === 'desc' ? -1 : 1;
}

return 0;
});
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

sortField is used as a generic keyof Person, so any sort value in the URL (including unsupported fields) will be used for sorting. The task only requires sorting by name, sex, born, and died; consider validating sortField against this allowed set before applying sorting so unexpected search params don’t affect behavior.

Comment thread src/components/PeopleTable.tsx Outdated
Comment on lines +17 to +36
const handleSort = (field: keyof Person) => {
// ... твоя логіка сортування залишається без змін ...
let nextSort: string | null = field;
let nextOrder: string | null = null;

if (currentSort === field) {
if (currentOrder !== 'desc') {
nextOrder = 'desc';
} else {
nextSort = null;
nextOrder = null;
}
}

setSearchParams(
getSearchWith(searchParams, {
sort: nextSort,
order: nextOrder,
}),
);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

handleSort does not fully enforce the 3-step sort cycle and also passes a string to setSearchParams. First, make sure that when switching to a new column you clear any stale order from previous sorts and explicitly represent ascending state (e.g., sort=<field> and order removed). Second, setSearchParams expects a URLSearchParams or an init object, not the raw string from getSearchWith; consider wrapping that string or using an object form.

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

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Review Summary

I am approving your solution because all critical functional requirements for this task are met, including filtering, multi‑century selection, URL‑backed state, and the full sorting click cycle with correct sort/order params. The People page correctly keeps filters and sort in the URL, preserves them when navigating via the Navbar and person links, and only shows the filters sidebar when data is successfully loaded and non‑empty. Sorting is limited to the allowed fields (name, sex, born, died), the first click is always ascending with no order, the second adds order=desc, and the third clears both sort and order, matching the checklist behavior.

Some type‑safety and validation details (like making sort validation stricter in PeoplePage or treating order as a more explicit union type) could be refined, but these are non‑blocking improvements rather than functional bugs. From the perspective of the required behavior and URL semantics, your implementation behaves correctly and consistently across components. Nicely done bringing everything into alignment with the spec and prior review feedback.


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

Footnotes

  1. Rate AI review example

Comment on lines +18 to +32
setSearchParams(
new URLSearchParams(
getSearchWith(searchParams, { query: value || null }),
),
);
};

// Логіка для додавання/видалення століть
const getCenturySearch = (century: string) => {
let newCenturies = [...centuries];

if (newCenturies.includes(century)) {
newCenturies = newCenturies.filter(c => c !== century);
} else {
newCenturies.push(century);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The checklist requires: (1) first click = ascending with no order param, (2) second click = descending with order=desc, and (3) third click = sorting disabled with no sort and no order. Your handleSort correctly toggles sort and sets order='desc' on the second click, and clears both on the third click, so the URL behavior from the table side matches the requirements.

Comment on lines +31 to +32
} else {
newCenturies.push(century);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

isSortValid checks only that sortField is among name/sex/born/died, but it doesn’t validate order. Later you treat order as either 'desc' or “ascending” (any other value), so a stale or manually entered order=desc combined with a new sort value would make the first click appear descending, which violates the requirement that first click is always ascending. Consider validating order (only accept 'desc'), and treating anything else as “no order” so the first click is always ascending.

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