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=301 --cache --cache-location=node_modules/.cache/eslint",
"lint": "NODE_OPTIONS=--max_old_space_size=8192 eslint . --max-warnings=299 --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
26 changes: 26 additions & 0 deletions src/components/LHNOptionsList/OptionRowLHNData.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
import {deepEqual} from 'fast-equals';
import React, {useMemo, useRef} from 'react';
import useCurrentReportID from '@hooks/useCurrentReportID';
import useGetExpensifyCardFromReportAction from '@hooks/useGetExpensifyCardFromReportAction';
import useOnyx from '@hooks/useOnyx';
import {getSortedReportActions, shouldReportActionBeVisibleAsLastAction} from '@libs/ReportActionsUtils';
import {canUserPerformWriteAction as canUserPerformWriteActionUtil} from '@libs/ReportUtils';
import SidebarUtils from '@libs/SidebarUtils';
import CONST from '@src/CONST';
import type {OptionData} from '@src/libs/ReportUtils';
import ONYXKEYS from '@src/ONYXKEYS';
import OptionRowLHN from './OptionRowLHN';
import type {OptionRowLHNDataProps} from './types';

Expand Down Expand Up @@ -39,6 +44,25 @@ function OptionRowLHNData({
const isReportFocused = isOptionFocused && currentReportIDValue?.currentReportID === reportID;

const optionItemRef = useRef<OptionData | undefined>(undefined);

const [reportActionsData] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reportID}`, {canBeMissing: true});

const lastAction = useMemo(() => {
if (!reportActionsData || !fullReport) {
return undefined;
}

const canUserPerformWriteAction = canUserPerformWriteActionUtil(fullReport);
const actionsArray = getSortedReportActions(Object.values(reportActionsData));

const reportActionsForDisplay = actionsArray.filter(
(reportAction) => shouldReportActionBeVisibleAsLastAction(reportAction, canUserPerformWriteAction) && reportAction.actionName !== CONST.REPORT.ACTIONS.TYPE.CREATED,
);

return reportActionsForDisplay.at(-1);
}, [reportActionsData, fullReport]);

const card = useGetExpensifyCardFromReportAction({reportAction: lastAction, policyID: fullReport?.policyID});
const optionItem = useMemo(() => {
Comment thread
DylanDylann marked this conversation as resolved.
// Note: ideally we'd have this as a dependent selector in onyx!
const item = SidebarUtils.getOptionData({
Expand All @@ -51,6 +75,7 @@ function OptionRowLHNData({
parentReportAction,
lastMessageTextFromReport,
invoiceReceiverPolicy,
card,
localeCompare,
});
// eslint-disable-next-line react-compiler/react-compiler
Expand Down Expand Up @@ -84,6 +109,7 @@ function OptionRowLHNData({
invoiceReceiverPolicy,
lastMessageTextFromReport,
reportAttributes,
card,
localeCompare,
]);

Expand Down
4 changes: 2 additions & 2 deletions src/components/ReportActionItem/IssueCardMessage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import type {OnyxEntry} from 'react-native-onyx';
import Button from '@components/Button';
import {useSession} from '@components/OnyxListItemProvider';
import RenderHTML from '@components/RenderHTML';
import useGetExpensifyCardFromReportAction from '@hooks/useGetExpensifyCardFromReportAction';
import useLocalize from '@hooks/useLocalize';
import useOnyx from '@hooks/useOnyx';
import useThemeStyles from '@hooks/useThemeStyles';
import {getExpensifyCardFromReportAction} from '@libs/CardMessageUtils';
import Navigation from '@libs/Navigation/Navigation';
import {getCardIssuedMessage, getOriginalMessage, shouldShowAddMissingDetails} from '@libs/ReportActionsUtils';
import ONYXKEYS from '@src/ONYXKEYS';
Expand All @@ -25,7 +25,7 @@ function IssueCardMessage({action, policyID}: IssueCardMessageProps) {
const styles = useThemeStyles();
const session = useSession();
const assigneeAccountID = (getOriginalMessage(action) as IssueNewCardOriginalMessage)?.assigneeAccountID;
const expensifyCard = getExpensifyCardFromReportAction({reportAction: action, policyID});
const expensifyCard = useGetExpensifyCardFromReportAction({reportAction: action, policyID});
const isAssigneeCurrentUser = !isEmptyObject(session) && session.accountID === assigneeAccountID;
const shouldShowAddMissingDetailsButton = isAssigneeCurrentUser && shouldShowAddMissingDetails(action?.actionName, expensifyCard);
const [cardList] = useOnyx(ONYXKEYS.CARD_LIST, {canBeMissing: true});
Expand Down
25 changes: 25 additions & 0 deletions src/hooks/useGetExpensifyCardFromReportAction.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import {getPolicy, getWorkspaceAccountID, isPolicyAdmin} from '@libs/PolicyUtils';
import {getOriginalMessage, isCardIssuedAction} from '@libs/ReportActionsUtils';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import type {Card, ReportAction} from '@src/types/onyx';
import useOnyx from './useOnyx';

function useGetExpensifyCardFromReportAction({reportAction, policyID}: {reportAction?: ReportAction; policyID?: string}): Card | undefined {
const [allUserCards] = useOnyx(ONYXKEYS.CARD_LIST, {canBeMissing: true});
const [allExpensifyCards] = useOnyx(ONYXKEYS.COLLECTION.WORKSPACE_CARDS_LIST, {
selector: (val) => {
const workspaceAccountID = getWorkspaceAccountID(policyID);
return val?.[`${ONYXKEYS.COLLECTION.WORKSPACE_CARDS_LIST}${workspaceAccountID}_${CONST.EXPENSIFY_CARD.BANK}`] ?? {};
},
canBeMissing: true,
});
const cardIssuedActionOriginalMessage = isCardIssuedAction(reportAction) ? getOriginalMessage(reportAction) : undefined;

const cardID = cardIssuedActionOriginalMessage?.cardID ?? CONST.DEFAULT_NUMBER_ID;
// This will be fixed as part of https://github.com/Expensify/Expensify/issues/507850
// eslint-disable-next-line deprecation/deprecation
return isPolicyAdmin(getPolicy(policyID)) ? allExpensifyCards?.[cardID] : allUserCards?.[cardID];
}

export default useGetExpensifyCardFromReportAction;
45 changes: 0 additions & 45 deletions src/libs/CardMessageUtils.ts

This file was deleted.

6 changes: 3 additions & 3 deletions src/libs/SidebarUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,14 @@
import type {PartialPolicyForSidebar, ReportsToDisplayInLHN} from '@hooks/useSidebarOrderedReports';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import type {PersonalDetails, PersonalDetailsList, ReportActions, ReportAttributesDerivedValue, ReportNameValuePairs, Transaction, TransactionViolation} from '@src/types/onyx';
import type {Card, PersonalDetails, PersonalDetailsList, ReportActions, ReportAttributesDerivedValue, ReportNameValuePairs, Transaction, TransactionViolation} from '@src/types/onyx';
import type Beta from '@src/types/onyx/Beta';
import type {ReportAttributes} from '@src/types/onyx/DerivedValues';
import type {Errors} from '@src/types/onyx/OnyxCommon';
import type Policy from '@src/types/onyx/Policy';
import type PriorityMode from '@src/types/onyx/PriorityMode';
import type Report from '@src/types/onyx/Report';
import type ReportAction from '@src/types/onyx/ReportAction';
import {getExpensifyCardFromReportAction} from './CardMessageUtils';
import {extractCollectionItemID} from './CollectionUtils';
import {hasValidDraftComment} from './DraftCommentUtils';
import {translateLocal} from './Localize';
Expand Down Expand Up @@ -132,7 +131,7 @@

const visibleReportActionItems: ReportActions = {};
let allPersonalDetails: OnyxEntry<PersonalDetailsList>;
Onyx.connect({

Check warning on line 134 in src/libs/SidebarUtils.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.PERSONAL_DETAILS_LIST,
callback: (value) => {
allPersonalDetails = value ?? {};
Expand All @@ -140,7 +139,7 @@
});

let allReports: OnyxCollection<Report>;
Onyx.connect({

Check warning on line 142 in src/libs/SidebarUtils.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.REPORT,
waitForCollectionCallback: true,
callback: (value) => {
Expand All @@ -148,7 +147,7 @@
},
});

Onyx.connect({

Check warning on line 150 in src/libs/SidebarUtils.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.REPORT_ACTIONS,
callback: (actions, key) => {
if (!actions || !key) {
Expand Down Expand Up @@ -510,6 +509,7 @@
parentReportAction,
lastMessageTextFromReport: lastMessageTextFromReportProp,
invoiceReceiverPolicy,
card,
localeCompare,
}: {
report: OnyxEntry<Report>;
Expand All @@ -521,6 +521,7 @@
lastMessageTextFromReport?: string;
invoiceReceiverPolicy?: OnyxEntry<Policy>;
reportAttributes: OnyxEntry<ReportAttributes>;
card: Card | undefined;
localeCompare: LocaleContextProps['localeCompare'];
}): OptionData | undefined {
// When a user signs out, Onyx is cleared. Due to the lazy rendering with a virtual list, it's possible for
Expand Down Expand Up @@ -746,7 +747,6 @@
} else if (lastAction?.actionName === CONST.REPORT.ACTIONS.TYPE.POLICY_CHANGE_LOG.LEAVE_POLICY) {
result.alternateText = getPolicyChangeLogEmployeeLeftMessage(lastAction, true);
} else if (isCardIssuedAction(lastAction)) {
const card = getExpensifyCardFromReportAction({reportAction: lastAction, policyID: report.policyID});
result.alternateText = getCardIssuedMessage({reportAction: lastAction, expensifyCard: card});
} else if (lastAction?.actionName !== CONST.REPORT.ACTIONS.TYPE.REPORT_PREVIEW && lastActorDisplayName && lastMessageTextFromReport) {
result.alternateText = formatReportLastMessageText(Parser.htmlToText(`${lastActorDisplayName}: ${lastMessageText}`));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import ContextMenuItem from '@components/ContextMenuItem';
import FocusTrapForModal from '@components/FocusTrap/FocusTrapForModal';
import useArrowKeyFocusManager from '@hooks/useArrowKeyFocusManager';
import useEnvironment from '@hooks/useEnvironment';
import useGetExpensifyCardFromReportAction from '@hooks/useGetExpensifyCardFromReportAction';
import useKeyboardShortcut from '@hooks/useKeyboardShortcut';
import useLocalize from '@hooks/useLocalize';
import useNetwork from '@hooks/useNetwork';
Expand All @@ -20,7 +21,6 @@ import useReportIsArchived from '@hooks/useReportIsArchived';
import useResponsiveLayout from '@hooks/useResponsiveLayout';
import useRestoreInputFocus from '@hooks/useRestoreInputFocus';
import useStyleUtils from '@hooks/useStyleUtils';
import {getExpensifyCardFromReportAction} from '@libs/CardMessageUtils';
import getNonEmptyStringOnyxID from '@libs/getNonEmptyStringOnyxID';
import {getLinkedTransactionID, getOneTransactionThreadReportID, getOriginalMessage, getReportAction} from '@libs/ReportActionsUtils';
import {
Expand Down Expand Up @@ -321,7 +321,7 @@ function BaseReportActionContextMenu({
};

// eslint-disable-next-line @typescript-eslint/non-nullable-type-assertion-style
const card = getExpensifyCardFromReportAction({reportAction: (reportAction ?? null) as ReportAction, policyID});
const card = useGetExpensifyCardFromReportAction({reportAction: (reportAction ?? null) as ReportAction, policyID});

return (
(isVisible || shouldKeepOpen || !isMini) && (
Expand Down
1 change: 1 addition & 0 deletions tests/perf-test/SidebarUtils.perf-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ describe('SidebarUtils', () => {
policy,
parentReportAction,
oneTransactionThreadReport: undefined,
card: undefined,
localeCompare,
}),
);
Expand Down
13 changes: 13 additions & 0 deletions tests/unit/SidebarUtilsTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,7 @@ describe('SidebarUtils', () => {
policy: undefined,
parentReportAction: undefined,
oneTransactionThreadReport: undefined,
card: undefined,
Comment thread
DylanDylann marked this conversation as resolved.
localeCompare,
});
const optionDataUnpinned = SidebarUtils.getOptionData({
Expand All @@ -338,6 +339,7 @@ describe('SidebarUtils', () => {
policy: undefined,
parentReportAction: undefined,
oneTransactionThreadReport: undefined,
card: undefined,
localeCompare,
});

Expand Down Expand Up @@ -832,6 +834,7 @@ describe('SidebarUtils', () => {
policy: undefined,
parentReportAction: undefined,
oneTransactionThreadReport: undefined,
card: undefined,
localeCompare,
});

Expand Down Expand Up @@ -890,6 +893,7 @@ describe('SidebarUtils', () => {
policy: undefined,
parentReportAction: undefined,
oneTransactionThreadReport: undefined,
card: undefined,
localeCompare,
});

Expand Down Expand Up @@ -931,6 +935,7 @@ describe('SidebarUtils', () => {
parentReportAction: undefined,
lastMessageTextFromReport: 'test message',
oneTransactionThreadReport: undefined,
card: undefined,
localeCompare,
});

Expand Down Expand Up @@ -965,6 +970,7 @@ describe('SidebarUtils', () => {
parentReportAction: undefined,
lastMessageTextFromReport: 'test message',
oneTransactionThreadReport: undefined,
card: undefined,
localeCompare,
});

Expand Down Expand Up @@ -996,6 +1002,7 @@ describe('SidebarUtils', () => {
parentReportAction: undefined,
lastMessageTextFromReport: 'test message',
oneTransactionThreadReport: undefined,
card: undefined,
localeCompare,
});

Expand Down Expand Up @@ -1116,6 +1123,7 @@ describe('SidebarUtils', () => {
policy,
parentReportAction: undefined,
oneTransactionThreadReport: undefined,
card: undefined,
localeCompare,
});
const {totalDisplaySpend} = getMoneyRequestSpendBreakdown(iouReport);
Expand Down Expand Up @@ -1158,6 +1166,7 @@ describe('SidebarUtils', () => {
parentReportAction: undefined,
lastMessageTextFromReport: 'test message',
oneTransactionThreadReport: undefined,
card: undefined,
localeCompare,
});

Expand Down Expand Up @@ -1223,6 +1232,7 @@ describe('SidebarUtils', () => {
policy: undefined,
parentReportAction: undefined,
oneTransactionThreadReport: undefined,
card: undefined,
localeCompare,
});

Expand Down Expand Up @@ -1265,6 +1275,7 @@ describe('SidebarUtils', () => {
policy: undefined,
parentReportAction: undefined,
oneTransactionThreadReport: undefined,
card: undefined,
localeCompare,
});

Expand Down Expand Up @@ -1329,6 +1340,7 @@ describe('SidebarUtils', () => {
policy: undefined,
parentReportAction: undefined,
oneTransactionThreadReport: undefined,
card: undefined,
localeCompare,
});

Expand Down Expand Up @@ -1440,6 +1452,7 @@ describe('SidebarUtils', () => {
policy: undefined,
parentReportAction: undefined,
oneTransactionThreadReport: undefined,
card: undefined,
localeCompare,
});

Expand Down
Loading
Loading