Skip to content
This repository has been archived by the owner on Dec 11, 2019. It is now read-only.

Refactors TabPage and TabPages into redux #9414

Merged
merged 1 commit into from
Jun 15, 2017

Conversation

NejcZdovc
Copy link
Contributor

@NejcZdovc NejcZdovc commented Jun 13, 2017

Test Plan

  • try to open enough tabs to trigger tab page (default is 20)
  • see if audio indicator is displayed if you have video playing in tab page
  • check if you can close tab page (note about Close tab page is not working #9420)
  • check if you can mute/unmute tab page

Description

Submitter Checklist:

  • Submitted a ticket for my issue if one did not already exist.
  • Used Github auto-closing keywords in the commit message.
  • Added/updated tests for this change (for new code or code which already has tests).
  • Ran git rebase -i to squash commits (if needed).
  • Tagged reviewers and labelled the pull request as needed.

Resolves #9339

Auditors: @bsclifton @bridiver

Reviewer Checklist:

  • Adequate test coverage exists to prevent regressions
  • Tests should be independent and work correctly when run individually or as a suite ref
  • New files have MPL2 license header

Copy link
Member

@bsclifton bsclifton left a comment

Choose a reason for hiding this comment

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

Likely not caused by this PR, but I did discover a bug.

  1. Have two tab pages
  2. In tab page 1, mute one of the two videos
  3. Switch to tab page 2
  4. Right click tab page indicator, pick "Mute Tabs"
  5. Notice that the mute for tabs is toggled, not set to false
  6. Picking unmute seems to work fine

update: captured with #9464

Copy link
Member

@bsclifton bsclifton left a comment

Choose a reason for hiding this comment

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

Left a comment regarding adding one unit test (for TabPages, the page count). Other properties being tested is welcomed too 😄

Test plan worked, other than the mute/unmute scenario I noted. I'll capture a separate issue for that (or if it exists, +1 it)

const sourceDragData = dndData.getDragData(e.dataTransfer, dragTypes.TAB)
const sourceDragFromPageIndex = this.props.sourceDragFromPageIndex
// This must be executed async because the state change that this causes
// will cause the onDragEnd to never run
setTimeout(() => {
// If we're moving to a right page, then we're already shifting everything to the left by one, so we want
// to drop it on the right.
windowActions.moveTab(sourceDragData.get('key'), moveToFrame.get('key'),
windowActions.moveTab(sourceDragData.get('key'), this.props.moveToFrameKey,
Copy link
Member

Choose a reason for hiding this comment

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

Should we still be using windowActions / frameKey? I think it would make more sense to use appAction / tabId

Copy link
Member

Choose a reason for hiding this comment

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

Although, that change might be quite a bit larger. I'd be OK with us doing that later 😄

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah when I am doing refactors I try to keep it as close as possible, because this way we are less error prone and we will have a few more iterations of redux components anyway when we will start moving into apps state (state helpers)

const tabsPerPage = Number(getSetting(settings.TABS_PER_PAGE))

const props = {}
props.tabPageCount = Math.ceil(frames.size / tabsPerPage)
Copy link
Member

Choose a reason for hiding this comment

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

can this but put into a property? that way we can unit test it 😄

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You mean into function?

Copy link
Member

Choose a reason for hiding this comment

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

@NejcZdovc yeah- basically the ES6 classes have "properties" when they're exposed using a getter. Like:

class TabPage extends React.Component {
  //..
  get tabPageCount () {
    return Math.ceil(this.frames.size / this.tabsPerPage)
  }
  //..

versus a typical method or function

class TabPage extends React.Component {
  //..
  tabPageCount () {}
}

function tabPageCount() {}

Copy link
Member

Choose a reason for hiding this comment

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

Getters are very easy to test using Enzyme 😄

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Problem is that you can't use getter in mergeProps, because you don't have access to the component. So what we can do is create helper in util file

Copy link
Member

@bsclifton bsclifton Jun 14, 2017

Choose a reason for hiding this comment

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

ahh that's right! I had forgotten 😄 I saw you use getters in #9413, but I now see those are in render. Util function would be great 😄

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes you can use getters for html content so that renderer is not that big, but one thing that you need to be carful is that you always trigger re-render when needed. That means that you shouldn't do any calculation inside the getter that can change getter return.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Moved into util file and added unit tests

Resolves brave#9339

Auditors: @bsclifton @bridiver

Test Plan:
- try to open enaugh tabs to trigger tab page (default is 20)
- see if audio indicator is displayed if you have video playing in tab page
- check if you can close tab page
Copy link
Member

@bsclifton bsclifton left a comment

Choose a reason for hiding this comment

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

Huge thanks for adding the tests 😄 👍 Changes look great

@bsclifton bsclifton merged commit ed4824b into brave:master Jun 15, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Redux component - Tab page
2 participants