Skip to content

task solution#1112

Open
h-rostyslav wants to merge 4 commits into
mate-academy:masterfrom
h-rostyslav:develop
Open

task solution#1112
h-rostyslav wants to merge 4 commits into
mate-academy:masterfrom
h-rostyslav:develop

Conversation

@h-rostyslav
Copy link
Copy Markdown

No description provided.

Copy link
Copy Markdown

@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.

Review Summary

The implementation has critical blockers that prevent task completion. Table sorting is completely missing - checklist items #1 and #2 require sorting by column headers in ASC/DESC order, but no sorting code exists. Row selection is broken - the click handler only removes the 'active' class from existing rows but never adds it to the clicked row (items #3 and #4). Required field validation is missing - the form should validate that all fields are non-empty before processing (item #18). Additionally, the success notification appears on line 69 BEFORE the employee is added to the table on line 81, which creates incorrect UX. Eight of fourteen Cypress tests are failing due to these issues. These are not minor problems - the core table functionality (sorting and selection) is fundamentally broken and must be fixed before the PR can be approved.


✨ 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/scripts/main.js
Comment on lines +5 to +16
tbody.addEventListener('click', (e) => {
const row = e.target.closest('tr');

if (!row) {
return;
}

const active = tbody.querySelector('.active');

if (active) {
active.classList.remove('active');
}
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 click handler removes the 'active' class from existing rows but never adds the 'active' class to the clicked row. According to checklist item #3 and #4, clicking a row should make it selected with the 'active' class. Add row.classList.add('active') before removing the previous active class.

Comment thread src/scripts/main.js
Comment on lines +47 to +52

const employeeName = form.elements.name.value;
const position = form.elements.position.value;
const age = +form.elements.age.value;
const salary = +form.elements.salary.value;
const office = form.elements.office.value;
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 form is missing required field validation. Checklist item #18 states all fields are required. Empty inputs should trigger an error notification before processing other validations.

Comment thread src/scripts/main.js Outdated
Comment on lines +69 to +70

showNotification('success', 'Success', 'Employee added successfully');
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 success notification is shown on line 69 BEFORE adding the employee to the table (line 81). This creates incorrect UX - the notification should appear after the employee is successfully added. Move the success notification call to after tbody.append(tr).

Comment thread src/scripts/main.js
Comment on lines 1 to +17
'use strict';

// write code here
const tbody = document.querySelector('tbody');

tbody.addEventListener('click', (e) => {
const row = e.target.closest('tr');

if (!row) {
return;
}

const active = tbody.querySelector('.active');

if (active) {
active.classList.remove('active');
}
});
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Table sorting functionality is completely missing. Checklist items #1 and #2 require sorting by column headers in ASC order on first click and DESC on second click. You need to add click handlers to table headers and implement sorting logic.

Comment thread src/scripts/main.js
Comment on lines +45 to +67
form.addEventListener('submit', (e) => {
e.preventDefault();

const employeeName = form.elements.name.value;
const position = form.elements.position.value;
const age = +form.elements.age.value;
const salary = +form.elements.salary.value;
const office = form.elements.office.value;

if (employeeName.length < 4) {
showNotification(
'error',
'Error',
'Name must be at least 4 characters long',
);

return;
}

if (age < 18 || age > 90) {
showNotification('error', 'Invalid Age', 'Age must be between 18 and 90');

return;
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 form validation logic runs but doesn't check if required fields are empty. According to checklist item #18, all fields must be required. Add a check at the beginning of the submit handler to validate that no field is empty.

Copy link
Copy Markdown

@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.

Review Summary

The code has a critical bug that violates a core requirement. On line 10, currentDirection is initialized to 'desc', which causes the first column click to sort in DESC order instead of the required ASC order. The task explicitly states that "When users click on one of the table headers, the table should be sorted in ASC order." To fix this, initialize currentDirection with 'asc' instead so the first click sorts ascending and subsequent clicks properly toggle to descending. This is a blocking issue because the sorting direction is incorrect for the primary interaction (first click), which directly breaks a specified requirement.


✨ 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/scripts/main.js Outdated
Comment on lines +14 to +15

const currentDirection = sordDirections[columnIndex] || 'desc';
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Bug: First click on a column sorts in DESC instead of ASC. The requirement states 'When users click on one of the table headers, the table should be sorted in ASC order'. Currently, currentDirection defaults to 'desc', so the first click toggles to 'asc', but the SORT happens with newDirection (which is 'asc'), making the result DESC. To fix: initialize currentDirection with 'asc' (or a value that toggles to 'asc' on first click), so the sort uses 'asc'.

Copy link
Copy Markdown

@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.

Review Summary

The sort state isn't being reflected in the DOM. Add 'sort-asc' and 'sort-desc' classes to the active column header during sorting, and remove them from other headers. This is required for the Cypress tests to pass.


✨ 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

Copy link
Copy Markdown

@2pasha 2pasha left a comment

Choose a reason for hiding this comment

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

lgtm 🔥

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.

3 participants