diff --git a/config/eslint/eslint.seatbelt.tsv b/config/eslint/eslint.seatbelt.tsv index 0f78ce026bcf..86e37f10d977 100644 --- a/config/eslint/eslint.seatbelt.tsv +++ b/config/eslint/eslint.seatbelt.tsv @@ -364,7 +364,6 @@ "../../src/components/Search/FilterComponents/AdvancedFilters/DateFilterContent.tsx" "no-restricted-imports" 1 "../../src/components/Search/FilterComponents/AdvancedFilters/ReportFieldFilterContent.tsx" "no-restricted-imports" 1 "../../src/components/Search/FilterComponents/AdvancedFilters/TextInputFilterContent.tsx" "no-restricted-imports" 1 -"../../src/components/Search/FilterComponents/CategorySelector.tsx" "rulesdir/no-useOnyx-dependencies-arg" 1 "../../src/components/Search/FilterComponents/DateFilterBase.tsx" "no-restricted-imports" 1 "../../src/components/Search/FilterComponents/DateFilterBase.tsx" "react-hooks/set-state-in-effect" 1 "../../src/components/Search/FilterComponents/DatePresetFilterBase.tsx" "@typescript-eslint/no-unsafe-type-assertion" 2 @@ -398,7 +397,6 @@ "../../src/components/Search/SearchList/ListItem/MemberListItemHeader.tsx" "@typescript-eslint/no-unsafe-type-assertion" 2 "../../src/components/Search/SearchList/ListItem/ReportListItemHeader.tsx" "@typescript-eslint/no-unsafe-type-assertion" 4 "../../src/components/Search/SearchList/ListItem/TaskListItem.tsx" "@typescript-eslint/no-unsafe-type-assertion" 1 -"../../src/components/Search/SearchList/ListItem/TaskListItem.tsx" "rulesdir/no-useOnyx-dependencies-arg" 1 "../../src/components/Search/SearchList/ListItem/TaskListItemRow.tsx" "no-restricted-imports" 1 "../../src/components/Search/SearchList/ListItem/TransactionGroupListExpanded.tsx" "@typescript-eslint/no-unsafe-type-assertion" 1 "../../src/components/Search/SearchList/ListItem/TransactionGroupListExpanded.tsx" "no-restricted-imports" 1 @@ -406,12 +404,10 @@ "../../src/components/Search/SearchList/ListItem/TransactionListItem/TransactionListItemNarrow.tsx" "@typescript-eslint/no-unsafe-type-assertion" 1 "../../src/components/Search/SearchList/ListItem/TransactionListItem/TransactionListItemWide.tsx" "@typescript-eslint/no-unsafe-type-assertion" 1 "../../src/components/Search/SearchList/ListItem/TransactionListItem/index.tsx" "@typescript-eslint/no-unsafe-type-assertion" 4 -"../../src/components/Search/SearchList/ListItem/TransactionListItem/index.tsx" "rulesdir/no-useOnyx-dependencies-arg" 1 "../../src/components/Search/SearchList/ListItem/WithdrawalIDListItemHeader.tsx" "@typescript-eslint/no-unsafe-type-assertion" 2 "../../src/components/Search/SearchMultipleSelectionPicker.tsx" "@typescript-eslint/no-unsafe-type-assertion" 1 "../../src/components/Search/SearchPageHeader/SearchActionsBarCreateButton.tsx" "@typescript-eslint/no-unsafe-type-assertion" 1 "../../src/components/Search/SearchPageHeader/SearchActionsBarCreateButton.tsx" "no-restricted-imports" 1 -"../../src/components/Search/SearchPageHeader/SearchActionsBarCreateButton.tsx" "rulesdir/no-useOnyx-dependencies-arg" 1 "../../src/components/Search/SearchPageHeader/SearchAdvancedFiltersButton.tsx" "no-restricted-imports" 1 "../../src/components/Search/SearchPageHeader/SearchFilterBar.tsx" "@typescript-eslint/no-unsafe-type-assertion" 3 "../../src/components/Search/SearchPageHeader/SearchSaveButton.tsx" "no-restricted-imports" 1 @@ -1188,7 +1184,6 @@ "../../src/pages/Search/SearchEditMultiple/SearchEditMultiplePage.tsx" "no-restricted-imports" 1 "../../src/pages/Search/SearchEditMultiple/SearchEditMultipleTagPage.tsx" "@typescript-eslint/no-unsafe-type-assertion" 1 "../../src/pages/Search/SearchEditMultiple/SearchEditMultipleUtils.ts" "@typescript-eslint/no-unsafe-type-assertion" 3 -"../../src/pages/Search/SearchHoldReasonPage.tsx" "rulesdir/no-useOnyx-dependencies-arg" 1 "../../src/pages/Search/SearchMoneyRequestReportPage.tsx" "@typescript-eslint/no-deprecated/deprecatedGetReportName" 1 "../../src/pages/Search/SearchMoneyRequestReportPage.tsx" "@typescript-eslint/no-unsafe-type-assertion" 2 "../../src/pages/Search/SearchPage.tsx" "react-hooks/set-state-in-effect" 1 diff --git a/src/components/Search/FilterComponents/CategorySelector.tsx b/src/components/Search/FilterComponents/CategorySelector.tsx index 766f71e544fa..87154b56fab0 100644 --- a/src/components/Search/FilterComponents/CategorySelector.tsx +++ b/src/components/Search/FilterComponents/CategorySelector.tsx @@ -32,24 +32,18 @@ function CategorySelector({value = [], policyID, selectionListTextInputStyle, se return {text: category, value: category}; }); - const availableNonPersonalPolicyCategoriesSelector = (policyCategories: OnyxCollection) => - Object.fromEntries( - Object.entries(policyCategories ?? {}).filter(([key, categories]) => { - if (key === `${ONYXKEYS.COLLECTION.POLICY_CATEGORIES}${personalPolicyID}`) { - return false; - } - const availableCategories = Object.values(categories ?? {}).filter((category) => category.pendingAction !== CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE); - return availableCategories.length > 0; - }), - ); - - const [allPolicyCategories = getEmptyObject>>()] = useOnyx( - ONYXKEYS.COLLECTION.POLICY_CATEGORIES, - { - selector: availableNonPersonalPolicyCategoriesSelector, - }, - [availableNonPersonalPolicyCategoriesSelector], - ); + const [allPolicyCategories = getEmptyObject>>()] = useOnyx(ONYXKEYS.COLLECTION.POLICY_CATEGORIES, { + selector: (policyCategories: OnyxCollection) => + Object.fromEntries( + Object.entries(policyCategories ?? {}).filter(([key, categories]) => { + if (key === `${ONYXKEYS.COLLECTION.POLICY_CATEGORIES}${personalPolicyID}`) { + return false; + } + const availableCategories = Object.values(categories ?? {}).filter((category) => category.pendingAction !== CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE); + return availableCategories.length > 0; + }), + ), + }); const categoryItems = [{text: translate('search.noCategory'), value: CONST.SEARCH.CATEGORY_EMPTY_VALUE as string}]; const uniqueCategoryNames = new Set( diff --git a/src/components/Search/SearchList/ListItem/ExpenseReportListItem.tsx b/src/components/Search/SearchList/ListItem/ExpenseReportListItem.tsx index aac06010f341..92db0bf84ac7 100644 --- a/src/components/Search/SearchList/ListItem/ExpenseReportListItem.tsx +++ b/src/components/Search/SearchList/ListItem/ExpenseReportListItem.tsx @@ -123,7 +123,7 @@ function ExpenseReportListItemInner({ const [parentPolicy] = originalUseOnyx(`${ONYXKEYS.COLLECTION.POLICY}${getNonEmptyStringOnyxID(reportItem.policyID)}`); const [parentReport] = originalUseOnyx(`${ONYXKEYS.COLLECTION.REPORT}${getNonEmptyStringOnyxID(reportItem.reportID)}`); const [policyCategories] = originalUseOnyx(`${ONYXKEYS.COLLECTION.POLICY_CATEGORIES}${getNonEmptyStringOnyxID(reportItem.policyID)}`); - const [submitterLogin] = originalUseOnyx(ONYXKEYS.PERSONAL_DETAILS_LIST, {selector: personalDetailsLoginSelector(reportItem.ownerAccountID)}, [reportItem.ownerAccountID]); + const [submitterLogin] = originalUseOnyx(ONYXKEYS.PERSONAL_DETAILS_LIST, {selector: personalDetailsLoginSelector(reportItem.ownerAccountID)}); const shouldUseMarkAsDoneCopy = shouldShowMarkAsDone({ policy: parentPolicy, @@ -237,8 +237,7 @@ function ExpenseReportListItemInner({ // hydrate into the live collection, rule/category changes still push violation updates that must // reflect on the badge (per-row selector, not the screen-level collection merge this slice removed). const snapshotTransactionIDs = (reportItem.transactions ?? []).map((transaction) => transaction.transactionID); - const liveViolationsSelector = transactionViolationsByIDsSelector(snapshotTransactionIDs); - const [liveViolationsForSnapshotTransactions] = originalUseOnyx(ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS, {selector: liveViolationsSelector}, [liveViolationsSelector]); + const [liveViolationsForSnapshotTransactions] = originalUseOnyx(ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS, {selector: transactionViolationsByIDsSelector(snapshotTransactionIDs)}); const {currentUserAccountID, currentUserLogin, introSelected, betas, isSelfTourViewed, activePolicy, nextStep, chatReportPolicy, amountOwed, delegateEmail, delegateAccountID} = useReportPaymentContext({ reportID: reportItem.reportID, diff --git a/src/components/Search/SearchList/ListItem/GroupHeader.tsx b/src/components/Search/SearchList/ListItem/GroupHeader.tsx index 5e96d432467e..b2d4635acbae 100644 --- a/src/components/Search/SearchList/ListItem/GroupHeader.tsx +++ b/src/components/Search/SearchList/ListItem/GroupHeader.tsx @@ -113,8 +113,9 @@ function GroupHeader({ const [parentReport] = originalUseOnyx(`${ONYXKEYS.COLLECTION.REPORT}${oneTransactionReportID}`); const [oneTransactionThreadReport] = originalUseOnyx(`${ONYXKEYS.COLLECTION.REPORT}${oneTransactionChildReportID}`); const [oneTransaction] = originalUseOnyx(`${ONYXKEYS.COLLECTION.TRANSACTION}${oneTransactionID}`); - const parentReportActionSelector = (reportActions: OnyxEntry): OnyxEntry => reportActions?.[`${oneTransactionItem?.reportAction?.reportActionID}`]; - const [parentReportAction] = originalUseOnyx(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${oneTransactionReportID}`, {selector: parentReportActionSelector}, [oneTransactionItem]); + const [parentReportAction] = originalUseOnyx(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${oneTransactionReportID}`, { + selector: (reportActions: OnyxEntry): OnyxEntry => reportActions?.[`${oneTransactionItem?.reportAction?.reportActionID}`], + }); const transactionPreviewData: TransactionPreviewData = useMemo( () => ({ hasParentReport: !!parentReport, diff --git a/src/components/Search/SearchList/ListItem/ReportListItemHeader.tsx b/src/components/Search/SearchList/ListItem/ReportListItemHeader.tsx index 19c4a6f83259..86d2419a6baf 100644 --- a/src/components/Search/SearchList/ListItem/ReportListItemHeader.tsx +++ b/src/components/Search/SearchList/ListItem/ReportListItemHeader.tsx @@ -273,7 +273,7 @@ function ReportListItemHeaderInner({ return chatReportID ? snapshot?.data?.[`${ONYXKEYS.COLLECTION.REPORT}${chatReportID}`] : undefined; }, [snapshot, snapshotReport?.chatReportID, reportItem.parentReportID]); const [parentPolicy] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY}${getNonEmptyStringOnyxID(snapshotReport?.policyID ?? reportItem.policyID)}`); - const [submitterLogin] = originalUseOnyx(ONYXKEYS.PERSONAL_DETAILS_LIST, {selector: personalDetailsLoginSelector(reportItem.ownerAccountID)}, [reportItem.ownerAccountID]); + const [submitterLogin] = originalUseOnyx(ONYXKEYS.PERSONAL_DETAILS_LIST, {selector: personalDetailsLoginSelector(reportItem.ownerAccountID)}); const [parentChatReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${getNonEmptyStringOnyxID(snapshotReport?.chatReportID ?? reportItem.parentReportID)}`); const chatReport = parentChatReport ?? snapshotChatReport; const [chatReportActions] = useOnyx( diff --git a/src/components/Search/SearchList/ListItem/TaskListItem.tsx b/src/components/Search/SearchList/ListItem/TaskListItem.tsx index 3edf00aa8268..03d4d09aa549 100644 --- a/src/components/Search/SearchList/ListItem/TaskListItem.tsx +++ b/src/components/Search/SearchList/ListItem/TaskListItem.tsx @@ -44,8 +44,9 @@ function TaskListItem({ const taskItem = item as unknown as TaskListItemType; const parentReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${taskItem?.parentReportID}`]; const parentReportID = taskItem?.parentReportID; - const parentReportAttributeNameSelector = (value: OnyxEntry) => (parentReportID ? value?.reports?.[parentReportID]?.reportName : undefined); - const [liveParentReportAttributeName] = useOnyx(ONYXKEYS.DERIVED.REPORT_ATTRIBUTES, {selector: parentReportAttributeNameSelector}, [parentReportID]); + const [liveParentReportAttributeName] = useOnyx(ONYXKEYS.DERIVED.REPORT_ATTRIBUTES, { + selector: (value: OnyxEntry) => (parentReportID ? value?.reports?.[parentReportID]?.reportName : undefined), + }); const liveTaskItem: TaskListItemType = liveParentReportAttributeName && liveParentReportAttributeName !== taskItem.parentReportName ? {...taskItem, parentReportName: liveParentReportAttributeName} : taskItem; const styles = useThemeStyles(); diff --git a/src/components/Search/SearchList/ListItem/TransactionGroupListItem.tsx b/src/components/Search/SearchList/ListItem/TransactionGroupListItem.tsx index 7d0306f6ed3e..986b49424317 100644 --- a/src/components/Search/SearchList/ListItem/TransactionGroupListItem.tsx +++ b/src/components/Search/SearchList/ListItem/TransactionGroupListItem.tsx @@ -119,10 +119,9 @@ function TransactionGroupListItemImpl({ const [parentReport] = originalUseOnyx(`${ONYXKEYS.COLLECTION.REPORT}${getNonEmptyStringOnyxID(oneTransactionItem?.reportID)}`); const [oneTransactionThreadReport] = originalUseOnyx(`${ONYXKEYS.COLLECTION.REPORT}${oneTransactionItem?.reportAction?.childReportID}`); const [oneTransaction] = originalUseOnyx(`${ONYXKEYS.COLLECTION.TRANSACTION}${getNonEmptyStringOnyxID(oneTransactionItem?.transactionID)}`); - const parentReportActionSelector = (reportActions: OnyxEntry): OnyxEntry => reportActions?.[`${oneTransactionItem?.reportAction?.reportActionID}`]; - const [parentReportAction] = originalUseOnyx(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${getNonEmptyStringOnyxID(oneTransactionItem?.reportID)}`, {selector: parentReportActionSelector}, [ - oneTransactionItem, - ]); + const [parentReportAction] = originalUseOnyx(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${getNonEmptyStringOnyxID(oneTransactionItem?.reportID)}`, { + selector: (reportActions: OnyxEntry): OnyxEntry => reportActions?.[`${oneTransactionItem?.reportAction?.reportActionID}`], + }); const transactionPreviewData: TransactionPreviewData = { hasParentReport: !!parentReport, hasTransaction: !!oneTransaction, diff --git a/src/components/Search/SearchList/ListItem/TransactionListItem/index.tsx b/src/components/Search/SearchList/ListItem/TransactionListItem/index.tsx index ed120c401a42..cb2578f1de73 100644 --- a/src/components/Search/SearchList/ListItem/TransactionListItem/index.tsx +++ b/src/components/Search/SearchList/ListItem/TransactionListItem/index.tsx @@ -129,15 +129,13 @@ function TransactionListItemInner({ const [parentReport] = originalUseOnyx(`${ONYXKEYS.COLLECTION.REPORT}${getNonEmptyStringOnyxID(transactionItem.reportID)}`); const [transactionThreadReport] = originalUseOnyx(`${ONYXKEYS.COLLECTION.REPORT}${transactionItem?.reportAction?.childReportID}`); - const [submitterLogin] = useOnyx(ONYXKEYS.PERSONAL_DETAILS_LIST, {selector: personalDetailsLoginSelector(transactionItem?.report?.ownerAccountID)}, [ - transactionItem?.report?.ownerAccountID, - ]); + const [submitterLogin] = useOnyx(ONYXKEYS.PERSONAL_DETAILS_LIST, {selector: personalDetailsLoginSelector(transactionItem?.report?.ownerAccountID)}); const [transaction] = originalUseOnyx(`${ONYXKEYS.COLLECTION.TRANSACTION}${getNonEmptyStringOnyxID(transactionItem.transactionID)}`); const [transactionViolationsForRow] = originalUseOnyx(`${ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS}${getNonEmptyStringOnyxID(transactionItem.transactionID)}`); - const parentReportActionSelector = (reportActions: OnyxEntry): OnyxEntry => reportActions?.[`${transactionItem?.reportAction?.reportActionID}`]; - const [parentReportAction] = originalUseOnyx(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${getNonEmptyStringOnyxID(transactionItem.reportID)}`, {selector: parentReportActionSelector}, [ - transactionItem, - ]); + const parentReportActionID = transactionItem?.reportAction?.reportActionID; + const [parentReportAction] = originalUseOnyx(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${getNonEmptyStringOnyxID(transactionItem.reportID)}`, { + selector: (reportActions: OnyxEntry): OnyxEntry => reportActions?.[`${parentReportActionID}`], + }); const currentUserDetails = useCurrentUserPersonalDetails(); const [parentChatReport] = originalUseOnyx(`${ONYXKEYS.COLLECTION.REPORT}${getNonEmptyStringOnyxID(snapshotReport?.chatReportID)}`); const [chatReportActions] = originalUseOnyx(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${getNonEmptyStringOnyxID(snapshotReport?.chatReportID ?? snapshotReport?.parentReportID)}`); diff --git a/src/components/Search/SearchPageHeader/SearchActionsBarCreateButton.tsx b/src/components/Search/SearchPageHeader/SearchActionsBarCreateButton.tsx index af7d8f92238f..71124c5cff09 100644 --- a/src/components/Search/SearchPageHeader/SearchActionsBarCreateButton.tsx +++ b/src/components/Search/SearchPageHeader/SearchActionsBarCreateButton.tsx @@ -55,8 +55,9 @@ function SearchActionsBarCreateButton() { const {isBetaEnabled} = usePermissions(); const isASAPSubmitBetaEnabled = isBetaEnabled(CONST.BETAS.ASAP_SUBMIT); const isSubmit2026BetaEnabled = isBetaEnabled(CONST.BETAS.SUBMIT_2026); - const groupPoliciesWithChatEnabledSelector = (policies: OnyxCollection) => getGroupPoliciesWhereReportCanBeCreated(policies, isSubmit2026BetaEnabled, email); - const [groupPoliciesWithChatEnabled = CONST.EMPTY_ARRAY] = useOnyx(ONYXKEYS.COLLECTION.POLICY, {selector: groupPoliciesWithChatEnabledSelector}, [email, isSubmit2026BetaEnabled]); + const [groupPoliciesWithChatEnabled = CONST.EMPTY_ARRAY] = useOnyx(ONYXKEYS.COLLECTION.POLICY, { + selector: (policies: OnyxCollection) => getGroupPoliciesWhereReportCanBeCreated(policies, isSubmit2026BetaEnabled, email), + }); const currentUserPersonalDetails = useCurrentUserPersonalDetails(); const hasViolations = hasViolationsReportUtils(undefined, transactionViolations, session?.accountID ?? CONST.DEFAULT_NUMBER_ID, session?.email ?? ''); const [activePolicyID] = useOnyx(ONYXKEYS.NVP_ACTIVE_POLICY_ID); diff --git a/src/pages/Search/SearchHoldReasonPage.tsx b/src/pages/Search/SearchHoldReasonPage.tsx index 4a3949405a99..95fd80d2fbe1 100644 --- a/src/pages/Search/SearchHoldReasonPage.tsx +++ b/src/pages/Search/SearchHoldReasonPage.tsx @@ -42,8 +42,7 @@ function SearchHoldReasonPage({route}: SearchHoldReasonPageProps) { () => (route.name === SCREENS.SEARCH.MONEY_REQUEST_REPORT_HOLD_TRANSACTIONS ? selectedTransactionIDs : Object.keys(selectedTransactions)), [route.name, selectedTransactionIDs, selectedTransactions], ); - const violationsSelector = useMemo(() => transactionViolationsByIDsSelector(relevantTransactionIDs), [relevantTransactionIDs]); - const [selectedTransactionViolations] = useOnyx(ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS, {selector: violationsSelector}, [violationsSelector]); + const [selectedTransactionViolations] = useOnyx(ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS, {selector: transactionViolationsByIDsSelector(relevantTransactionIDs)}); const {isOffline} = useNetwork(); const [isTrackIntentUser] = useOnyx(ONYXKEYS.NVP_INTRO_SELECTED, {selector: isTrackIntentUserSelector});