This repository has been archived by the owner on Dec 11, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 973
Converts ImportBrowserDataPanel into redux component #9485
Merged
NejcZdovc
merged 1 commit into
brave:master
from
NejcZdovc:redux/importBrowserDataPanel
Jun 17, 2017
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,9 +4,10 @@ | |
|
||
const React = require('react') | ||
const {StyleSheet, css} = require('aphrodite/no-important') | ||
const Immutable = require('immutable') | ||
|
||
// Components | ||
const ImmutableComponent = require('../immutableComponent') | ||
const ReduxComponent = require('../reduxComponent') | ||
const Dialog = require('../common/dialog') | ||
const Button = require('../common/button') | ||
const SwitchControl = require('../common/switchControl') | ||
|
@@ -20,106 +21,82 @@ const { | |
} = require('../common/commonForm') | ||
|
||
// Actions | ||
const windowActions = require('../../../../js/actions/windowActions') | ||
const appActions = require('../../../../js/actions/appActions') | ||
const windowActions = require('../../../../js/actions/windowActions') | ||
|
||
// Styles | ||
const globalStyles = require('../styles/global') | ||
|
||
class ImportBrowserDataPanel extends ImmutableComponent { | ||
constructor () { | ||
super() | ||
class ImportBrowserDataPanel extends React.Component { | ||
constructor (props) { | ||
super(props) | ||
this.onToggleHistory = this.onToggleSetting.bind(this, 'history') | ||
this.onToggleFavorites = this.onToggleSetting.bind(this, 'favorites') | ||
this.onToggleCookies = this.onToggleSetting.bind(this, 'cookies') | ||
this.onImport = this.onImport.bind(this) | ||
this.onChange = this.onChange.bind(this) | ||
} | ||
|
||
onToggleSetting (setting, e) { | ||
windowActions.setImportBrowserDataSelected(this.props.importBrowserDataSelected.set(setting, e.target.value)) | ||
} | ||
get browserData () { | ||
let index = this.props.importBrowserDataSelected.get('index') | ||
if (index === undefined) { | ||
index = '0' | ||
} | ||
return this.props.importBrowserDataDetail.get(index) | ||
} | ||
get supportHistory () { | ||
let browserData = this.browserData | ||
if (browserData === undefined) { | ||
return false | ||
} | ||
return browserData.get('history') | ||
} | ||
get supportFavorites () { | ||
let browserData = this.browserData | ||
if (browserData === undefined) { | ||
return false | ||
} | ||
return browserData.get('favorites') | ||
} | ||
get supportCookies () { | ||
let browserData = this.browserData | ||
if (browserData === undefined) { | ||
return false | ||
} | ||
return browserData.get('cookies') | ||
windowActions.setImportBrowserDataSelected({ | ||
[setting]: e.target.value | ||
}) | ||
} | ||
|
||
onImport () { | ||
let index = this.props.importBrowserDataSelected.get('index') | ||
if (index === undefined) { | ||
this.props.importBrowserDataSelected = this.props.importBrowserDataSelected.set('index', '0') | ||
} | ||
let browserData = this.browserData | ||
if (browserData !== undefined) { | ||
let type = browserData.get('type') | ||
this.props.importBrowserDataSelected = this.props.importBrowserDataSelected.set('type', type) | ||
} | ||
appActions.importBrowserData(this.props.importBrowserDataSelected) | ||
this.props.onHide() | ||
let data = {} | ||
data.index = this.props.selectedIndex.toString() | ||
data.cookies = this.props.cookies | ||
data.favorites = this.props.favorites | ||
data.history = this.props.history | ||
data.type = this.props.type | ||
|
||
appActions.importBrowserData(Immutable.fromJS(data)) | ||
this.onHide() | ||
} | ||
|
||
onChange (e) { | ||
this.props.importBrowserDataSelected = this.props.importBrowserDataSelected.set('index', e.target.value) | ||
this.props.importBrowserDataSelected = this.props.importBrowserDataSelected.set('history', false) | ||
this.props.importBrowserDataSelected = this.props.importBrowserDataSelected.set('favorites', false) | ||
this.props.importBrowserDataSelected = this.props.importBrowserDataSelected.set('cookies', false) | ||
let importBrowserDataSelected = this.props.importBrowserDataSelected | ||
if (this.supportHistory) { | ||
importBrowserDataSelected = importBrowserDataSelected.set('history', true) | ||
} | ||
if (this.supportFavorites) { | ||
importBrowserDataSelected = importBrowserDataSelected.set('favorites', true) | ||
} | ||
if (this.supportCookies) { | ||
importBrowserDataSelected = importBrowserDataSelected.set('cookies', true) | ||
} | ||
windowActions.setImportBrowserDataSelected(importBrowserDataSelected) | ||
windowActions.setImportBrowserDataSelected(~~e.target.value) | ||
} | ||
|
||
onHide () { | ||
windowActions.setImportBrowserDataDetail() | ||
} | ||
get selectedBrowser () { | ||
let index = this.props.importBrowserDataSelected.get('index') | ||
if (index === undefined) { | ||
this.props.importBrowserDataSelected = this.props.importBrowserDataSelected.set('index', '0') | ||
if (this.supportHistory) { | ||
this.props.importBrowserDataSelected = this.props.importBrowserDataSelected.set('history', true) | ||
} | ||
if (this.supportFavorites) { | ||
this.props.importBrowserDataSelected = this.props.importBrowserDataSelected.set('favorites', true) | ||
} | ||
if (this.supportCookies) { | ||
this.props.importBrowserDataSelected = this.props.importBrowserDataSelected.set('cookies', true) | ||
} | ||
|
||
componentWillMount () { | ||
if (this.props.selectedIndex == null) { | ||
windowActions.setImportBrowserDataSelected(0) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nice cleanup |
||
} | ||
return index !== undefined ? index : '0' | ||
} | ||
|
||
mergeProps (state, ownProps) { | ||
const currentWindow = state.get('currentWindow') | ||
const importBrowserDataSelected = currentWindow.get('importBrowserDataSelected', Immutable.Map()) | ||
const importBrowserDataDetail = currentWindow.get('importBrowserDataDetail', Immutable.Map()) | ||
const index = importBrowserDataSelected.get('index', '0') | ||
const currentSelectedBrowser = importBrowserDataDetail.get(index, Immutable.Map()) | ||
|
||
const props = {} | ||
// used in renderer | ||
props.browserNames = importBrowserDataDetail.map((browser) => browser.get('name')) | ||
props.browserIndexes = importBrowserDataDetail.map((browser) => browser.get('index')) | ||
props.isSupportingHistory = currentSelectedBrowser.get('history', false) | ||
props.isSupportingFavorites = currentSelectedBrowser.get('favorites', false) | ||
props.isSupportingCookies = currentSelectedBrowser.get('cookies', false) | ||
props.currentIndex = index | ||
props.cookies = importBrowserDataSelected.get('cookies') | ||
props.favorites = importBrowserDataSelected.get('favorites') | ||
props.history = importBrowserDataSelected.get('history') | ||
props.type = importBrowserDataSelected.get('type') | ||
|
||
// used in other functions | ||
props.selectedIndex = importBrowserDataSelected.get('index') | ||
|
||
return props | ||
} | ||
|
||
render () { | ||
var browsers = [] | ||
if (this.props.importBrowserDataDetail !== undefined) { | ||
this.props.importBrowserDataDetail.toJS().forEach((browser) => { | ||
browsers.push(<option value={browser.index}>{browser.name}</option>) | ||
}) | ||
} | ||
return <Dialog onHide={this.props.onHide} testId='importBrowserDataPanel' isClickDismiss> | ||
return <Dialog onHide={this.onHide} testId='importBrowserDataPanel' isClickDismiss> | ||
<CommonForm data-test-id='importBrowserData' onClick={(e) => e.stopPropagation()}> | ||
<CommonFormTitle | ||
data-test-id='importBrowserDataTitle' | ||
|
@@ -128,35 +105,39 @@ class ImportBrowserDataPanel extends ImmutableComponent { | |
<CommonFormSection data-test-id='importBrowserDataOptions'> | ||
<div className={css(styles.dropdownWrapper)}> | ||
<CommonFormDropdown | ||
value={this.selectedBrowser} | ||
value={this.props.currentIndex} | ||
onChange={this.onChange} > | ||
{browsers} | ||
{ | ||
this.props.browserNames.map((name, i) => { | ||
return <option value={this.props.browserIndexes.get(i)}>{name}</option> | ||
}) | ||
} | ||
</CommonFormDropdown> | ||
</div> | ||
<SwitchControl | ||
rightl10nId='browserHistory' | ||
checkedOn={this.props.importBrowserDataSelected.get('history')} | ||
checkedOn={this.props.history} | ||
onClick={this.onToggleHistory} | ||
disabled={!this.supportHistory} | ||
disabled={!this.props.isSupportingHistory} | ||
/> | ||
<SwitchControl | ||
rightl10nId='favoritesOrBookmarks' | ||
checkedOn={this.props.importBrowserDataSelected.get('favorites')} | ||
checkedOn={this.props.favorites} | ||
onClick={this.onToggleFavorites} | ||
disabled={!this.supportFavorites} | ||
disabled={!this.props.isSupportingFavorites} | ||
/> | ||
<SwitchControl | ||
rightl10nId='cookies' | ||
checkedOn={this.props.importBrowserDataSelected.get('cookies')} | ||
checkedOn={this.props.cookies} | ||
onClick={this.onToggleCookies} | ||
disabled={!this.supportCookies} | ||
disabled={!this.props.isSupportingCookies} | ||
/> | ||
</CommonFormSection> | ||
<CommonFormSection> | ||
<div data-l10n-id='importDataCloseBrowserWarning' /> | ||
</CommonFormSection> | ||
<CommonFormButtonWrapper data-test-id='importBrowserDataButtons'> | ||
<Button l10nId='cancel' className='whiteButton' onClick={this.props.onHide} /> | ||
<Button l10nId='cancel' className='whiteButton' onClick={this.onHide} /> | ||
<Button l10nId='import' className='primaryButton' onClick={this.onImport} /> | ||
</CommonFormButtonWrapper> | ||
<CommonFormBottomWrapper data-test-id='importBrowserDataWarning'> | ||
|
@@ -167,10 +148,10 @@ class ImportBrowserDataPanel extends ImmutableComponent { | |
} | ||
} | ||
|
||
module.exports = ReduxComponent.connect(ImportBrowserDataPanel) | ||
|
||
const styles = StyleSheet.create({ | ||
dropdownWrapper: { | ||
marginBottom: `calc(${globalStyles.spacing.dialogInsideMargin} / 2)` | ||
} | ||
}) | ||
|
||
module.exports = ImportBrowserDataPanel |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 think this check can be removed. Is there any case it will have value when
componentWillMount
being called?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 would leave it