-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
Remove underscore usage #40346
Remove underscore usage #40346
Changes from 12 commits
3a905c7
81f4716
2fe221d
84ab150
7c9704b
ac5a4dd
0cc0b12
861ea79
cca7dd7
c95933b
5995e6c
612b324
5901f28
583ccaa
880ef45
99760ff
b7bb995
26e3367
15c00f0
3c4bcf8
2b51b64
2be0ef2
60b1ade
c6ee94f
fbb7e8b
8ce0836
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,13 @@ | ||
import lodashDebounce from 'lodash/debounce'; | ||
import lodashFind from 'lodash/find'; | ||
import lodashFindIndex from 'lodash/findIndex'; | ||
import lodashGet from 'lodash/get'; | ||
import lodashIsEqual from 'lodash/isEqual'; | ||
import lodashMap from 'lodash/map'; | ||
import lodashValues from 'lodash/values'; | ||
import PropTypes from 'prop-types'; | ||
import React, {Component} from 'react'; | ||
import {View} from 'react-native'; | ||
import _ from 'underscore'; | ||
import ArrowKeyFocusManager from '@components/ArrowKeyFocusManager'; | ||
import Button from '@components/Button'; | ||
import FixedFooter from '@components/FixedFooter'; | ||
|
@@ -77,9 +82,9 @@ class BaseOptionsSelector extends Component { | |
this.calculateAllVisibleOptionsCount = this.calculateAllVisibleOptionsCount.bind(this); | ||
this.handleFocusIn = this.handleFocusIn.bind(this); | ||
this.handleFocusOut = this.handleFocusOut.bind(this); | ||
this.debouncedUpdateSearchValue = _.debounce(this.updateSearchValue, CONST.TIMING.SEARCH_OPTION_LIST_DEBOUNCE_TIME); | ||
this.debouncedUpdateSearchValue = lodashDebounce(this.updateSearchValue, CONST.TIMING.SEARCH_OPTION_LIST_DEBOUNCE_TIME); | ||
this.relatedTarget = null; | ||
this.accessibilityRoles = _.values(CONST.ROLE); | ||
this.accessibilityRoles = lodashValues(CONST.ROLE); | ||
this.isWebOrDesktop = [CONST.PLATFORM.DESKTOP, CONST.PLATFORM.WEB].includes(getPlatform()); | ||
|
||
const allOptions = this.flattenSections(); | ||
|
@@ -155,7 +160,7 @@ class BaseOptionsSelector extends Component { | |
this.focusedOption = this.state.allOptions[this.state.focusedIndex]; | ||
} | ||
|
||
if (_.isEqual(this.props.sections, prevProps.sections)) { | ||
if (lodashIsEqual(this.props.sections, prevProps.sections)) { | ||
return; | ||
} | ||
|
||
|
@@ -171,14 +176,14 @@ class BaseOptionsSelector extends Component { | |
} | ||
const newFocusedIndex = this.props.selectedOptions.length; | ||
const isNewFocusedIndex = newFocusedIndex !== this.state.focusedIndex; | ||
const prevFocusedOption = _.find(newOptions, (option) => this.focusedOption && option.keyForList === this.focusedOption.keyForList); | ||
const prevFocusedOptionIndex = prevFocusedOption ? _.findIndex(newOptions, (option) => this.focusedOption && option.keyForList === this.focusedOption.keyForList) : undefined; | ||
const prevFocusedOption = lodashFind(newOptions, (option) => this.focusedOption && option.keyForList === this.focusedOption.keyForList); | ||
const prevFocusedOptionIndex = prevFocusedOption ? lodashFindIndex(newOptions, (option) => this.focusedOption && option.keyForList === this.focusedOption.keyForList) : undefined; | ||
// eslint-disable-next-line react/no-did-update-set-state | ||
this.setState( | ||
{ | ||
sections: newSections, | ||
allOptions: newOptions, | ||
focusedIndex: prevFocusedOptionIndex || (_.isNumber(this.props.focusedIndex) ? this.props.focusedIndex : newFocusedIndex), | ||
focusedIndex: prevFocusedOptionIndex || (typeof this.props.focusedIndex === 'number' ? this.props.focusedIndex : newFocusedIndex), | ||
}, | ||
() => { | ||
// If we just toggled an option on a multi-selection page or cleared the search input, scroll to top | ||
|
@@ -230,11 +235,11 @@ class BaseOptionsSelector extends Component { | |
} else { | ||
defaultIndex = this.props.selectedOptions.length; | ||
} | ||
if (_.isUndefined(this.props.initiallyFocusedOptionKey)) { | ||
if (typeof this.props.initiallyFocusedOptionKey === 'undefined') { | ||
return defaultIndex; | ||
} | ||
|
||
const indexOfInitiallyFocusedOption = _.findIndex(allOptions, (option) => option.keyForList === this.props.initiallyFocusedOptionKey); | ||
const indexOfInitiallyFocusedOption = lodashFindIndex(allOptions, (option) => option.keyForList === this.props.initiallyFocusedOptionKey); | ||
|
||
return indexOfInitiallyFocusedOption; | ||
} | ||
|
@@ -245,8 +250,8 @@ class BaseOptionsSelector extends Component { | |
* @returns {Objects[]} | ||
*/ | ||
sliceSections() { | ||
return _.map(this.props.sections, (section) => { | ||
if (_.isEmpty(section.data)) { | ||
return lodashMap(this.props.sections, (section) => { | ||
if (section.data.length === 0) { | ||
return section; | ||
} | ||
|
||
|
@@ -266,7 +271,7 @@ class BaseOptionsSelector extends Component { | |
calculateAllVisibleOptionsCount() { | ||
let count = 0; | ||
|
||
_.forEach(this.state.sections, (section) => { | ||
this.state.sections.forEach((section) => { | ||
count += lodashGet(section, 'data.length', 0); | ||
}); | ||
|
||
|
@@ -347,7 +352,7 @@ class BaseOptionsSelector extends Component { | |
|
||
selectFocusedOption(e) { | ||
const focusedItemKey = lodashGet(e, ['target', 'attributes', 'id', 'value']); | ||
const focusedOption = focusedItemKey ? _.find(this.state.allOptions, (option) => option.keyForList === focusedItemKey) : this.state.allOptions[this.state.focusedIndex]; | ||
const focusedOption = focusedItemKey ? lodashFind(this.state.allOptions, (option) => option.keyForList === focusedItemKey) : this.state.allOptions[this.state.focusedIndex]; | ||
|
||
if (!focusedOption || !this.props.isFocused) { | ||
return; | ||
|
@@ -393,8 +398,8 @@ class BaseOptionsSelector extends Component { | |
const allOptions = []; | ||
this.disabledOptionsIndexes = []; | ||
let index = 0; | ||
_.each(this.props.sections, (section, sectionIndex) => { | ||
_.each(section.data, (option, optionIndex) => { | ||
this.props.sections.forEach((section, sectionIndex) => { | ||
section.data.forEach((option, optionIndex) => { | ||
allOptions.push({ | ||
...option, | ||
sectionIndex, | ||
|
@@ -496,8 +501,8 @@ class BaseOptionsSelector extends Component { | |
render() { | ||
const shouldShowShowMoreButton = this.state.allOptions.length > CONST.MAX_OPTIONS_SELECTOR_PAGE_LENGTH * this.state.paginationPage; | ||
const shouldShowFooter = | ||
!this.props.isReadOnly && (this.props.shouldShowConfirmButton || this.props.footerContent) && !(this.props.canSelectMultipleOptions && _.isEmpty(this.props.selectedOptions)); | ||
const defaultConfirmButtonText = _.isUndefined(this.props.confirmButtonText) ? this.props.translate('common.confirm') : this.props.confirmButtonText; | ||
!this.props.isReadOnly && (this.props.shouldShowConfirmButton || this.props.footerContent) && !(this.props.canSelectMultipleOptions && this.props.selectedOptions.length === 0); | ||
const defaultConfirmButtonText = typeof this.props.confirmButtonText === 'undefined' ? this.props.translate('common.confirm') : this.props.confirmButtonText; | ||
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. NAB, I think 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. You're right, updated! |
||
const shouldShowDefaultConfirmButton = !this.props.footerContent && defaultConfirmButtonText; | ||
const safeAreaPaddingBottomStyle = shouldShowFooter ? undefined : this.props.safeAreaPaddingBottomStyle; | ||
const listContainerStyles = this.props.listContainerStyles || [this.props.themeStyles.flex1]; | ||
|
This file was deleted.
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.
@blazejkustra We got lint errors when I removed this. Do we want to update
eslint-config-expensify
to remove this rule or keep turning this rule off?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 feel like we should
eslint-config-expensify
.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.
@mountiny can you confirm?
I will update this tomorrow
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 have turned this off and added back
npm install underscore
inCIGitLogicTest
for now since we don't have any answer yet. I think you can start reviewing it. @hungvu193There 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.
Btw, I ask for the help in slack
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.
Sure. I'll review in a while