-
Notifications
You must be signed in to change notification settings - Fork 3.5k
81443: Reduce cont of Eslint issues from 399 to 378 #81588
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| import {useCallback} from 'react'; | ||
| import {useCallback, useMemo} from 'react'; | ||
| import type {OnyxCollection} from 'react-native-onyx'; | ||
| import {extractCollectionItemID} from '@libs/CollectionUtils'; | ||
| import {getReportTransactions, isChatRoom, isPolicyExpenseChat, isPolicyRelatedReport, isTaskReport} from '@libs/ReportUtils'; | ||
|
|
@@ -9,19 +9,26 @@ import useOnyx from './useOnyx'; | |
|
|
||
| function useTransactionViolationOfWorkspace(policyID?: string) { | ||
| const [allReports] = useOnyx(ONYXKEYS.COLLECTION.REPORT, {canBeMissing: true}); | ||
| const reportsToArchive = Object.values(allReports ?? {}).filter( | ||
| (report): report is Report => report != null && isPolicyRelatedReport(report, policyID) && (isChatRoom(report) || isPolicyExpenseChat(report) || isTaskReport(report)), | ||
| const reportsToArchive = useMemo( | ||
| () => | ||
| Object.values(allReports ?? {}).filter( | ||
| (report): report is Report => report != null && isPolicyRelatedReport(report, policyID) && (isChatRoom(report) || isPolicyExpenseChat(report) || isTaskReport(report)), | ||
| ), | ||
| [allReports, policyID], | ||
| ); | ||
| const transactionIDSet = new Set<string>(); | ||
| for (const report of reportsToArchive) { | ||
| if (!report?.iouReportID) { | ||
| continue; | ||
| } | ||
| const reportTransactions = getReportTransactions(report.iouReportID); | ||
| for (const transaction of reportTransactions) { | ||
| transactionIDSet.add(transaction.transactionID); | ||
| const transactionIDSet = useMemo(() => { | ||
| const set = new Set<string>(); | ||
| for (const report of reportsToArchive) { | ||
| if (!report?.iouReportID) { | ||
| continue; | ||
| } | ||
| const reportTransactions = getReportTransactions(report.iouReportID); | ||
| for (const transaction of reportTransactions) { | ||
| set.add(transaction.transactionID); | ||
| } | ||
| } | ||
| } | ||
| return set; | ||
| }, [reportsToArchive]); | ||
|
Comment on lines
+19
to
+31
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.
Because Useful? React with 👍 / 👎. |
||
|
|
||
| const transactionViolationSelector = useCallback( | ||
| (violations: OnyxCollection<TransactionViolations>) => { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| import React, {useCallback, useEffect, useMemo, useState} from 'react'; | ||
| import React, {useCallback, useMemo, useState} from 'react'; | ||
| import {View} from 'react-native'; | ||
| import type {StyleProp, ViewStyle} from 'react-native'; | ||
| import FormHelpMessage from '@components/FormHelpMessage'; | ||
|
|
@@ -83,7 +83,8 @@ function CardTypeStep() { | |
| const styles = useThemeStyles(); | ||
| const companyCardBankIcons = useCompanyCardBankIcons(); | ||
| const [addNewCard] = useOnyx(ONYXKEYS.ADD_NEW_COMPANY_CARD, {canBeMissing: true}); | ||
| const [typeSelected, setTypeSelected] = useState<CardFeedProvider>(); | ||
| const [localTypeSelected, setLocalTypeSelected] = useState<CardFeedProvider>(); | ||
|
Contributor
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. ❌ [PERF-6] (docs)The removed Suggested fix: Replace the local state pattern with true state derivation: const [localTypeSelected, setLocalTypeSelected] = useState<CardFeedProvider>();
const typeSelected = localTypeSelected ?? addNewCard?.data.feedType;This ensures Please rate this suggestion with 👍 or 👎 to help us improve! Reactions are used to monitor reviewer efficiency. |
||
| const typeSelected = localTypeSelected ?? addNewCard?.data.feedType; | ||
| const [isError, setIsError] = useState(false); | ||
| const data = getAvailableCompanyCardTypes({ | ||
| translate, | ||
|
|
@@ -111,10 +112,6 @@ function CardTypeStep() { | |
| } | ||
| }, [bankName, isNewCardTypeSelected, isOtherBankSelected, typeSelected]); | ||
|
|
||
| useEffect(() => { | ||
| setTypeSelected(addNewCard?.data.feedType); | ||
| }, [addNewCard?.data.feedType]); | ||
|
|
||
| const handleBackButtonPress = () => { | ||
| if (isOtherBankSelected) { | ||
| setAddNewCompanyCardStepAndData({step: CONST.COMPANY_CARDS.STEP.SELECT_BANK}); | ||
|
|
@@ -153,7 +150,7 @@ function CardTypeStep() { | |
| data={data} | ||
| ListItem={RadioListItem} | ||
| onSelectRow={({value}) => { | ||
| setTypeSelected(value); | ||
| setLocalTypeSelected(value); | ||
| setIsError(false); | ||
| }} | ||
| confirmButtonOptions={confirmButtonOptions} | ||
|
|
||
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.
❌ [PERF-5] (docs)
Including the entire
reportobject in the dependency array causes unnecessary re-renders when any property ofreportchanges. The grouping functions only usereport.currency, not the entire report object.Suggested fix: Use specific field comparison instead of the entire object:
This ensures the memoization only breaks when the actually-used properties change.
Please rate this suggestion with 👍 or 👎 to help us improve! Reactions are used to monitor reviewer efficiency.