Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
901 changes: 228 additions & 673 deletions .github/actions/javascript/authorChecklist/index.js

Large diffs are not rendered by default.

901 changes: 228 additions & 673 deletions .github/actions/javascript/awaitStagingDeploys/index.js

Large diffs are not rendered by default.

901 changes: 228 additions & 673 deletions .github/actions/javascript/bumpVersion/index.js

Large diffs are not rendered by default.

903 changes: 229 additions & 674 deletions .github/actions/javascript/checkAndroidStatus/index.js

Large diffs are not rendered by default.

901 changes: 228 additions & 673 deletions .github/actions/javascript/checkDeployBlockers/index.js

Large diffs are not rendered by default.

901 changes: 228 additions & 673 deletions .github/actions/javascript/checkSVGCompression/index.js

Large diffs are not rendered by default.

901 changes: 228 additions & 673 deletions .github/actions/javascript/failureNotifier/index.js

Large diffs are not rendered by default.

901 changes: 228 additions & 673 deletions .github/actions/javascript/formatCodeCovComment/index.js

Large diffs are not rendered by default.

901 changes: 228 additions & 673 deletions .github/actions/javascript/generateHelpPreviewComment/index.js

Large diffs are not rendered by default.

903 changes: 229 additions & 674 deletions .github/actions/javascript/getAndroidRolloutPercentage/index.js

Large diffs are not rendered by default.

901 changes: 228 additions & 673 deletions .github/actions/javascript/getArtifactInfo/index.js

Large diffs are not rendered by default.

901 changes: 228 additions & 673 deletions .github/actions/javascript/getDeployPullRequestList/index.js

Large diffs are not rendered by default.

901 changes: 228 additions & 673 deletions .github/actions/javascript/getPreviousVersion/index.js

Large diffs are not rendered by default.

901 changes: 228 additions & 673 deletions .github/actions/javascript/getPullRequestDetails/index.js

Large diffs are not rendered by default.

901 changes: 228 additions & 673 deletions .github/actions/javascript/getPullRequestIncrementalChanges/index.js

Large diffs are not rendered by default.

901 changes: 228 additions & 673 deletions .github/actions/javascript/isAuthorizedContributor/index.js

Large diffs are not rendered by default.

1,208 changes: 369 additions & 839 deletions .github/actions/javascript/isDeployChecklistLocked/index.js

Large diffs are not rendered by default.

901 changes: 228 additions & 673 deletions .github/actions/javascript/markPullRequestsAsDeployed/index.js

Large diffs are not rendered by default.

901 changes: 228 additions & 673 deletions .github/actions/javascript/postOrReplaceComment/index.js

Large diffs are not rendered by default.

1,208 changes: 369 additions & 839 deletions .github/actions/javascript/proposalPoliceComment/index.js

Large diffs are not rendered by default.

901 changes: 228 additions & 673 deletions .github/actions/javascript/reopenIssueWithComment/index.js

Large diffs are not rendered by default.

901 changes: 228 additions & 673 deletions .github/actions/javascript/reviewerChecklist/index.js

Large diffs are not rendered by default.

901 changes: 228 additions & 673 deletions .github/actions/javascript/validateReassureOutput/index.js

Large diffs are not rendered by default.

901 changes: 228 additions & 673 deletions .github/actions/javascript/verifySignedCommits/index.js

Large diffs are not rendered by default.

901 changes: 228 additions & 673 deletions .github/actions/javascript/verifyStagingBuildsSucceeded/index.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions __mocks__/react-native-onyx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import type {ConnectOptions, OnyxKey} from 'react-native-onyx';

// eslint-disable-next-line no-restricted-imports
import Onyx, {useOnyx} from 'react-native-onyx';
import Onyx, {useOnyx, useOnyxState} from 'react-native-onyx';

let connectCallbackDelay = 0;
function addDelayToConnectCallback(delay: number) {
Expand Down Expand Up @@ -41,4 +41,4 @@ const reactNativeOnyxMock: ReactNativeOnyxMock = {

export default reactNativeOnyxMock;

export {useOnyx};
export {useOnyx, useOnyxState};
1 change: 0 additions & 1 deletion config/eslint/eslint.seatbelt.tsv
Original file line number Diff line number Diff line change
Expand Up @@ -1984,7 +1984,6 @@
"../../tests/ui/UnreadIndicatorsTest.tsx" "@typescript-eslint/no-restricted-imports" 1
"../../tests/ui/WorkspaceMoreFeaturesPageTest.tsx" "no-restricted-imports" 1
"../../tests/unit/canEditFieldOfMoneyRequestTest.ts" "@typescript-eslint/no-deprecated/randomReportAction.originalMessage" 3
"../../tests/unit/canEditFieldOfMoneyRequestTest.ts" "@typescript-eslint/no-restricted-imports" 1
"../../tests/unit/components/HTMLEngineProvider/VictoryChartAttributesParsers.test.ts" "rulesdir/no-raw-typography" 1
"../../tests/unit/FormulaTest.ts" "no-restricted-imports" 1
"../../tests/unit/HomePage/YourSpendSection/useYourSpendDataTest.ts" "no-restricted-imports" 1
Expand Down
2 changes: 0 additions & 2 deletions src/ONYXKEYS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1435,7 +1435,6 @@ const ONYXKEYS = {
DERIVED: {
REPORT_ATTRIBUTES: 'reportAttributes',
REPORT_TRANSACTIONS_AND_VIOLATIONS: 'reportTransactionsAndViolations',
OUTSTANDING_REPORTS_BY_POLICY_ID: 'outstandingReportsByPolicyID',
VISIBLE_REPORT_ACTIONS: 'visibleReportActions',
NON_PERSONAL_AND_WORKSPACE_CARD_LIST: 'nonPersonalAndWorkspaceCardList',
PERSONAL_AND_WORKSPACE_CARD_LIST: 'personalAndWorkspaceCardList',
Expand Down Expand Up @@ -2018,7 +2017,6 @@ type OnyxValuesMapping = {
type OnyxDerivedValuesMapping = {
[ONYXKEYS.DERIVED.REPORT_ATTRIBUTES]: OnyxTypes.ReportAttributesDerivedValue;
[ONYXKEYS.DERIVED.REPORT_TRANSACTIONS_AND_VIOLATIONS]: OnyxTypes.ReportTransactionsAndViolationsDerivedValue;
[ONYXKEYS.DERIVED.OUTSTANDING_REPORTS_BY_POLICY_ID]: OnyxTypes.OutstandingReportsByPolicyIDDerivedValue;
[ONYXKEYS.DERIVED.VISIBLE_REPORT_ACTIONS]: OnyxTypes.VisibleReportActionsDerivedValue;
[ONYXKEYS.DERIVED.NON_PERSONAL_AND_WORKSPACE_CARD_LIST]: OnyxTypes.NonPersonalAndWorkspaceCardListDerivedValue;
[ONYXKEYS.DERIVED.PERSONAL_AND_WORKSPACE_CARD_LIST]: OnyxTypes.PersonalAndWorkspaceCardListDerivedValue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import useLifecycleActions from '@hooks/useLifecycleActions';
import useLocalize from '@hooks/useLocalize';
import useNetwork from '@hooks/useNetwork';
import useOnyx from '@hooks/useOnyx';
import useOutstandingReportsByPolicyID from '@hooks/useOutstandingReportsByPolicyID';
import usePaginatedReportActions from '@hooks/usePaginatedReportActions';
import useParticipantsInvoiceReport from '@hooks/useParticipantsInvoiceReport';
import usePayChatReportActions from '@hooks/usePayChatReportActions';
Expand Down Expand Up @@ -111,7 +112,7 @@ function MoneyReportHeaderSecondaryActionsInner({reportID, primaryAction, isRepo
const [submitterLogin] = usePersonalDetail(moneyRequestReport?.ownerAccountID, loginSelector);
const [bankAccountList] = useOnyx(ONYXKEYS.BANK_ACCOUNT_LIST);
const [reportMetadata] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_METADATA}${moneyRequestReport?.reportID}`);
const [outstandingReportsByPolicyID] = useOnyx(ONYXKEYS.DERIVED.OUTSTANDING_REPORTS_BY_POLICY_ID);
const outstandingReportsByPolicyID = useOutstandingReportsByPolicyID();
const [moveExpenseReportNameValuePairs] = useOnyx(ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS, {
selector: createMoveExpenseReportNVPSelector(outstandingReportsByPolicyID, moneyRequestReport?.reportID),
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import useLifecycleActions from '@hooks/useLifecycleActions';
import useLocalize from '@hooks/useLocalize';
import useNetwork from '@hooks/useNetwork';
import useOnyx from '@hooks/useOnyx';
import useOutstandingReportsByPolicyID from '@hooks/useOutstandingReportsByPolicyID';
import {usePersonalDetail} from '@hooks/usePersonalDetails';
import useReportIsArchived from '@hooks/useReportIsArchived';
import useSelectedTransactionsActions from '@hooks/useSelectedTransactionsActions';
Expand Down Expand Up @@ -79,7 +80,7 @@ function MoneyReportHeaderSelectionDropdown({reportID, primaryAction, isReportIn
const [cardList] = useOnyx(ONYXKEYS.CARD_LIST);
const [reportMetadata] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_METADATA}${getNonEmptyStringOnyxID(moneyRequestReport?.reportID)}`);
const [dismissedRejectUseExplanation] = useOnyx(ONYXKEYS.NVP_DISMISSED_REJECT_USE_EXPLANATION);
const [outstandingReportsByPolicyID] = useOnyx(ONYXKEYS.DERIVED.OUTSTANDING_REPORTS_BY_POLICY_ID);
const outstandingReportsByPolicyID = useOutstandingReportsByPolicyID();
const [moveExpenseReportNameValuePairs] = useOnyx(ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS, {
selector: createMoveExpenseReportNVPSelector(outstandingReportsByPolicyID, moneyRequestReport?.reportID),
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import MenuItemFieldHTML from '@components/MenuItem/presets/MenuItemFieldHTML';
import useLocalize from '@hooks/useLocalize';
import useOnyx from '@hooks/useOnyx';
import useOutstandingReports from '@hooks/useOutstandingReports';
import {useOutstandingReportsForPolicy} from '@hooks/useOutstandingReportsByPolicyID';
import {useDerivedReportNameByReportID} from '@hooks/useReportAttributes';

import createDynamicRoute from '@libs/Navigation/helpers/dynamicRoutesUtils/createDynamicRoute';
Expand All @@ -20,7 +21,6 @@ import type {Participant} from '@src/types/onyx/IOU';

import type {OnyxEntry} from 'react-native-onyx';

import {createOutstandingReportsForPolicySelector} from '@selectors/Report';
import React from 'react';

import ExpenseFieldRow from './ExpenseFieldRow';
Expand All @@ -47,7 +47,7 @@ function ReportField({selectedParticipants, iouType, reportID, reportActionID, a
const {translate, localeCompare} = useLocalize();

const policyID = selectedParticipants?.at(0)?.policyID;
const [outstandingReportsForPolicy] = useOnyx(ONYXKEYS.DERIVED.OUTSTANDING_REPORTS_BY_POLICY_ID, {selector: createOutstandingReportsForPolicySelector(policyID)});
const outstandingReportsForPolicy = useOutstandingReportsForPolicy(policyID);
const [reportNameValuePairs] = useOnyx(ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS);
const [rules] = useOnyx(ONYXKEYS.COLLECTION.RULE);

Expand Down
3 changes: 2 additions & 1 deletion src/components/MoneyRequestHeaderSecondaryActions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import useLocalize from '@hooks/useLocalize';
import useMoneyRequestPolicyTagsForReport from '@hooks/useMoneyRequestPolicyTagsForReport';
import useNetwork from '@hooks/useNetwork';
import useOnyx from '@hooks/useOnyx';
import useOutstandingReportsByPolicyID from '@hooks/useOutstandingReportsByPolicyID';
import useParticipantsPolicyTags from '@hooks/useParticipantsPolicyTags';
import usePermissions from '@hooks/usePermissions';
import {usePersonalDetail} from '@hooks/usePersonalDetails';
Expand Down Expand Up @@ -174,7 +175,7 @@ function MoneyRequestHeaderSecondaryActions({reportID, onBackButtonPress}: Money
const [policyRecentlyUsedCurrencies] = useOnyx(ONYXKEYS.RECENTLY_USED_CURRENCIES);
const [dismissedRejectUseExplanation] = useOnyx(ONYXKEYS.NVP_DISMISSED_REJECT_USE_EXPLANATION);
const [dismissedHoldUseExplanation] = useOnyx(ONYXKEYS.NVP_DISMISSED_HOLD_USE_EXPLANATION);
const [outstandingReportsByPolicyID] = useOnyx(ONYXKEYS.DERIVED.OUTSTANDING_REPORTS_BY_POLICY_ID);
const outstandingReportsByPolicyID = useOutstandingReportsByPolicyID();
const [introSelected] = useOnyx(ONYXKEYS.NVP_INTRO_SELECTED);
const [recentWaypoints] = useOnyx(ONYXKEYS.NVP_RECENT_WAYPOINTS);
const [shouldFailAllRequests] = useOnyx(ONYXKEYS.NETWORK, {selector: shouldFailAllRequestsSelector});
Expand Down
3 changes: 2 additions & 1 deletion src/components/ReportActionItem/MoneyRequestView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import {useMemoizedLazyExpensifyIcons} from '@hooks/useLazyAsset';
import useLocalize from '@hooks/useLocalize';
import useNetwork from '@hooks/useNetwork';
import useOnyx from '@hooks/useOnyx';
import useOutstandingReportsByPolicyID from '@hooks/useOutstandingReportsByPolicyID';
import usePermissions from '@hooks/usePermissions';
import {usePersonalDetail} from '@hooks/usePersonalDetails';
import usePersonalPolicy from '@hooks/usePersonalPolicy';
Expand Down Expand Up @@ -289,7 +290,7 @@ function MoneyRequestView({
const [transactionBackup] = useOnyx(`${ONYXKEYS.COLLECTION.TRANSACTION_BACKUP}${getNonEmptyStringOnyxID(linkedTransactionID)}`);
const transactionViolations = useTransactionViolations(transaction?.transactionID, false, distanceOriginalPolicy ?? policy);
const allTransactionViolations = useAllTransactionViolations(transaction?.transactionID);
const [outstandingReportsByPolicyID] = useOnyx(ONYXKEYS.DERIVED.OUTSTANDING_REPORTS_BY_POLICY_ID);
const outstandingReportsByPolicyID = useOutstandingReportsByPolicyID();
const currentUserPersonalDetails = useCurrentUserPersonalDetails();
const delegateAccountID = useDelegateAccountID();
const personalDetailsList = usePersonalDetails();
Expand Down
10 changes: 6 additions & 4 deletions src/components/Search/SearchWriteActionsProvider.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import useCurrentUserPersonalDetails from '@hooks/useCurrentUserPersonalDetails';
import useNetwork from '@hooks/useNetwork';
import useOnyx from '@hooks/useOnyx';
import useOutstandingReportsByPolicyID from '@hooks/useOutstandingReportsByPolicyID';
import useResponsiveLayout from '@hooks/useResponsiveLayout';
import useSelfDMReport from '@hooks/useSelfDMReport';
import useShiftRangeSelection from '@hooks/useShiftRangeSelection';
Expand All @@ -21,10 +22,11 @@ import {isTransactionPendingDelete} from '@libs/TransactionUtils';

import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import type {OutstandingReportsByPolicyIDDerivedValue, Report, ReportNameValuePairs, SearchResults, Transaction} from '@src/types/onyx';
import type {Report, ReportNameValuePairs, SearchResults, Transaction} from '@src/types/onyx';
import type {SearchDataTypes} from '@src/types/onyx/SearchResults';
import {getEmptyObject, isEmptyObject} from '@src/types/utils/EmptyObject';

import type {OutstandingReportsByPolicyID} from '@selectors/Report';
import type {OnyxCollection, OnyxEntry} from 'react-native-onyx';

import {useIsFocused} from '@react-navigation/native';
Expand Down Expand Up @@ -120,8 +122,8 @@ type ReconcileSelectionParams = {
/** Report name-value pairs collection, used for the change-report eligibility archived check */
reportNameValuePairs: OnyxCollection<ReportNameValuePairs>;

/** Derived outstanding reports per policy, used for the change-report eligibility check */
outstandingReportsByPolicyID: OutstandingReportsByPolicyIDDerivedValue | undefined;
/** Outstanding reports per policy, used for the change-report eligibility check */
outstandingReportsByPolicyID: OutstandingReportsByPolicyID | undefined;

/** Whether the current snapshot is settled and can safely refresh/prune exclusions */
shouldReconcileExcludedTransactions: boolean;
Expand Down Expand Up @@ -535,7 +537,7 @@ function SearchWriteActionsProvider({
const {accountID, email, login} = useCurrentUserPersonalDetails();
const selfDMReport = useSelfDMReport();
const [reportNameValuePairs] = useOnyx(ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS);
const [outstandingReportsByPolicyID] = useOnyx(ONYXKEYS.DERIVED.OUTSTANDING_REPORTS_BY_POLICY_ID);
const outstandingReportsByPolicyID = useOutstandingReportsByPolicyID();
const [rules] = useOnyx(ONYXKEYS.COLLECTION.RULE);
const {applySelection, getSelectedTransactions, getExcludedTransactions, getAreAllMatchingItemsSelected} = useSearchSelectionActions();

Expand Down
11 changes: 6 additions & 5 deletions src/components/Search/selectionBuilders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ import type {ShiftRangeBatch} from '@libs/shiftRangeSelection';
import {getOriginalTransactionWithSplitInfo, hasValidModifiedAmount, isExpenseUnreported, isOnHold, isTransactionPendingDelete} from '@libs/TransactionUtils';

import CONST from '@src/CONST';
import type {OutstandingReportsByPolicyIDDerivedValue, Report, ReportNameValuePairs, Rule, Transaction} from '@src/types/onyx';
import type {Report, ReportNameValuePairs, Rule, Transaction} from '@src/types/onyx';
import type {SearchGroupBase, SearchResultDataType} from '@src/types/onyx/SearchResults';

import type {OutstandingReportsByPolicyID} from '@selectors/Report';
import type {OnyxCollection, OnyxEntry} from 'react-native-onyx';

import {deepEqual} from 'fast-equals';
Expand Down Expand Up @@ -119,8 +120,8 @@ type MapTransactionItemToSelectedEntryParams = {
/** Report name-value pairs collection, used for the change-report eligibility archived check */
reportNameValuePairs: OnyxCollection<ReportNameValuePairs>;

/** Derived outstanding reports per policy, used for the change-report eligibility check */
outstandingReportsByPolicyID: OutstandingReportsByPolicyIDDerivedValue | undefined;
/** Outstanding reports per policy, used for the change-report eligibility check */
outstandingReportsByPolicyID: OutstandingReportsByPolicyID | undefined;

/** The current user's self-DM report, used as the parent for unreported (track) expenses */
selfDMReport: OnyxEntry<Report>;
Expand Down Expand Up @@ -272,8 +273,8 @@ type PrepareTransactionsListParams = {
/** Report name-value pairs collection, used for the change-report eligibility archived check */
reportNameValuePairs: OnyxCollection<ReportNameValuePairs>;

/** Derived outstanding reports per policy, used for the change-report eligibility check */
outstandingReportsByPolicyID: OutstandingReportsByPolicyIDDerivedValue | undefined;
/** Outstanding reports per policy, used for the change-report eligibility check */
outstandingReportsByPolicyID: OutstandingReportsByPolicyID | undefined;

/** The current user's self-DM report, used as the parent for unreported (track) expenses */
selfDMReport: OnyxEntry<Report>;
Expand Down
7 changes: 5 additions & 2 deletions src/components/Table/TableBody.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ function TableBodyList({contentContainerStyle, emptyMessage, onLayout, style, ..
noResultsStateElement,
tableListMetadata,
isEmptyResult,
isDefaultViewEmpty,
scrollWidth,
tableWidth,
} = useTableContext<TableData>();
Expand Down Expand Up @@ -337,8 +338,10 @@ function TableBodyList({contentContainerStyle, emptyMessage, onLayout, style, ..
</View>
);

const emptyStateContent =
tableListMetadata.hasPageHeader && isEmptyResult ? (noResultsStateElement ?? EmptyResultComponent) : (emptyStateElement ?? renderListComponent(ListEmptyComponent));
// When the default view hides every row (e.g. all workspaces are archived), no search or filter is active,
// so show the empty state rather than "No results".
const shouldShowNoResultsState = tableListMetadata.hasPageHeader && isEmptyResult && !isDefaultViewEmpty;
const emptyStateContent = shouldShowNoResultsState ? (noResultsStateElement ?? EmptyResultComponent) : (emptyStateElement ?? renderListComponent(ListEmptyComponent));
const footerElement = renderListComponent(ListFooterComponent);
// Consumer footer flex growth is useful below normal rows, but inside the combined empty-state
// footer it can expand over the page header. Preserve the remaining style while disabling growth.
Expand Down
5 changes: 3 additions & 2 deletions src/components/Table/TableEmptyStates/TableNoResultsState.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@ type TableNoResultsStateProps = Omit<GenericEmptyStateComponentProps, 'headerMed
export default function TableNoResultsState(emptyStateProps: TableNoResultsStateProps) {
const styles = useThemeStyles();
const {translate} = useLocalize();
const {isEmptyResult, tableListMetadata} = useTableContext();
const {isEmptyResult, isDefaultViewEmpty, tableListMetadata} = useTableContext();
const illustrations = useMemoizedLazyIllustrations(['EmptyShelves']);

if (!isEmptyResult) {
// The default view hiding every row is not a search/filter result, so the empty state handles it instead.
if (!isEmptyResult || isDefaultViewEmpty) {
return null;
}

Expand Down
3 changes: 2 additions & 1 deletion src/hooks/useExpenseActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ import {useMemoizedLazyExpensifyIcons} from './useLazyAsset';
import useLocalize from './useLocalize';
import useMoneyRequestPolicyTagsForReport from './useMoneyRequestPolicyTagsForReport';
import useOnyx from './useOnyx';
import useOutstandingReportsByPolicyID from './useOutstandingReportsByPolicyID';
import useParentReportAction from './useParentReportAction';
import useParticipantsPolicyTags, {getPolicyTagsSelector} from './useParticipantsPolicyTags';
import usePermissions from './usePermissions';
Expand Down Expand Up @@ -155,7 +156,7 @@ function useExpenseActions({reportID, isReportInSearch = false, backTo, onDuplic
const [policyRecentlyUsedCurrencies] = useOnyx(ONYXKEYS.RECENTLY_USED_CURRENCIES);
const [selfDMReportID] = useOnyx(ONYXKEYS.SELF_DM_REPORT_ID);
const [selfDMReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${selfDMReportID}`);
const [outstandingReportsByPolicyID] = useOnyx(ONYXKEYS.DERIVED.OUTSTANDING_REPORTS_BY_POLICY_ID);
const outstandingReportsByPolicyID = useOutstandingReportsByPolicyID();
const [conciergeReportID] = useOnyx(ONYXKEYS.CONCIERGE_REPORT_ID);
const [conciergeChat] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${conciergeReportID}`);
const [introSelected] = useOnyx(ONYXKEYS.NVP_INTRO_SELECTED);
Expand Down
10 changes: 3 additions & 7 deletions src/hooks/useIsApproverOfOutstandingPolicyReports.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import {isApproverOfOutstandingPolicyReports} from '@libs/ReportUtils';

import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';

import useCurrentUserPersonalDetails from './useCurrentUserPersonalDetails';
import useOnyx from './useOnyx';
import {useOutstandingReportsForPolicy} from './useOutstandingReportsByPolicyID';
import usePrivateIsArchivedMap from './usePrivateIsArchivedMap';

/**
Expand All @@ -13,11 +10,10 @@ import usePrivateIsArchivedMap from './usePrivateIsArchivedMap';
*/
function useIsApproverOfOutstandingPolicyReports(policyID: string | undefined): boolean {
const currentUserPersonalDetails = useCurrentUserPersonalDetails();
// Subscribing without a selector keeps the change detection a reference compare, and the reports are reduced to a boolean below.
const [outstandingReportsByPolicyID] = useOnyx(ONYXKEYS.DERIVED.OUTSTANDING_REPORTS_BY_POLICY_ID);
const outstandingReportsForPolicy = useOutstandingReportsForPolicy(policyID);
const privateIsArchivedMap = usePrivateIsArchivedMap();

return isApproverOfOutstandingPolicyReports(currentUserPersonalDetails.accountID, outstandingReportsByPolicyID?.[policyID ?? CONST.DEFAULT_NUMBER_ID], privateIsArchivedMap);
return isApproverOfOutstandingPolicyReports(currentUserPersonalDetails.accountID, outstandingReportsForPolicy, privateIsArchivedMap);
}

export default useIsApproverOfOutstandingPolicyReports;
3 changes: 2 additions & 1 deletion src/hooks/useOutstandingReports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@ import type {OnyxEntry} from 'react-native-onyx';

import useMappedPolicies from './useMappedPolicies';
import useOnyx from './useOnyx';
import useOutstandingReportsByPolicyID from './useOutstandingReportsByPolicyID';

const policyIdMapper = (policy: OnyxEntry<Policy>) => policy?.id;

export default function useOutstandingReports(selectedReportID: string | undefined, selectedPolicyID: string | undefined, ownerAccountID: number | undefined, isEditing: boolean) {
const [outstandingReportsByPolicyID] = useOnyx(ONYXKEYS.DERIVED.OUTSTANDING_REPORTS_BY_POLICY_ID);
const outstandingReportsByPolicyID = useOutstandingReportsByPolicyID();
const [personalPolicyID] = useOnyx(ONYXKEYS.PERSONAL_POLICY_ID);
const [allPoliciesID] = useMappedPolicies(policyIdMapper);
const [selectedReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${selectedReportID}`);
Expand Down
Loading