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

Remove underscore usage #40346

Merged
merged 26 commits into from
Apr 22, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
3a905c7
remove underscore and unused file
bernhardoj Apr 17, 2024
81f4716
remove unnecessary eslint disable
bernhardoj Apr 18, 2024
2fe221d
Merge branch 'main' into chore/39121-remove-underscore
bernhardoj Apr 18, 2024
84ab150
remove unnecessary eslint disable
bernhardoj Apr 18, 2024
7c9704b
don't install underscore
bernhardoj Apr 18, 2024
ac5a4dd
replace underscore with lodash
bernhardoj Apr 18, 2024
0cc0b12
fix lint
bernhardoj Apr 18, 2024
861ea79
prettier
bernhardoj Apr 18, 2024
cca7dd7
uninstall underscore
bernhardoj Apr 18, 2024
c95933b
update comment
bernhardoj Apr 18, 2024
5995e6c
fix lint
bernhardoj Apr 18, 2024
612b324
remove underscore rule
bernhardoj Apr 18, 2024
5901f28
Merge branch 'main' into chore/39121-remove-underscore
bernhardoj Apr 19, 2024
583ccaa
turn off prefer underscore lint back
bernhardoj Apr 19, 2024
880ef45
add back underscore
bernhardoj Apr 19, 2024
99760ff
prettier
bernhardoj Apr 19, 2024
b7bb995
remove underscore guideline
bernhardoj Apr 19, 2024
26e3367
Merge branch 'main' into chore/39121-remove-underscore
bernhardoj Apr 19, 2024
15c00f0
Merge branch 'main' into chore/39121-remove-underscore
bernhardoj Apr 20, 2024
3c4bcf8
remove unused files
bernhardoj Apr 20, 2024
2b51b64
remove underscore from code example
bernhardoj Apr 20, 2024
2be0ef2
Merge branch 'main' into chore/39121-remove-underscore
bernhardoj Apr 22, 2024
60b1ade
simplify code
bernhardoj Apr 22, 2024
c6ee94f
replaced underscore with lodash
bernhardoj Apr 22, 2024
fbb7e8b
Merge branch 'main' into chore/39121-remove-underscore
bernhardoj Apr 22, 2024
8ce0836
update doc
bernhardoj Apr 22, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions src/ROUTES.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,11 +202,6 @@ const ROUTES = {
route: 'r/:reportID/avatar',
getRoute: (reportID: string) => `r/${reportID}/avatar` as const,
},
EDIT_REQUEST: {
route: 'r/:threadReportID/edit/:field/:tagIndex?',
getRoute: (threadReportID: string, field: ValueOf<typeof CONST.EDIT_REQUEST_FIELD>, tagIndex?: number) =>
`r/${threadReportID}/edit/${field}${typeof tagIndex === 'number' ? `/${tagIndex}` : ''}` as const,
},
EDIT_CURRENCY_REQUEST: {
route: 'r/:threadReportID/edit/currency',
getRoute: (threadReportID: string, currency: string, backTo: string) => `r/${threadReportID}/edit/currency?currency=${currency}&backTo=${backTo}` as const,
Expand Down
1 change: 0 additions & 1 deletion src/SCREENS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,6 @@ const SCREENS = {
},

EDIT_REQUEST: {
ROOT: 'EditRequest_Root',
mountiny marked this conversation as resolved.
Show resolved Hide resolved
CURRENCY: 'EditRequest_Currency',
REPORT_FIELD: 'EditRequest_ReportField',
},
Expand Down
89 changes: 0 additions & 89 deletions src/components/Modal/modalPropTypes.js

This file was deleted.

35 changes: 18 additions & 17 deletions src/components/OptionsSelector/BaseOptionsSelector.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import lodashDebounce from 'lodash/debounce';
import lodashGet from 'lodash/get';
import lodashIsEqual from 'lodash/isEqual';
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';
Expand Down Expand Up @@ -77,9 +78,9 @@
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 = Object.values(CONST.ROLE);

Check failure on line 83 in src/components/OptionsSelector/BaseOptionsSelector.js

View workflow job for this annotation

GitHub Actions / Run ESLint

Prefer '_.values' over the native function
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's disable the lint error with a comment

Copy link
Contributor

Choose a reason for hiding this comment

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

I think it would be better if we removed the ESLint config.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Or should i just use lodash here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated to use lodash

this.isWebOrDesktop = [CONST.PLATFORM.DESKTOP, CONST.PLATFORM.WEB].includes(getPlatform());

const allOptions = this.flattenSections();
Expand Down Expand Up @@ -155,7 +156,7 @@
this.focusedOption = this.state.allOptions[this.state.focusedIndex];
}

if (_.isEqual(this.props.sections, prevProps.sections)) {
if (lodashIsEqual(this.props.sections, prevProps.sections)) {
return;
}

Expand All @@ -171,14 +172,14 @@
}
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 = newOptions.find((option) => this.focusedOption && option.keyForList === this.focusedOption.keyForList);

Check failure on line 175 in src/components/OptionsSelector/BaseOptionsSelector.js

View workflow job for this annotation

GitHub Actions / Run ESLint

Prefer '_.find' over the native function
const prevFocusedOptionIndex = prevFocusedOption ? newOptions.findIndex((option) => this.focusedOption && option.keyForList === this.focusedOption.keyForList) : undefined;

Check failure on line 176 in src/components/OptionsSelector/BaseOptionsSelector.js

View workflow job for this annotation

GitHub Actions / Run ESLint

Prefer '_.findIndex' over the native function
// 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
Expand Down Expand Up @@ -230,11 +231,11 @@
} 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 = allOptions.findIndex((option) => option.keyForList === this.props.initiallyFocusedOptionKey);

Check failure on line 238 in src/components/OptionsSelector/BaseOptionsSelector.js

View workflow job for this annotation

GitHub Actions / Run ESLint

Prefer '_.findIndex' over the native function

return indexOfInitiallyFocusedOption;
}
Expand All @@ -245,8 +246,8 @@
* @returns {Objects[]}
*/
sliceSections() {
return _.map(this.props.sections, (section) => {
if (_.isEmpty(section.data)) {
return this.props.sections.map((section) => {

Check failure on line 249 in src/components/OptionsSelector/BaseOptionsSelector.js

View workflow job for this annotation

GitHub Actions / Run ESLint

Prefer '_.map' over the native function
if (section.data.length === 0) {
return section;
}

Expand All @@ -266,7 +267,7 @@
calculateAllVisibleOptionsCount() {
let count = 0;

_.forEach(this.state.sections, (section) => {
this.state.sections.forEach((section) => {
count += lodashGet(section, 'data.length', 0);
});

Expand Down Expand Up @@ -347,7 +348,7 @@

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 ? this.state.allOptions.find((option) => option.keyForList === focusedItemKey) : this.state.allOptions[this.state.focusedIndex];

Check failure on line 351 in src/components/OptionsSelector/BaseOptionsSelector.js

View workflow job for this annotation

GitHub Actions / Run ESLint

Prefer '_.find' over the native function

if (!focusedOption || !this.props.isFocused) {
return;
Expand Down Expand Up @@ -393,8 +394,8 @@
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,
Expand Down Expand Up @@ -496,8 +497,8 @@
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;
Copy link
Contributor

Choose a reason for hiding this comment

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

NAB, I think this.props.confirmButtonText === 'undefined' is enough.

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'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];
Expand Down
48 changes: 0 additions & 48 deletions src/components/Popover/popoverPropTypes.js

This file was deleted.

Loading
Loading