-
Notifications
You must be signed in to change notification settings - Fork 49
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
Fixed #70 - user now stays in the same tab while navigating around th… #289
Fixed #70 - user now stays in the same tab while navigating around th… #289
Conversation
@@ -141,36 +142,41 @@ define(['angularAMD', 'userSettingsService'], function (angularAMD) { | |||
if (!_.isEmpty($(suiteContainer).nextAll( | |||
'.aside-report:not(.is-hidden)').first().find( | |||
'.test-name'))) { | |||
currentTab = $('.nav-tabs > .nav-item').filter('.active').text().replace(/\s/g, ''); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is it possible to have more than one .nav-item
element with class active
? if not, why not going without filtering?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not at once, no. What would you recommend? I've tried adding class to the selector but it doesn't work as intended.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
after discussion I'm ok with keeping it as it is
} else { | ||
currentTab = $('.nav-tabs > .nav-item').filter('.active').text().replace(/\s/g, ''); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add a $
prefix to the variable name to indicate it holds a jQuery object
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Even though it's just plain text at the end ('screenlayout' for example)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, didn't notice - no need to worry about it then.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The name is very misleading though - rename it to currentTabLabel
or something else more accurate
if (!_.isEmpty($(suiteContainer).prevAll( | ||
'.aside-report:not(.is-hidden)').first() | ||
.find('.test-name'))) { | ||
currentTab = $('.nav-tabs > .nav-item').filter('.active').text().replace(/\s/g, ''); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here you have active
and in the lines below is-active
- can we make it consistent?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.active is a class for tabs while .is-active is a class for sidebar menu, I didn't modify any html/css structure. I can ask @Skejven what he thinks about it and then maybe change it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@oliwerin what is the problem with existing those two classes?
If you recommend to align them, please do so in a separate pull request.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Skejven It's not a huge issue but it's a class representing certain state and ideally there should be only one - for better consistency, readability and maintainability.
function clickOnTab() { | ||
var currentTab = userSettingsService.getLastTab(); | ||
var nextTestTabs = $('.nav-tabs').children(); | ||
for(var i=0;i <nextTestTabs.length; i++) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why you're not using jQuery each
for keeping it simpler and more consistent?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will change that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you also fix formatting? Thanks.
|
||
function clickOnTab() { | ||
var currentTab = userSettingsService.getLastTab(); | ||
var nextTestTabs = $('.nav-tabs').children(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Both lines - 248-249 - consider adding a $
prefix if they store jQuery collections
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here again currentTab is just plain text, will change that to currentTabLabel.
As to next line I will change that.
} | ||
} | ||
|
||
var mutationObserver = new MutationObserver(callback); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you shortly explain why it's needed with config set to true
for each property?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've used this: https://developer.mozilla.org/en-US/docs/Web/API/MutationObserverInit
I've tried few configs and this one has been working properly for me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, but why do you need MutationObserver, whatever its config is?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks for changes in the DOM before it is displayed to the user.
Here, if I didn't use MutationObserver my screen would flick every time I changed tree URL, because selecting the tab is done by using .click();
With MutationObserver I can atually click something before it is displayed (but it already exists in the DOM), both the delay and the flickering is gone.
I've tried using timeout - but it is based on how many tests are performed, the more tests, the longer the timeout should be (and it varies from 10 to 50ms +). Then I've tried with window.onhashchange but it didn't change anything. I just needed something that would detect a change before user sees anything.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's worth to keep in mind that MutationObserver with such an extensive config might be performance heavy. It also sounds to me that it's used to fix a problem that should not occur - I don't think that screen should flick every time you change the URL. Maybe it would be better to spend more time on it and fix it properly.
I would suggest at least adding a short comment explaining why MutationObserver is used so future developers working on it have a clear understanding.
if (!_.isEmpty($(suiteContainer).prevAll( | ||
'.aside-report:not(.is-hidden)').first() | ||
.find('.test-name'))) { | ||
currentTab = $('.nav-tabs > .nav-item').filter('.active').text().replace(/\s/g, ''); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@oliwerin what is the problem with existing those two classes?
If you recommend to align them, please do so in a separate pull request.
$previousElement.click(); | ||
currentItem.parents('.url-name').removeClass('is-active'); | ||
suiteContainer.addClass('is-expanded'); | ||
if (!_.isEmpty($(suiteContainer).prevAll( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe it would be worth to put following 20 lines into a separate method? traverseTreeUp
is a little to long now.
function clickOnTab() { | ||
var currentTab = userSettingsService.getLastTab(); | ||
var nextTestTabs = $('.nav-tabs').children(); | ||
for(var i=0;i <nextTestTabs.length; i++) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you also fix formatting? Thanks.
|
||
function callback(mutList) { | ||
var finished = false; | ||
mutList.forEach(function(mut) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about using Array.prototype.find()
insead of forEach
? You wouldn't have to do this nasty finished
guard and finish forEach
loop (better performance).
testContainer.removeClass('is-active'); | ||
currentItem.removeClass('is-active'); | ||
toggleNextTest(suiteContainer); | ||
currentTabLabel = $('.nav-tabs > .nav-item').filter('.active').text().replace(/\s/g, ''); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indentation seems to be out of place in this line
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, didn't notice. Fixed now.
|
||
function clickOnTab() { | ||
var currentTabLabel = userSettingsService.getLastTab(); | ||
var $nextTestTabs = $('.nav-tabs').children(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In some places you use multiple var
notation (here) and in others one var
and variables declarations separated out by a comma. I'd be good to stick with just one of them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed, but I still got some stuff to do (with MutationObserver) so I will commit tomorrow.
Please update Changelog file https://github.com/Cognifide/aet/blob/master/CONTRIBUTING.md#changelog |
testContainer.removeClass('is-active'); | ||
currentItem.removeClass('is-active'); | ||
toggleNextTest(suiteContainer); | ||
currentTabLabel = $('.nav-tabs > .nav-item').filter('.active').text().replace(/\s/g, ''); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line is repeated across the file few times - can it be moved to a seperate function, e.g. getCurrentTabLabel
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
User now stays in the same tab while navigating around tests tree.
Description
Moving around the tree by using [ ] or arrows now automatically opens up url view instead of test view. User also stays on the same tab when moving between urls. If the same type of tab isn't found on the next/previous test url then first tab is selected.
Motivation and Context
Fix for issue: #70 - Navigating between pages should remain user on the same tab
Types of changes
Checklist:
I hereby agree to the terms of the AET Contributor License Agreement.