From 3bc8d30190fa818e16c4c8c6a2e57cbf507470b2 Mon Sep 17 00:00:00 2001 From: Mykhailo Kravchenko Date: Fri, 15 Sep 2023 14:00:02 +0200 Subject: [PATCH 1/4] fix focus on different scenarios --- src/components/CategoryPicker/index.js | 26 ++++++++++--------- .../OptionsSelector/BaseOptionsSelector.js | 4 +-- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/src/components/CategoryPicker/index.js b/src/components/CategoryPicker/index.js index 91c7e82e7887..4ee429a2e389 100644 --- a/src/components/CategoryPicker/index.js +++ b/src/components/CategoryPicker/index.js @@ -34,21 +34,23 @@ function CategoryPicker({policyCategories, reportID, iouType, iou, policyRecentl ]; }, [iou.category]); + const sections = useMemo(() => { + const {categoryOptions} = OptionsListUtils.getNewChatOptions({}, {}, [], searchValue, selectedOptions, [], false, false, true, policyCategories, policyRecentlyUsedCategories, false); + + return categoryOptions; + }, [policyCategories, policyRecentlyUsedCategories, searchValue, selectedOptions]); + const initialFocusedIndex = useMemo(() => { - if (isCategoriesCountBelowThreshold && selectedOptions.length > 0) { - return _.chain(policyCategories) - .values() - .findIndex((category) => category.name === selectedOptions[0].name, true) - .value(); - } + let categoryInitialFocusedIndex = 0; - return 0; - }, [policyCategories, selectedOptions, isCategoriesCountBelowThreshold]); + if (!_.isEmpty(searchValue) || isCategoriesCountBelowThreshold) { + const index = _.findIndex(lodashGet(sections, '[0].data', []), (category) => category.searchText === iou.category); - const sections = useMemo( - () => OptionsListUtils.getNewChatOptions({}, {}, [], searchValue, selectedOptions, [], false, false, true, policyCategories, policyRecentlyUsedCategories, false).categoryOptions, - [policyCategories, policyRecentlyUsedCategories, searchValue, selectedOptions], - ); + categoryInitialFocusedIndex = index === -1 ? 0 : index; + } + + return categoryInitialFocusedIndex; + }, [iou.category, searchValue, isCategoriesCountBelowThreshold, sections]); const headerMessage = OptionsListUtils.getHeaderMessage(lodashGet(sections, '[0].data.length', 0) > 0, false, searchValue); const shouldShowTextInput = !isCategoriesCountBelowThreshold; diff --git a/src/components/OptionsSelector/BaseOptionsSelector.js b/src/components/OptionsSelector/BaseOptionsSelector.js index bff9f8b6d7d0..aa02701b1c98 100755 --- a/src/components/OptionsSelector/BaseOptionsSelector.js +++ b/src/components/OptionsSelector/BaseOptionsSelector.js @@ -107,13 +107,13 @@ class BaseOptionsSelector extends Component { }); return; } - const newFocusedIndex = this.props.selectedOptions.length; + const newFocusedIndex = this.props.selectedOptions.length; // eslint-disable-next-line react/no-did-update-set-state this.setState( { allOptions: newOptions, - focusedIndex: newFocusedIndex, + focusedIndex: _.isNumber(this.props.initialFocusedIndex) ? this.props.initialFocusedIndex : newFocusedIndex, }, () => { // If we just toggled an option on a multi-selection page or cleared the search input, scroll to top From 14d9d155bbdd3b66780349f9e55a18ac5639f533 Mon Sep 17 00:00:00 2001 From: Blazej Kustra Date: Mon, 18 Sep 2023 14:57:19 +0200 Subject: [PATCH 2/4] [TS migration] Migrate 'AddEncryptedAuthToken.js' lib to TypeScript --- src/libs/migrateOnyx.js | 2 - src/libs/migrations/AddEncryptedAuthToken.js | 42 -------------------- 2 files changed, 44 deletions(-) delete mode 100644 src/libs/migrations/AddEncryptedAuthToken.js diff --git a/src/libs/migrateOnyx.js b/src/libs/migrateOnyx.js index 9389a9b66fbc..0bc2f1d3c04b 100644 --- a/src/libs/migrateOnyx.js +++ b/src/libs/migrateOnyx.js @@ -1,6 +1,5 @@ import _ from 'underscore'; import Log from './Log'; -import AddEncryptedAuthToken from './migrations/AddEncryptedAuthToken'; import RenameActiveClientsKey from './migrations/RenameActiveClientsKey'; import RenamePriorityModeKey from './migrations/RenamePriorityModeKey'; import MoveToIndexedDB from './migrations/MoveToIndexedDB'; @@ -19,7 +18,6 @@ export default function () { MoveToIndexedDB, RenameActiveClientsKey, RenamePriorityModeKey, - AddEncryptedAuthToken, RenameExpensifyNewsStatus, AddLastVisibleActionCreated, KeyReportActionsByReportActionID, diff --git a/src/libs/migrations/AddEncryptedAuthToken.js b/src/libs/migrations/AddEncryptedAuthToken.js deleted file mode 100644 index 1c8d6a1e2a43..000000000000 --- a/src/libs/migrations/AddEncryptedAuthToken.js +++ /dev/null @@ -1,42 +0,0 @@ -/* eslint-disable rulesdir/no-api-in-views */ -import _ from 'underscore'; -import Onyx from 'react-native-onyx'; -import Log from '../Log'; -import ONYXKEYS from '../../ONYXKEYS'; -import * as Authentication from '../Authentication'; - -/** - * This migration adds an encryptedAuthToken to the SESSION key, if it is not present. - * - * @returns {Promise} - */ -export default function () { - return new Promise((resolve) => { - const connectionID = Onyx.connect({ - key: ONYXKEYS.SESSION, - callback: (session) => { - Onyx.disconnect(connectionID); - - if (session && !_.isEmpty(session.encryptedAuthToken)) { - Log.info('[Migrate Onyx] Skipped migration AddEncryptedAuthToken'); - return resolve(); - } - - if (!session || !session.authToken) { - Log.info('[Migrate Onyx] Skipped migration AddEncryptedAuthToken'); - return resolve(); - } - - // If there is an auth token but no encrypted auth token, reauthenticate. - if (session.authToken && _.isUndefined(session.encryptedAuthToken)) { - return Authentication.reauthenticate('Onyx_Migration_AddEncryptedAuthToken').then(() => { - Log.info('[Migrate Onyx] Ran migration AddEncryptedAuthToken'); - return resolve(); - }); - } - - return resolve(); - }, - }); - }); -} From 7ec19d27c51463db6dfc3387bb5c7a49f774a33f Mon Sep 17 00:00:00 2001 From: Hans Date: Tue, 19 Sep 2023 11:36:07 +0700 Subject: [PATCH 3/4] fix bottom not transparent --- src/components/IllustratedHeaderPageLayout.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/IllustratedHeaderPageLayout.js b/src/components/IllustratedHeaderPageLayout.js index 92a9c8b8552b..edf3c118f984 100644 --- a/src/components/IllustratedHeaderPageLayout.js +++ b/src/components/IllustratedHeaderPageLayout.js @@ -59,7 +59,7 @@ function IllustratedHeaderPageLayout({backgroundColor, children, illustration, f titleColor={backgroundColor === themeColors.appBG ? undefined : themeColors.textColorfulBackground} iconFill={backgroundColor === themeColors.appBG ? undefined : themeColors.iconColorfulBackground} /> - + {/* Safari on ios/mac has a bug where overscrolling the page scrollview shows green the background color. This is a workaround to fix that. https://github.com/Expensify/App/issues/23422 */} {Browser.isSafari() && ( From 7bdb3755f438c74538823e2fdc84268859b578d2 Mon Sep 17 00:00:00 2001 From: Blazej Kustra Date: Wed, 20 Sep 2023 15:55:58 +0200 Subject: [PATCH 4/4] Fix prettier --- src/libs/migrateOnyx.js | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/src/libs/migrateOnyx.js b/src/libs/migrateOnyx.js index a74c2a237e53..7394de694de1 100644 --- a/src/libs/migrateOnyx.js +++ b/src/libs/migrateOnyx.js @@ -13,14 +13,7 @@ export default function () { return new Promise((resolve) => { // Add all migrations to an array so they are executed in order - const migrationPromises = [ - MoveToIndexedDB, - RenameActiveClientsKey, - RenamePriorityModeKey, - RenameExpensifyNewsStatus, - AddLastVisibleActionCreated, - PersonalDetailsByAccountID, - ]; + const migrationPromises = [MoveToIndexedDB, RenameActiveClientsKey, RenamePriorityModeKey, RenameExpensifyNewsStatus, AddLastVisibleActionCreated, PersonalDetailsByAccountID]; // Reduce all promises down to a single promise. All promises run in a linear fashion, waiting for the // previous promise to finish before moving onto the next one.