From 88e620a8259dca40275363ecfdb6f96784850aa3 Mon Sep 17 00:00:00 2001 From: Tim Golen Date: Wed, 7 Dec 2022 14:41:13 -0700 Subject: [PATCH 1/4] Refactor the function for filtering the currency list --- src/libs/OptionsListUtils.js | 18 ------------------ src/pages/iou/IOUCurrencySelection.js | 19 +++++++++++-------- 2 files changed, 11 insertions(+), 26 deletions(-) diff --git a/src/libs/OptionsListUtils.js b/src/libs/OptionsListUtils.js index 0942d799eda7..c86603139a6e 100644 --- a/src/libs/OptionsListUtils.js +++ b/src/libs/OptionsListUtils.js @@ -778,23 +778,6 @@ function getHeaderMessage(hasSelectableOptions, hasUserToInvite, searchValue, ma return ''; } -/** - * Returns the currency list for sections display - * - * @param {Object} currencyOptions - * @param {String} searchValue - * @returns {Array} - */ -function getCurrencyListForSections(currencyOptions, searchValue) { - const filteredOptions = _.filter(currencyOptions, currencyOption => ( - isSearchStringMatch(searchValue, currencyOption.text))); - - return { - // returns filtered options i.e. options with string match if search text is entered - currencyOptions: filteredOptions, - }; -} - export { addSMSDomainIfPhoneNumber, isCurrentUser, @@ -803,7 +786,6 @@ export { getMemberInviteOptions, getHeaderMessage, getPersonalDetailsForLogins, - getCurrencyListForSections, getIOUConfirmationOptionsFromMyPersonalDetail, getIOUConfirmationOptionsFromParticipants, getSearchText, diff --git a/src/pages/iou/IOUCurrencySelection.js b/src/pages/iou/IOUCurrencySelection.js index 2621b19ce81f..1d0b2493add3 100644 --- a/src/pages/iou/IOUCurrencySelection.js +++ b/src/pages/iou/IOUCurrencySelection.js @@ -41,11 +41,9 @@ class IOUCurrencySelection extends Component { constructor(props) { super(props); - const {currencyOptions} = OptionsListUtils.getCurrencyListForSections(this.getCurrencyOptions(this.props.currencyList), ''); - this.state = { searchValue: '', - currencyData: currencyOptions, + currencyData: this.filterCurrencyList(), }; this.getCurrencyOptions = this.getCurrencyOptions.bind(this); this.getSections = this.getSections.bind(this); @@ -90,16 +88,21 @@ class IOUCurrencySelection extends Component { * @return {void} */ changeSearchValue(searchValue) { - const {currencyOptions} = OptionsListUtils.getCurrencyListForSections( - this.getCurrencyOptions(this.props.currencyList), - searchValue, - ); this.setState({ searchValue, - currencyData: currencyOptions, + currencyData: this.filterCurrencyList(searchValue), }); } + filterCurrencyList(searchValue = '') { + const currencyOptions = this.getCurrencyOptions(this.props.currencyList); + if (!searchValue) { + return currencyOptions; + } + const searchRegex = new RegExp(searchValue, 'i'); + return _.filter(currencyOptions, currencyOption => searchRegex.test(currencyOption.text)); + } + /** * Confirms the selection of currency and sets values in Onyx * From 646bb44fcc029930a6ac80c5e6bf8d7d8384f4dc Mon Sep 17 00:00:00 2001 From: Tim Golen Date: Wed, 7 Dec 2022 14:53:56 -0700 Subject: [PATCH 2/4] Rename method --- src/pages/iou/IOUCurrencySelection.js | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/pages/iou/IOUCurrencySelection.js b/src/pages/iou/IOUCurrencySelection.js index 1d0b2493add3..f2f2d7ac389e 100644 --- a/src/pages/iou/IOUCurrencySelection.js +++ b/src/pages/iou/IOUCurrencySelection.js @@ -43,7 +43,7 @@ class IOUCurrencySelection extends Component { this.state = { searchValue: '', - currencyData: this.filterCurrencyList(), + currencyData: this.getFilteredCurrencyList(), }; this.getCurrencyOptions = this.getCurrencyOptions.bind(this); this.getSections = this.getSections.bind(this); @@ -82,6 +82,15 @@ class IOUCurrencySelection extends Component { })); } + getFilteredCurrencyList(searchValue = '') { + const currencyOptions = this.getCurrencyOptions(this.props.currencyList); + if (!searchValue) { + return currencyOptions; + } + const searchRegex = new RegExp(searchValue, 'i'); + return _.filter(currencyOptions, currencyOption => searchRegex.test(currencyOption.text)); + } + /** * Sets new search value * @param {String} searchValue @@ -90,19 +99,10 @@ class IOUCurrencySelection extends Component { changeSearchValue(searchValue) { this.setState({ searchValue, - currencyData: this.filterCurrencyList(searchValue), + currencyData: this.getFilteredCurrencyList(searchValue), }); } - filterCurrencyList(searchValue = '') { - const currencyOptions = this.getCurrencyOptions(this.props.currencyList); - if (!searchValue) { - return currencyOptions; - } - const searchRegex = new RegExp(searchValue, 'i'); - return _.filter(currencyOptions, currencyOption => searchRegex.test(currencyOption.text)); - } - /** * Confirms the selection of currency and sets values in Onyx * From 59fe70d16d55efcfd032328db99231381a536093 Mon Sep 17 00:00:00 2001 From: Tim Golen Date: Wed, 7 Dec 2022 15:07:46 -0700 Subject: [PATCH 3/4] Remove unnecessary method --- src/pages/iou/IOUCurrencySelection.js | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/src/pages/iou/IOUCurrencySelection.js b/src/pages/iou/IOUCurrencySelection.js index f2f2d7ac389e..2886278b81b9 100644 --- a/src/pages/iou/IOUCurrencySelection.js +++ b/src/pages/iou/IOUCurrencySelection.js @@ -43,7 +43,7 @@ class IOUCurrencySelection extends Component { this.state = { searchValue: '', - currencyData: this.getFilteredCurrencyList(), + currencyData: this.getCurrencyOptions(this.props.currencyList), }; this.getCurrencyOptions = this.getCurrencyOptions.bind(this); this.getSections = this.getSections.bind(this); @@ -82,24 +82,19 @@ class IOUCurrencySelection extends Component { })); } - getFilteredCurrencyList(searchValue = '') { - const currencyOptions = this.getCurrencyOptions(this.props.currencyList); - if (!searchValue) { - return currencyOptions; - } - const searchRegex = new RegExp(searchValue, 'i'); - return _.filter(currencyOptions, currencyOption => searchRegex.test(currencyOption.text)); - } - /** * Sets new search value * @param {String} searchValue * @return {void} */ changeSearchValue(searchValue) { + const currencyOptions = this.getCurrencyOptions(this.props.currencyList); + const searchRegex = new RegExp(searchValue, 'i'); + const filteredCurrencies = _.filter(currencyOptions, currencyOption => searchRegex.test(currencyOption.text)); + this.setState({ searchValue, - currencyData: this.getFilteredCurrencyList(searchValue), + currencyData: filteredCurrencies, }); } From a4831ba9765d5e14ed198257ad9d4e345c491316 Mon Sep 17 00:00:00 2001 From: Tim Golen Date: Wed, 7 Dec 2022 15:13:19 -0700 Subject: [PATCH 4/4] Remove unused import --- src/pages/iou/IOUCurrencySelection.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/pages/iou/IOUCurrencySelection.js b/src/pages/iou/IOUCurrencySelection.js index 2886278b81b9..b7affe898beb 100644 --- a/src/pages/iou/IOUCurrencySelection.js +++ b/src/pages/iou/IOUCurrencySelection.js @@ -3,7 +3,6 @@ import PropTypes from 'prop-types'; import {withOnyx} from 'react-native-onyx'; import _ from 'underscore'; import ONYXKEYS from '../../ONYXKEYS'; -import * as OptionsListUtils from '../../libs/OptionsListUtils'; import OptionsSelector from '../../components/OptionsSelector'; import Navigation from '../../libs/Navigation/Navigation'; import ScreenWrapper from '../../components/ScreenWrapper';