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

Commit cb2cfa1

Browse files
committed
replace legacy logic with brand new NewSessionIcon state logic
- transitory state: tabs are responsible but still looks ugly. Auditors: @NejcZdovc, @luixxiul Test plan: npm run test -- --grep="Tabs content - NewSessionIcon"
1 parent f672622 commit cb2cfa1

File tree

4 files changed

+118
-249
lines changed

4 files changed

+118
-249
lines changed

app/common/state/tabContentState/partitionState.js

+17
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* You can obtain one at http://mozilla.org/MPL/2.0/. */
44

55
// State helpers
6+
const tabUIState = require('../tabUIState')
67
const frameStateUtil = require('../../../../js/state/frameStateUtil')
78

89
// Constants
@@ -54,3 +55,19 @@ module.exports.getMaxAllowedPartitionNumber = (state, frameKey) => {
5455
}
5556
return partitionNumber
5657
}
58+
59+
module.exports.showPartitionIcon = (state, frameKey) => {
60+
const frame = frameStateUtil.getFrameByKey(state, frameKey)
61+
62+
if (frame == null) {
63+
if (process.env.NODE_ENV !== 'test') {
64+
console.error('Unable to find frame for showPartitionIcon method')
65+
}
66+
return false
67+
}
68+
69+
return (
70+
module.exports.isPartitionTab(state, frameKey) &&
71+
tabUIState.showTabEndIcon(state, frameKey)
72+
)
73+
}
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,18 @@
11
/* This Source Code Form is subject to the terms of the Mozilla Public
2-
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
3-
* You can obtain one at http://mozilla.org/MPL/2.0/. */
2+
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
3+
* You can obtain one at http://mozilla.org/MPL/2.0/. */
44

55
const React = require('react')
66
const {StyleSheet, css} = require('aphrodite/no-important')
7-
const Immutable = require('immutable')
87

98
// Components
109
const ReduxComponent = require('../../reduxComponent')
1110
const TabIcon = require('./tabIcon')
1211

1312
// State
13+
const partitionState = require('../../../../common/state/tabContentState/partitionState')
1414
const tabUIState = require('../../../../common/state/tabUIState')
15-
16-
// Constants
17-
const {tabs} = require('../../../../../js/constants/config')
18-
19-
// Utils
15+
const tabState = require('../../../../common/state/tabState')
2016
const frameStateUtil = require('../../../../../js/state/frameStateUtil')
2117

2218
// Styles
@@ -26,44 +22,39 @@ const newSessionSvg = require('../../../../extensions/brave/img/tabs/new_session
2622
class NewSessionIcon extends React.Component {
2723
mergeProps (state, ownProps) {
2824
const currentWindow = state.get('currentWindow')
29-
const frameKey = ownProps.frameKey
30-
const frame = frameStateUtil.getFrameByKey(currentWindow, frameKey) || Immutable.Map()
31-
const partition = frame.get('partitionNumber')
32-
const hasSeconardImage = tabUIState.hasVisibleSecondaryIcon(currentWindow, ownProps.frameKey)
25+
const tabId = ownProps.tabId
26+
const frameKey = frameStateUtil.getFrameKeyByTabId(currentWindow, tabId)
3327

3428
const props = {}
35-
// used in renderer
36-
props.showSessionIcon = !!partition && hasSeconardImage
29+
props.isPinned = tabState.isTabPinned(state, tabId)
30+
props.showPartitionIcon = partitionState.showPartitionIcon(currentWindow, frameKey)
3731
props.isActive = frameStateUtil.isFrameKeyActive(currentWindow, frameKey)
38-
props.iconColor = tabUIState.getTabIconColor(currentWindow, frameKey)
39-
props.partitionNumber = typeof partition === 'string'
40-
? partition.replace(/^partition-/i, '')
41-
: partition
42-
props.partitionIndicator = props.partitionNumber > tabs.maxAllowedNewSessions
43-
? tabs.maxAllowedNewSessions
44-
: props.partitionNumber
45-
46-
// used in functions
47-
props.frameKey = frameKey
32+
props.textIsWhite = tabUIState.checkIfTextColor(currentWindow, frameKey, 'white')
33+
props.partitionNumber = partitionState.getMaxAllowedPartitionNumber(currentWindow, frameKey)
34+
props.tabId = tabId
4835

4936
return props
5037
}
5138

5239
render () {
53-
if (!this.props.showSessionIcon) {
40+
if (
41+
this.props.isPinned ||
42+
!this.props.showPartitionIcon ||
43+
this.props.partitionNumber === 0
44+
) {
5445
return null
5546
}
56-
const newSession = StyleSheet.create({
57-
indicator: {
58-
// Based on getTextColorForBackground() icons can be only black or white.
59-
filter: this.props.isActive && this.props.iconColor === 'white' ? 'invert(100%)' : 'none'
47+
48+
const newSessionProps = StyleSheet.create({
49+
newSession__indicator: {
50+
filter: this.props.isActive && this.props.textIsWhite ? 'invert(100%)' : 'none'
6051
}
6152
})
6253

6354
return <TabIcon symbol
6455
data-test-id='newSessionIcon'
65-
className={css(styles.icon, styles.newSession, newSession.indicator)}
66-
symbolContent={this.props.partitionIndicator}
56+
className={css(styles.newSession__icon, newSessionProps.newSession__indicator)}
57+
symbolContent={this.props.partitionNumber}
6758
l10nArgs={this.props.partitionNumber}
6859
l10nId='sessionInfoTab'
6960
/>
@@ -73,21 +64,17 @@ class NewSessionIcon extends React.Component {
7364
module.exports = ReduxComponent.connect(NewSessionIcon)
7465

7566
const styles = StyleSheet.create({
76-
icon: {
67+
newSession__icon: {
68+
zIndex: 99,
69+
boxSizing: 'border-box',
70+
display: 'flex',
71+
alignItems: 'center',
72+
backgroundImage: `url(${newSessionSvg})`,
73+
backgroundPosition: 'center left',
74+
backgroundRepeat: 'no-repeat',
75+
backgroundSize: '13px',
7776
width: globalStyles.spacing.iconSize,
78-
minWidth: globalStyles.spacing.iconSize,
7977
height: globalStyles.spacing.iconSize,
80-
backgroundSize: globalStyles.spacing.iconSize,
81-
fontSize: globalStyles.fontSize.tabIcon,
82-
backgroundPosition: 'center',
83-
backgroundRepeat: 'no-repeat',
84-
paddingLeft: globalStyles.spacing.defaultIconPadding,
85-
paddingRight: globalStyles.spacing.defaultIconPadding
86-
},
87-
88-
newSession: {
89-
position: 'relative',
90-
backgroundImage: `url(${newSessionSvg})`,
91-
backgroundPosition: 'left'
78+
marginRight: globalStyles.spacing.defaultTabMargin
9279
}
9380
})

app/renderer/components/tabs/tab.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ class Tab extends React.Component {
371371
<TabTitle tabId={this.props.tabId} />
372372
</div>
373373
<PrivateIcon tabId={this.props.tabId} />
374-
<NewSessionIcon frameKey={this.props.frameKey} />
374+
<NewSessionIcon tabId={this.props.tabId} />
375375
<CloseTabIcon tabId={this.props.tabId} fixTabWidth={this.fixTabWidth} />
376376
</div>
377377
</div>

0 commit comments

Comments
 (0)