Conversation
mateacademy-ai-mentor
left a comment
There was a problem hiding this comment.
Review Summary
You've built a good foundation with a working debounced filter, which is a great start. However, this submission requires changes because some core functionality is missing.
Here are the main issues to address:
- Selection logic is incomplete: In
App.tsx, when a user clicks a suggestion, the input field's text is not updated and the suggestion list does not close. You need to create a new handler for theonSelectedprop that updates thequerystate and hides the list. - Whitespace filtering: The filter runs even for input containing only spaces, which violates a checklist requirement [CHECKLIST ITEM #1]. Please make sure to
.trim()the user's input before filtering. - Incorrect message visibility: The "No matching suggestions" message remains visible even when the dropdown is closed. Its display should be conditional on the dropdown being open and the query having no results.
✨ 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
mateacademy-ai-mentor
left a comment
There was a problem hiding this comment.
Review Summary
Great job addressing some of the previous feedback! While the foundation is strong, I'm requesting changes because a few critical requirements are not yet met, which break the core functionality of the autocomplete component.
Here’s what needs to be fixed:
- Selection Logic: When a suggestion is clicked, the input field is cleared instead of being filled with the selected name. In your
handleSelectfunction, please set thequerystate to the person's name. - Inability to Type Spaces: You are trimming the input value in
handleQueryChange, which prevents users from typing spaces to search for multi-word names. Thequerystate should reflect the user's raw input; trimming should only be applied to the value used for filtering. - Customizable Debounce Delay: The task requires the debounce
delayto be a customizable prop, but it is currently hardcoded. This logic should be part of a reusable component that accepts props. - Incorrect Test Attributes: The
data-qaattributes, which are required for tests, have been changed todata-cy. Please change them back todata-qa.
Once these issues are resolved, your component will be fully functional. Keep up the great work!
✨ 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
| [preparedQuery], | ||
| ); | ||
|
|
||
| const applyQuery = useCallback(debounce(setPreparedQuery, 300), []); |
There was a problem hiding this comment.
The task requires the debounce delay to be customizable via a prop with a default value of 300ms. Currently, the delay is hardcoded here. This suggests that the autocomplete logic should be encapsulated in a separate, reusable component that can accept props.
| return ( | ||
| <div className="container"> | ||
| <main className="section is-flex is-flex-direction-column"> | ||
| <h1 className="title" data-cy="title"> |
There was a problem hiding this comment.
The task description explicitly states, "Don't remove the data-qa attributes. It is required for tests." All data-cy attributes throughout the application should be changed back to data-qa to ensure that the automated tests can run successfully.
mateacademy-ai-mentor
left a comment
There was a problem hiding this comment.
Review Summary
I'm approving this submission as an educational override to help you progress. You've done a great job fixing the selection logic! However, a few key requirements still need attention.
Please make sure to:
- Use
data-qafor test attributes instead ofdata-cyacross all components, as required by the task. - Make the debounce
delaya customizable prop inApp.tsxinstead of hardcoding it. - Prevent the filter from running when the input contains only spaces by checking the trimmed value. This addresses checklist item #1.
- Fix the focus/blur bug by canceling the debounced
onBlurcall inside theonFocushandler.
You're very close to a perfect solution. Keep up the fantastic effort!
✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨
Footnotes
| //const field = useRef<HTMLInputElement>(null); | ||
|
|
||
| return ( | ||
| <div className="dropdown-menu" role="menu" data-cy="suggestions-list"> |
There was a problem hiding this comment.
The task requirements specify using data-qa attributes for testing, not data-cy. Please update this attribute to data-qa="suggestions-list".
| {filteredPeople.map((person: Person) => ( | ||
| <div | ||
| className="dropdown-item" | ||
| data-cy="suggestion-item" |
There was a problem hiding this comment.
As per the task requirements, this should be a data-qa attribute for testing purposes. Please change it to data-qa="suggestion-item".
| peopleFromServer.filter(person => | ||
| person.name.includes(preparedQuery.trim()), |
There was a problem hiding this comment.
This violates checklist item #1: 'make sure that filter won't be called if user enred spaces only;'. The .filter() method is called even for an empty or spaces-only query. Consider adding a check to avoid filtering in this case and directly return the full list of people.
| [preparedQuery], | ||
| ); | ||
|
|
||
| const applyQuery = useCallback(debounce(setPreparedQuery, 300), []); |
There was a problem hiding this comment.
The debounce delay is hardcoded. According to the requirements, the delay should be a customizable prop with a default value of 300ms.
| return ( | ||
| <div className="container"> | ||
| <main className="section is-flex is-flex-direction-column"> | ||
| <h1 className="title" data-cy="title"> |
There was a problem hiding this comment.
The task requires using data-qa attributes for testing, but data-cy is used here. This was also pointed out in the previous review. Please update all test attributes to data-qa.
| @@ -19,55 +50,36 @@ export const App: React.FC = () => { | |||
| placeholder="Enter a part of the name" | |||
| className="input" | |||
| data-cy="search-input" | |||
There was a problem hiding this comment.
The task requires using data-qa attributes for testing, but data-cy is used here.
| onFocus={() => setBlured(true)} | ||
| onBlur={() => loseQuery(false)} |
There was a problem hiding this comment.
There's a subtle bug in the focus/blur handling. If you blur the input and then quickly re-focus it (within 1 second), the suggestions will appear and then disappear. This is because the debounced loseQuery call from onBlur isn't cancelled. You can fix this by calling loseQuery.cancel() inside the onFocus handler.
| is-align-self-flex-start | ||
| " | ||
| role="alert" | ||
| data-cy="no-suggestions-message" |
There was a problem hiding this comment.
The task requires using data-qa attributes for testing, but data-cy is used here.
brespect
left a comment
There was a problem hiding this comment.
Almost done, but make sure you have correctly deployed your DEMO LINK. For now, it is not working. Also, remove all redundant comments in final code
DEMO LINK