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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
"test:debug": "TZ=utc NODE_OPTIONS='--inspect-brk --experimental-vm-modules' jest --runInBand",
"perf-test": "NODE_OPTIONS=--experimental-vm-modules npx reassure",
"typecheck": "NODE_OPTIONS=--max_old_space_size=8192 tsc",
"lint": "NODE_OPTIONS=--max_old_space_size=8192 eslint . --max-warnings=198 --cache --cache-location=node_modules/.cache/eslint",
"lint": "NODE_OPTIONS=--max_old_space_size=8192 eslint . --max-warnings=197 --cache --cache-location=node_modules/.cache/eslint",
"lint-changed": "NODE_OPTIONS=--max_old_space_size=8192 ./scripts/lintChanged.sh",
"lint-watch": "npx eslint-watch --watch --changed",
"shellcheck": "./scripts/shellCheck.sh",
Expand Down
15 changes: 13 additions & 2 deletions src/hooks/useSearchTypeMenuSections.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,22 @@ const useSearchTypeMenuSections = () => {
const {isOffline} = useNetwork();
const [allPolicies] = useOnyx(ONYXKEYS.COLLECTION.POLICY, {selector: (policies) => mapOnyxCollectionItems(policies, policySelector), canBeMissing: true});
const [currentUserLoginAndAccountID] = useOnyx(ONYXKEYS.SESSION, {selector: (session) => ({email: session?.email, accountID: session?.accountID}), canBeMissing: false});
const [activePolicyID] = useOnyx(ONYXKEYS.NVP_ACTIVE_POLICY_ID, {canBeMissing: true});
const [savedSearches] = useOnyx(ONYXKEYS.SAVED_SEARCHES, {canBeMissing: true});

const typeMenuSections = useMemo(
() => createTypeMenuSections(currentUserLoginAndAccountID?.email, currentUserLoginAndAccountID?.accountID, cardFeedsByPolicy, defaultCardFeed, allPolicies, savedSearches, isOffline),
[currentUserLoginAndAccountID?.email, currentUserLoginAndAccountID?.accountID, cardFeedsByPolicy, defaultCardFeed, allPolicies, savedSearches, isOffline],
() =>
createTypeMenuSections(
currentUserLoginAndAccountID?.email,
currentUserLoginAndAccountID?.accountID,
cardFeedsByPolicy,
defaultCardFeed,
allPolicies,
activePolicyID,
savedSearches,
isOffline,
),
[currentUserLoginAndAccountID?.email, currentUserLoginAndAccountID?.accountID, cardFeedsByPolicy, defaultCardFeed, allPolicies, activePolicyID, savedSearches, isOffline],
);

return {typeMenuSections};
Expand Down
2 changes: 0 additions & 2 deletions src/libs/Firebase/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ type PerfAttributes = {
transactionViolationsLength: string;
policiesLength: string;
transactionsLength: string;
policyType: string;
policyRole: string;
};

// TODO confirm which attributes are required for Firebase
Expand Down
4 changes: 0 additions & 4 deletions src/libs/Firebase/utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// We have opted for `Onyx.connectWithoutView` here as this logic is strictly non-UI in nature.
import Onyx from 'react-native-onyx';
import {getActivePolicy} from '@libs/PolicyUtils';
import * as SessionUtils from '@libs/SessionUtils';
import ONYXKEYS from '@src/ONYXKEYS';
import type {PerfAttributes} from './types';
Expand Down Expand Up @@ -60,7 +59,6 @@ Onyx.connectWithoutView({

function getAttributes<T extends keyof PerfAttributes>(attributes?: T[]): Pick<PerfAttributes, T> {
const session = SessionUtils.getSession();
const policy = getActivePolicy();

const allAttributes: PerfAttributes = {
accountId: session?.accountID?.toString() ?? 'N/A',
Expand All @@ -70,8 +68,6 @@ function getAttributes<T extends keyof PerfAttributes>(attributes?: T[]): Pick<P
transactionViolationsLength: transactionViolationsCount.toString(),
policiesLength: policiesCount.toString(),
transactionsLength: transactionsCount.toString(),
policyType: policy?.type ?? 'N/A',
policyRole: policy?.role ?? 'N/A',
};

if (attributes && attributes.length > 0) {
Expand Down
13 changes: 0 additions & 13 deletions src/libs/PolicyUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,19 +56,13 @@
};

let allPolicies: OnyxCollection<Policy>;
let activePolicyId: OnyxEntry<string>;

Onyx.connect({

Check warning on line 60 in src/libs/PolicyUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.POLICY,
waitForCollectionCallback: true,
callback: (value) => (allPolicies = value),
});

Onyx.connect({
key: ONYXKEYS.NVP_ACTIVE_POLICY_ID,
callback: (value) => (activePolicyId = value),
});

/**
* Filter out the active policies, which will exclude policies with pending deletion
* and policies the current user doesn't belong to.
Expand Down Expand Up @@ -1354,12 +1348,6 @@
return policy?.approvalMode === CONST.POLICY.APPROVAL_MODE.OPTIONAL || !!policy?.errorFields?.approvalMode;
}

function getActivePolicy(): OnyxEntry<Policy> {
// This will be fixed as part of https://github.com/Expensify/Expensify/issues/507850
// eslint-disable-next-line deprecation/deprecation
return getPolicy(activePolicyId);
}

function getUserFriendlyWorkspaceType(workspaceType: ValueOf<typeof CONST.POLICY.TYPE>) {
switch (workspaceType) {
case CONST.POLICY.TYPE.CORPORATE:
Expand Down Expand Up @@ -1647,7 +1635,6 @@
hasUnsupportedIntegration,
getWorkflowApprovalsUnavailable,
getNetSuiteImportCustomFieldLabel,
getActivePolicy,
getUserFriendlyWorkspaceType,
isPolicyAccessible,
hasOtherControlWorkspaces,
Expand Down
5 changes: 3 additions & 2 deletions src/libs/SearchUIUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ import {translateLocal} from './Localize';
import Navigation from './Navigation/Navigation';
import Parser from './Parser';
import {getDisplayNameOrDefault} from './PersonalDetailsUtils';
import {arePaymentsEnabled, canSendInvoice, getActivePolicy, getGroupPaidPoliciesWithExpenseChatEnabled, getPolicy, isPaidGroupPolicy, isPolicyPayer} from './PolicyUtils';
import {arePaymentsEnabled, canSendInvoice, getGroupPaidPoliciesWithExpenseChatEnabled, getPolicy, isPaidGroupPolicy, isPolicyPayer} from './PolicyUtils';
import {
getOriginalMessage,
getReportActionHtml,
Expand Down Expand Up @@ -1863,6 +1863,7 @@ function createTypeMenuSections(
cardFeedsByPolicy: Record<string, CardFeedForDisplay[]>,
defaultCardFeed: CardFeedForDisplay | undefined,
policies: OnyxCollection<OnyxTypes.Policy>,
activePolicyID: string | undefined,
savedSearches: OnyxEntry<OnyxTypes.SaveSearch>,
isOffline: boolean,
): SearchTypeMenuSection[] {
Expand Down Expand Up @@ -1894,7 +1895,7 @@ function createTypeMenuSections(
buttonText: 'report.newReport.createReport',
buttonAction: () => {
interceptAnonymousUser(() => {
const activePolicy = getActivePolicy();
const activePolicy = policies?.[`${ONYXKEYS.COLLECTION.POLICY}${activePolicyID}`];
const personalDetails = getPersonalDetailsForAccountID(currentUserAccountID) as OnyxTypes.PersonalDetails;

let workspaceIDForReportCreation: string | undefined;
Expand Down
2 changes: 0 additions & 2 deletions tests/unit/FirebaseUtilsTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ describe('getAttributes', () => {
'policiesLength',
'transactionsLength',
'transactionViolationsLength',
'policyType',
'policyRole',
];

const checkAttributes = (attributes: Partial<PerfAttributes>, expectedAttributes: Array<keyof Partial<PerfAttributes>>) => {
Expand Down
21 changes: 12 additions & 9 deletions tests/unit/Search/SearchUIUtilsTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1873,7 +1873,7 @@ describe('SearchUIUtils', () => {

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

Expand Down Expand Up @@ -1951,7 +1951,7 @@ describe('SearchUIUtils', () => {

const mockSavedSearches = {};

const sections = SearchUIUtils.createTypeMenuSections(adminEmail, adminAccountID, mockCardFeedsByPolicy, undefined, mockPolicies, mockSavedSearches, false);
const sections = SearchUIUtils.createTypeMenuSections(adminEmail, adminAccountID, mockCardFeedsByPolicy, undefined, mockPolicies, undefined, mockSavedSearches, false);

const todoSection = sections.find((section) => section.translationPath === 'common.todo');
expect(todoSection).toBeDefined();
Expand Down Expand Up @@ -2001,7 +2001,7 @@ describe('SearchUIUtils', () => {

const mockSavedSearches = {};

const sections = SearchUIUtils.createTypeMenuSections(adminEmail, adminAccountID, mockCardFeedsByPolicy, undefined, mockPolicies, mockSavedSearches, false);
const sections = SearchUIUtils.createTypeMenuSections(adminEmail, adminAccountID, mockCardFeedsByPolicy, undefined, mockPolicies, undefined, mockSavedSearches, false);

const accountingSection = sections.find((section) => section.translationPath === 'workspace.common.accounting');
expect(accountingSection).toBeDefined();
Expand Down Expand Up @@ -2030,7 +2030,7 @@ describe('SearchUIUtils', () => {
},
};

const sections = SearchUIUtils.createTypeMenuSections(adminEmail, adminAccountID, {}, undefined, {}, mockSavedSearches, false);
const sections = SearchUIUtils.createTypeMenuSections(adminEmail, adminAccountID, {}, undefined, {}, undefined, mockSavedSearches, false);

const savedSection = sections.find((section) => section.translationPath === 'search.savedSearchesMenuItemTitle');
expect(savedSection).toBeDefined();
Expand All @@ -2039,7 +2039,7 @@ describe('SearchUIUtils', () => {
it('should not show saved section when there are no saved searches', () => {
const mockSavedSearches = {};

const sections = SearchUIUtils.createTypeMenuSections(adminEmail, adminAccountID, {}, undefined, {}, mockSavedSearches, false);
const sections = SearchUIUtils.createTypeMenuSections(adminEmail, adminAccountID, {}, undefined, {}, undefined, mockSavedSearches, false);

const savedSection = sections.find((section) => section.translationPath === 'search.savedSearchesMenuItemTitle');
expect(savedSection).toBeUndefined();
Expand All @@ -2061,6 +2061,7 @@ describe('SearchUIUtils', () => {
{},
undefined,
{},
undefined,
mockSavedSearches,
false, // not offline
);
Expand All @@ -2085,6 +2086,7 @@ describe('SearchUIUtils', () => {
{},
undefined,
{},
undefined,
mockSavedSearches,
true, // offline
);
Expand All @@ -2107,7 +2109,7 @@ describe('SearchUIUtils', () => {
},
};

const sections = SearchUIUtils.createTypeMenuSections(adminEmail, adminAccountID, {}, undefined, mockPolicies, {}, false);
const sections = SearchUIUtils.createTypeMenuSections(adminEmail, adminAccountID, {}, undefined, mockPolicies, undefined, {}, false);

const todoSection = sections.find((section) => section.translationPath === 'common.todo');
expect(todoSection).toBeUndefined();
Expand All @@ -2133,6 +2135,7 @@ describe('SearchUIUtils', () => {
{}, // no card feeds
undefined,
mockPolicies,
undefined,
{},
false,
);
Expand Down Expand Up @@ -2165,7 +2168,7 @@ describe('SearchUIUtils', () => {
},
};

const sections = SearchUIUtils.createTypeMenuSections(adminEmail, adminAccountID, {}, undefined, mockPolicies, {}, false);
const sections = SearchUIUtils.createTypeMenuSections(adminEmail, adminAccountID, {}, undefined, mockPolicies, undefined, {}, false);

const accountingSection = sections.find((section) => section.translationPath === 'workspace.common.accounting');
expect(accountingSection).toBeDefined();
Expand All @@ -2190,7 +2193,7 @@ describe('SearchUIUtils', () => {
};

const mockCardFeedsByPolicy: Record<string, CardFeedForDisplay[]> = {};
const sections = SearchUIUtils.createTypeMenuSections(adminEmail, adminAccountID, mockCardFeedsByPolicy, undefined, mockPolicies, {}, false);
const sections = SearchUIUtils.createTypeMenuSections(adminEmail, adminAccountID, mockCardFeedsByPolicy, undefined, mockPolicies, undefined, {}, false);
const accountingSection = sections.find((section) => section.translationPath === 'workspace.common.accounting');

expect(accountingSection).toBeDefined();
Expand All @@ -2199,7 +2202,7 @@ describe('SearchUIUtils', () => {
});

it('should generate correct routes', () => {
const menuItems = SearchUIUtils.createTypeMenuSections(undefined, undefined, {}, undefined, {}, {}, false)
const menuItems = SearchUIUtils.createTypeMenuSections(undefined, undefined, {}, undefined, {}, undefined, {}, false)
.map((section) => section.menuItems)
.flat();

Expand Down
Loading