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

Fixed #70 - user now stays in the same tab while navigating around th… #289

Merged

Conversation

m-suchorski
Copy link

@m-suchorski m-suchorski commented Jul 18, 2018

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

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.

I hereby agree to the terms of the AET Contributor License Agreement.

@@ -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, '');

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?

Copy link
Author

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.

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, '');

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

Copy link
Author

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)?

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.

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, '');

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?

Copy link
Author

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.

Copy link
Contributor

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.

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++) {

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?

Copy link
Author

Choose a reason for hiding this comment

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

I will change that.

Copy link
Contributor

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();
Copy link

@oliwerin oliwerin Jul 18, 2018

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

Copy link
Author

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);

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?

Copy link
Author

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.

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?

Copy link
Author

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.

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, '');
Copy link
Contributor

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(
Copy link
Contributor

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++) {
Copy link
Contributor

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) {
Copy link
Contributor

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, '');

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

Copy link
Author

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();
Copy link

@oliwerin oliwerin Jul 19, 2018

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.

Copy link
Author

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.

@tkaik
Copy link
Contributor

tkaik commented Jul 19, 2018

testContainer.removeClass('is-active');
currentItem.removeClass('is-active');
toggleNextTest(suiteContainer);
currentTabLabel = $('.nav-tabs > .nav-item').filter('.active').text().replace(/\s/g, '');
Copy link
Contributor

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?

Copy link
Author

Choose a reason for hiding this comment

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

Fixed.

@malaskowski malaskowski merged commit 97272c8 into wttech:master Jul 30, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants