Skip to content
Merged
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
3 changes: 0 additions & 3 deletions src/hooks/useSearchTypeMenuSections.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ const useSearchTypeMenuSections = () => {
const [currentUserLoginAndAccountID] = useOnyx(ONYXKEYS.SESSION, {selector: currentUserLoginAndAccountIDSelector, canBeMissing: false});
const [activePolicyID] = useOnyx(ONYXKEYS.NVP_ACTIVE_POLICY_ID, {canBeMissing: true});
const [savedSearches] = useOnyx(ONYXKEYS.SAVED_SEARCHES, {canBeMissing: true});
const [reports] = useOnyx(ONYXKEYS.COLLECTION.REPORT, {canBeMissing: true});
const [transactionViolations] = useOnyx(ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS, {canBeMissing: true});
const {isBetaEnabled} = usePermissions();
const isASAPSubmitBetaEnabled = isBetaEnabled(CONST.BETAS.ASAP_SUBMIT);
Expand All @@ -70,7 +69,6 @@ const useSearchTypeMenuSections = () => {
defaultExpensifyCard,
isASAPSubmitBetaEnabled,
hasViolations,
reports,
),
[
currentUserLoginAndAccountID?.email,
Expand All @@ -84,7 +82,6 @@ const useSearchTypeMenuSections = () => {
isOffline,
isASAPSubmitBetaEnabled,
hasViolations,
reports,
],
);

Expand Down
37 changes: 2 additions & 35 deletions src/libs/SearchUIUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -523,40 +523,11 @@ function getSuggestedSearches(accountID: number = CONST.DEFAULT_NUMBER_ID, defau
};
}

/**
* Check if a user has any expense reports assigned to them for approval
*/
function hasPendingApprovalTasks(reports: OnyxCollection<OnyxTypes.Report>, currentUserAccountID?: number): boolean {
if (!reports || !currentUserAccountID) {
return false;
}

const hasPending = Object.values(reports).some((report) => {
if (!report) {
return false;
}

const isExpenseReport = report.type === CONST.REPORT.TYPE.EXPENSE;
const isSubmitted = report.stateNum === CONST.REPORT.STATE_NUM.SUBMITTED && report.statusNum === CONST.REPORT.STATUS_NUM.SUBMITTED;
const isAssignedToUser = report.managerID === currentUserAccountID;

if (isExpenseReport && isSubmitted && isAssignedToUser) {
return true;
}

return false;
});

return hasPending;
}

function getSuggestedSearchesVisibility(
currentUserEmail: string | undefined,
cardFeedsByPolicy: Record<string, CardFeedForDisplay[]>,
policies: OnyxCollection<OnyxTypes.Policy>,
defaultExpensifyCard: CardFeedForDisplay | undefined,
reports?: OnyxCollection<OnyxTypes.Report>,
currentUserAccountID?: number,
): Record<ValueOf<typeof CONST.SEARCH.SEARCH_KEYS>, boolean> {
let shouldShowSubmitSuggestion = false;
let shouldShowPaySuggestion = false;
Expand Down Expand Up @@ -593,10 +564,7 @@ function getSuggestedSearchesVisibility(

const isEligibleForSubmitSuggestion = isPaidPolicy;
const isEligibleForPaySuggestion = isPaidPolicy && isPayer;

const hasPendingApprovals = hasPendingApprovalTasks(reports, currentUserAccountID);
const isEligibleForApproveSuggestion = isPaidPolicy && isApprovalEnabled && (isApprover || isSubmittedTo || hasPendingApprovals);

const isEligibleForApproveSuggestion = isPaidPolicy && isApprovalEnabled && (isApprover || isSubmittedTo);
const isEligibleForExportSuggestion = isExporter && !hasExportError;
const isEligibleForStatementsSuggestion = isPaidPolicy && !!policy.areCompanyCardsEnabled && hasCardFeed;
const isEligibleForUnapprovedCashSuggestion = isPaidPolicy && isAdmin && isApprovalEnabled && isPaymentEnabled;
Expand Down Expand Up @@ -1957,12 +1925,11 @@ function createTypeMenuSections(
defaultExpensifyCard: CardFeedForDisplay | undefined,
isASAPSubmitBetaEnabled: boolean,
hasViolations: boolean,
reports?: OnyxCollection<OnyxTypes.Report>,
): SearchTypeMenuSection[] {
const typeMenuSections: SearchTypeMenuSection[] = [];

const suggestedSearches = getSuggestedSearches(currentUserAccountID, defaultCardFeed?.id);
const suggestedSearchesVisibility = getSuggestedSearchesVisibility(currentUserEmail, cardFeedsByPolicy, policies, defaultExpensifyCard, reports, currentUserAccountID);
const suggestedSearchesVisibility = getSuggestedSearchesVisibility(currentUserEmail, cardFeedsByPolicy, policies, defaultExpensifyCard);

// Todo section
{
Expand Down
6 changes: 3 additions & 3 deletions tests/unit/Search/SearchUIUtilsTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2019,7 +2019,7 @@ describe('SearchUIUtils', () => {

describe('Test createTypeMenuItems', () => {
it('should return the default menu items', () => {
const menuItems = SearchUIUtils.createTypeMenuSections(undefined, undefined, {}, undefined, {}, undefined, {}, false, undefined, true, false, undefined)
const menuItems = SearchUIUtils.createTypeMenuSections(undefined, undefined, {}, undefined, {}, undefined, {}, false, undefined, true, false)
.map((section) => section.menuItems)
.flat();

Expand Down Expand Up @@ -2652,7 +2652,7 @@ describe('SearchUIUtils', () => {
} as OnyxTypes.Policy,
};

const response = SearchUIUtils.getSuggestedSearchesVisibility(adminEmail, {}, policies, undefined, {}, adminAccountID);
const response = SearchUIUtils.getSuggestedSearchesVisibility(adminEmail, {}, policies, undefined);
expect(response.export).toBe(false);

// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
Expand All @@ -2666,7 +2666,7 @@ describe('SearchUIUtils', () => {
successfulDate: new Date().toISOString(),
};

const response2 = SearchUIUtils.getSuggestedSearchesVisibility(adminEmail, {}, policies, undefined, {}, adminAccountID);
const response2 = SearchUIUtils.getSuggestedSearchesVisibility(adminEmail, {}, policies, undefined);
expect(response2.export).toBe(true);
});
});
Expand Down
Loading