Skip to content
Merged
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
25 changes: 18 additions & 7 deletions src/libs/OptionsListUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1693,6 +1693,22 @@ function getValidPersonalDetailOptions(
return personalDetailsOptions;
}

/**
* Returns a list of logins that should be restricted (i.e., hidden or excluded in the UI)
* based on dynamic business logic and feature flags.
* Centralizes restriction logic to avoid scattering conditions across the codebase.
*/
function getRestrictedLogins(config: GetOptionsConfig, options: OptionList, canShowManagerMcTest: boolean): Record<string, boolean> {
Comment thread
DylanDylann marked this conversation as resolved.
const userHasReportWithManagerMcTest = Object.values(options.reports).some((report) => isManagerMcTestReport(report));
return {
[CONST.EMAIL.MANAGER_MCTEST]:
!canShowManagerMcTest ||
(getIsUserSubmittedExpenseOrScannedReceipt() && !userHasReportWithManagerMcTest) ||
!Permissions.isBetaEnabled(CONST.BETAS.NEWDOT_MANAGER_MCTEST, config.betas) ||
isUserInvitedToWorkspace(),
};
}

/**
* Options are reports and personal details. This function filters out the options that are not valid to be displayed.
*/
Expand All @@ -1711,18 +1727,13 @@ function getValidOptions(
...config
}: GetOptionsConfig = {},
): Options {
const userHasReportWithManagerMcTest = Object.values(options.reports).some((report) => isManagerMcTestReport(report));
const restrictedLogins = getRestrictedLogins(config, options, canShowManagerMcTest);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Not sure if we should pass down canShowManagerMcTest for this method

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

its a bit misleading to pass it as true and then still have it end up as false

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

canShowManagerMcTest is a flag to mark whether ManagerMcTest should be displayed or not in that place. For example, we only expect that ManagerMcTest displays on screen 1, then in screen 1 we will pass canShowManagerMcTest is true. But it doesn't mean that if canShowManagerMcTest is true, we will always display the ManagerMcTest option, we still need to check other conditions. Note that It is "canShow" not "shouldShow"


// Gather shared configs:
const loginsToExclude: Record<string, boolean> = {
[CONST.EMAIL.NOTIFICATIONS]: true,
...excludeLogins,
// Exclude Manager McTest if selection is made from Create or Submit flow
[CONST.EMAIL.MANAGER_MCTEST]:
!canShowManagerMcTest ||
(getIsUserSubmittedExpenseOrScannedReceipt() && !userHasReportWithManagerMcTest) ||
!Permissions.isBetaEnabled(CONST.BETAS.NEWDOT_MANAGER_MCTEST, config.betas) ||
isUserInvitedToWorkspace(),
...restrictedLogins,
};
// If we're including selected options from the search results, we only want to exclude them if the search input is empty
// This is because on certain pages, we show the selected options at the top when the search input is empty
Expand Down