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

Fix save quick edit modals #4742

Merged

Conversation

AlexVelezLl
Copy link
Member

Summary

Description of the change(s) you made

Fix save edit boolean map modals. This PR fixes two things:

  • When saving we do a filter of the current selected node, so we need to filter the values of this.selectedValues that have all nodes inside, but we have
            Object.entries(this.selectedValues)
              .filter(([value]) => value.length === this.nodeIds.length)

which is an error as the value is the second element of the entries, not the first.

  • Fix can save method, as we need to allow can save if there is at least one option selected, so we need to look for .some(value => value.length === this.nodes.length), but we have .some(value => value.length > 0) and this is an error as this condition is true for values that arent selected across all nodes.

Contributor's Checklist

PR process:

  • If this is an important user-facing change, PR or related issue the CHANGELOG label been added to this PR. Note: items with this label will be added to the CHANGELOG at a later time
  • If this includes an internal dependency change, a link to the diff is provided
  • The docs label has been added if this introduces a change that needs to be updated in the user docs?
  • If any Python requirements have changed, the updated requirements.txt files also included in this PR
  • Opportunities for using Google Analytics here are noted
  • Migrations are safe for a large db

Studio-specifc:

  • All user-facing strings are translated properly
  • The notranslate class been added to elements that shouldn't be translated by Google Chrome's automatic translation feature (e.g. icons, user-generated text)
  • All UI components are LTR and RTL compliant
  • Views are organized into pages, components, and layouts directories as described in the docs
  • Users' storage used is recalculated properly on any changes to main tree files
  • If there new ways this uses user data that needs to be factored into our Privacy Policy, it has been noted.

Testing:

  • Code is clean and well-commented
  • Contributor has fully tested the PR manually
  • If there are any front-end changes, before/after screenshots are included
  • Critical user journeys are covered by Gherkin stories
  • Any new interactions have been added to the QA Sheet
  • Critical and brittle code paths are covered by unit tests

Reviewer's Checklist

This section is for reviewers to fill out.

  • Automated test coverage is satisfactory
  • PR is fully functional
  • PR has been tested for accessibility regressions
  • External dependency files were updated if necessary (yarn and pip)
  • Documentation is updated
  • Contributor is in AUTHORS.md

Copy link
Member

@akolson akolson left a comment

Choose a reason for hiding this comment

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

Changes make sense to me! I'll leave the final approval to @AllanOXDi. Thanks @AlexVelezLl for noticing this and the change.

@AlexVelezLl
Copy link
Member Author

Thank you @akolson. I have fixed and added some unit tests to spot regressions like these 🤗

@@ -174,7 +176,7 @@
Object.assign(fieldValue, currentNode[this.field] || {});
}
Object.entries(this.selectedValues)
.filter(([value]) => value.length === this.nodeIds.length)
.filter(entry => entry[1].length === this.nodeIds.length)
Copy link
Member

Choose a reason for hiding this comment

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

Great catch! On correcting the filter. Changing the check to entry[1].length === this.nodeIds.length ensures we're filtering the selected values properly, as the second element of the entries represents the value, not the first.

@@ -107,7 +107,9 @@
},
canSave() {
if (this.hasMixedCategories) {
return Object.values(this.selectedValues).some(value => value.length > 0);
return Object.values(this.selectedValues).some(
value => value.length === this.nodes.length
Copy link
Member

Choose a reason for hiding this comment

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

The updated condition now ensures saving is only allowed when the selected values cover all nodes , which makes validation more robust. What would happen if partial selections are ever needed in other scenarios? maybe we might want to consider making this condition more flexible?

Copy link
Member Author

Choose a reason for hiding this comment

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

Hey! The thing is that "partial selections" just only serve to determine if we have mixedCategories, but the user doesnt see nor interact with any of these partial selections. For them they dont exists, so thats why we cant depend on them, and rather depend on what they are seeing which is selected options, and we have selected options when we have that value.length === this.nodes.length.

If we keep the condition of value.length > 0 then we will be taking these mixed options as valid values. So if I have for example 2 nodes:

Node 1:

  • Category A selected

Node 2:

  • Category B selected

Then when we open the modal, we will see the mixed options comment, but we wont see any of the options selected, because we dont have any option selected across all nodes, and we wont see any indeterminate state as they dont exist anymore, the only the user will se will be all checkboxes unchecked. But the user will still see the save button enabled, because canSave = true because all category A and B have value.length > 0, and this is an error, as we are not meeting the 4th acceptance criteria mentioned in #4651:

the "save" button only be active if one or more boxes is checked, but no validation is required (and no error message)

So, no, we cant have a more flexible condition as this condition does not met the requirements.

Copy link
Member

Choose a reason for hiding this comment

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

Thank you for explaining the reasoning behind the stricter condition.

Copy link
Member

@akolson akolson left a comment

Choose a reason for hiding this comment

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

With all comments addressed, approving this and merging. Thanks @AlexVelezLl @AllanOXDi

@AllanOXDi AllanOXDi merged commit cc0b008 into learningequality:unstable Sep 19, 2024
13 checks passed
@AlexVelezLl AlexVelezLl deleted the fix-save-quick-edit-modal branch September 19, 2024 14:17
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