Skip to content
Open
Show file tree
Hide file tree
Changes from 2 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
6 changes: 6 additions & 0 deletions src/components/MoneyReportHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -776,7 +776,7 @@
}, [iouTransactionID, requestParentReportAction, transactionThreadReport?.reportID, transactionViolations]);

const [allPolicyTags] = useOnyx(ONYXKEYS.COLLECTION.POLICY_TAGS);
const targetPolicyTags = defaultExpensePolicy ? (allPolicyTags?.[`${ONYXKEYS.COLLECTION.POLICY_TAGS}${defaultExpensePolicy.id}`] ?? {}) : {};

Check warning on line 779 in src/components/MoneyReportHeader.tsx

View workflow job for this annotation

GitHub Actions / ESLint check

The 'targetPolicyTags' conditional could make the dependencies of useCallback Hook (at line 818) change on every render. Move it inside the useCallback callback. Alternatively, wrap the initialization of 'targetPolicyTags' in its own useMemo() Hook

Check warning on line 779 in src/components/MoneyReportHeader.tsx

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

The 'targetPolicyTags' conditional could make the dependencies of useCallback Hook (at line 818) change on every render. Move it inside the useCallback callback. Alternatively, wrap the initialization of 'targetPolicyTags' in its own useMemo() Hook

const duplicateExpenseTransaction = useCallback(
(transactionList: OnyxTypes.Transaction[]) => {
Expand Down Expand Up @@ -1932,6 +1932,9 @@
}, [originalSelectedTransactionsOptions, showDeleteModal, dismissedRejectUseExplanation, isDelegateAccessRestricted, showDelegateNoAccessModal]);

const shouldShowSelectedTransactionsButton = !!selectedTransactionsOptions.length && !transactionThreadReportID;
const shouldPopoverUseScrollView =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❌ CONSISTENCY-3 (docs)

The shouldPopoverUseScrollView computation logic is now duplicated in 4 places across the codebase: SettlementButton/index.tsx, SearchBulkActionsButton.tsx, MoneyReportHeader.tsx, and MoneyRequestReportActionsList.tsx. All four perform the identical pattern:

options.length >= CONST.DROPDOWN_SCROLL_THRESHOLD ||
    options.some((option) => (option.subMenuItems?.length ?? 0) >= CONST.DROPDOWN_SCROLL_THRESHOLD);

Extract this into a shared utility function, for example:

// src/libs/shouldPopoverUseScrollView.ts
import CONST from '@src/CONST';
import type {DropdownOption} from '@components/ButtonWithDropdownMenu/types';

function shouldPopoverUseScrollView<T>(options: Array<DropdownOption<T>>): boolean {
    return (
        options.length >= CONST.DROPDOWN_SCROLL_THRESHOLD ||
        options.some((option) => (option.subMenuItems?.length ?? 0) >= CONST.DROPDOWN_SCROLL_THRESHOLD)
    );
}

export default shouldPopoverUseScrollView;

Then use it in all four call sites:

const popoverUseScrollView = shouldPopoverUseScrollView(selectedTransactionsOptions);

Please rate this suggestion with 👍 or 👎 to help us improve! Reactions are used to monitor reviewer efficiency.

selectedTransactionsOptions.length >= CONST.DROPDOWN_SCROLL_THRESHOLD ||
selectedTransactionsOptions.some((option) => (option.subMenuItems?.length ?? 0) >= CONST.DROPDOWN_SCROLL_THRESHOLD);

if (isMobileSelectionModeEnabled && shouldUseNarrowLayout) {
// If mobile selection mode is enabled but only one or no transactions remain, turn it off
Expand Down Expand Up @@ -2023,6 +2026,8 @@
})}
isSplitButton={false}
shouldAlwaysShowDropdownMenu
shouldPopoverUseScrollView={shouldPopoverUseScrollView}
wrapperStyle={styles.w100}
/>
</View>
)}
Expand All @@ -2040,6 +2045,7 @@
})}
isSplitButton={false}
shouldAlwaysShowDropdownMenu
shouldPopoverUseScrollView={shouldPopoverUseScrollView}
wrapperStyle={styles.w100}
/>
</View>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,10 @@
});
}, [originalSelectedTransactionsOptions, dismissedRejectUseExplanation, isDelegateAccessRestricted, showDelegateNoAccessModal]);

const shouldPopoverUseScrollView =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❌ CONSISTENCY-3 (docs)

Same duplicated shouldPopoverUseScrollView computation as in MoneyReportHeader.tsx, SettlementButton/index.tsx, and SearchBulkActionsButton.tsx. This should use the shared utility function suggested in the other comment to eliminate the 4-way duplication.


Please rate this suggestion with 👍 or 👎 to help us improve! Reactions are used to monitor reviewer efficiency.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nyomanjyotisa I think following DRY principle makes sense, wdyt?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh yeah, sorry I missed the bot comment. I will update the PR

selectedTransactionsOptions.length >= CONST.DROPDOWN_SCROLL_THRESHOLD ||
selectedTransactionsOptions.some((option) => (option.subMenuItems?.length ?? 0) >= CONST.DROPDOWN_SCROLL_THRESHOLD);

const dismissRejectModalBasedOnAction = useCallback(() => {
if (rejectModalAction === CONST.REPORT.TRANSACTION_SECONDARY_ACTIONS.REJECT_BULK) {
dismissRejectUseExplanation();
Expand Down Expand Up @@ -740,7 +744,7 @@
reportScrollManager.scrollToEnd();
readActionSkipped.current = false;
readNewestAction(report.reportID, !!reportMetadata?.hasOnceLoadedReportActions);
}, [setIsFloatingMessageCounterVisible, hasNewestReportAction, reportScrollManager, report.reportID, reportMetadata?.hasOnceLoadedReportActions]);

Check warning on line 747 in src/components/MoneyRequestReportView/MoneyRequestReportActionsList.tsx

View workflow job for this annotation

GitHub Actions / ESLint check

React Hook useCallback has a missing dependency: 'introSelected'. Either include it or remove the dependency array

Check warning on line 747 in src/components/MoneyRequestReportView/MoneyRequestReportActionsList.tsx

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

React Hook useCallback has a missing dependency: 'introSelected'. Either include it or remove the dependency array

const scrollToNewTransaction = useCallback(
(pageY: number) => {
Expand Down Expand Up @@ -800,6 +804,7 @@
customText={translate('workspace.common.selected', {count: selectedTransactionIDs.length})}
isSplitButton={false}
shouldAlwaysShowDropdownMenu
shouldPopoverUseScrollView={shouldPopoverUseScrollView}
wrapperStyle={[styles.w100, styles.ph5]}
/>
<View style={[styles.alignItemsCenter, styles.userSelectNone, styles.flexRow, styles.pt6, styles.ph8, styles.pb3]}>
Expand Down
Loading