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

removed scroll on adding new question #4181

Conversation

Jaspreet-singh-1032
Copy link
Contributor

Summary

fixes #4079

Removed scroll on adding new questions

Screenshots (if applicable)

https://www.loom.com/share/b19535f245364c39899f85d9db974202


Reviewer guidance

How can a reviewer test these changes?

  • add new questions into the exercise

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

// Instead of propagating an event all the way back to
// the scrolling panel, just use scrollIntoView
// (supported by most major browsers)
if (this.$el.scrollIntoView) {
Copy link
Member

Choose a reason for hiding this comment

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

Hi @Jaspreet-singh-1032, thank you for the changes here. Although I have some queries, removing this if statement would completely eliminate the smooth animation effect. Instead, we may want to enable scrolling with animation to the "response type" field rather than the "title/question". @MisRob @LianaHarris360 can you guide on the exact behaviour here? Removing the if statement does seem to work altho there won't be any scroll animation.

Copy link
Member

Choose a reason for hiding this comment

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

Yes, I think we would want to keep the animation scroll. As for enabling scrolling to the "response type" field, the scrollIntoView() method takes in a block argument in addition to behavior, that defines the vertical alignment and the default is set to 'start' which doesn't seem to scroll to the preferred view, so possibly trying 'center' or 'nearest' could be an option.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The maximum of the response type shown by using block: end or nearest.
This is how it looks.
image

Copy link
Member

@MisRob MisRob Jul 24, 2023

Choose a reason for hiding this comment

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

It seems to me that it's caused by the secondary bar (with "Details", "Questions", "Related"). Even though the scroll position is correct, the element we scrolled into view is hidden underneath the bar. I think that one way to deal with it might be something like:

  1. Get coordinates of the question type element
  2. Scroll window (https://developer.mozilla.org/en-US/docs/Web/API/Window/scrollTo) to those coordinates but with an offset that corresponds to the bar height.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, I will try this solution. However, the window.scrollTo function was not working here, but I will research it. It could be due to some CSS.

Copy link
Member

Choose a reason for hiding this comment

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

Ah, yes, this is a modal actually, so I assume that's the reason. Perhaps Element.scrollTo() https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollTo could be used then.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The scrollTo did not work on any of the elements. I think this is because there is an outer scrollable div in which all these elements are rendered and the scrollTo only works on the outer parent div and not on the internal elements.

Copy link
Contributor Author

@Jaspreet-singh-1032 Jaspreet-singh-1032 Jul 26, 2023

Choose a reason for hiding this comment

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

I was able to scroll using the outer div with scrollTo function. I think I can implement a workaround using it 💡

Copy link
Member

Choose a reason for hiding this comment

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

Ah, that sounds tricky. Wonderful you found a workaround, let's see. Let us know if you needed anything.

@vkWeb
Copy link
Member

vkWeb commented Jul 31, 2023

@Jaspreet-singh-1032 @MisRob @ozer550 @LianaHarris360 I've manually tested this, its working as expected.

Please go through the code once to see if we can simplify it more. Otherwise lets get it merged!

@Jaspreet-singh-1032 This was really a very tricky one, you did an excellent job with this, ❤️ I am really impressed! Here's one of the more tricky issue that I think you are an excellent fit to deal with: #4170. Let me know personally on Slack or on dev-community channel if you have any questions (you should have questions!).

cc @bjester.

@@ -333,6 +334,18 @@
this.$analytics.trackAction('exercise_editor', 'Add', {
eventLabel: 'Question',
});
this.$nextTick(() => {
if (this.$refs['questionCardRef'].length >= 1) {
Copy link
Member

@LianaHarris360 LianaHarris360 Jul 31, 2023

Choose a reason for hiding this comment

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

To avoid some redundancy, this.$refs['questionCardRef'] can be defined as a constant before the if statement and reused within.

Also consider using optional chaining (?.) to prevent potential errors from null values/handle them safely, for example:

if (questionCards?.length >=  1)

To echo @vkWeb you did a great job with this workaround!

Copy link
Member

@LianaHarris360 LianaHarris360 left a comment

Choose a reason for hiding this comment

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

The code changes look great to me and it works as intended. Thanks @Jaspreet-singh-1032

@vkWeb vkWeb merged commit d401e85 into learningequality:unstable Aug 1, 2023
@vkWeb
Copy link
Member

vkWeb commented Aug 1, 2023

@LianaHarris360 I've merged this! 🎉

@pcenov
Copy link
Member

pcenov commented Sep 18, 2023

LGTM as well!

@bjester bjester mentioned this pull request Sep 27, 2023
@akolson akolson mentioned this pull request Aug 13, 2024
@akolson akolson mentioned this pull request Oct 1, 2024
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.

Adding new question should show question type
6 participants