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=226 --cache --cache-location=node_modules/.cache/eslint",
"lint": "NODE_OPTIONS=--max_old_space_size=8192 eslint . --max-warnings=225 --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
1 change: 1 addition & 0 deletions src/components/LHNOptionsList/OptionRowLHNData.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ function OptionRowLHNData({
lastMessageTextFromReport,
invoiceReceiverPolicy,
card,
lastAction,
localeCompare,
isReportArchived,
});
Expand Down
14 changes: 7 additions & 7 deletions src/libs/ReportActionsUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
type MemberChangeMessageElement = MessageTextElement | MemberChangeMessageUserMentionElement | MemberChangeMessageRoomReferenceElement;

let allReportActions: OnyxCollection<ReportActions>;
Onyx.connect({

Check warning on line 60 in src/libs/ReportActionsUtils.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,
waitForCollectionCallback: true,
callback: (actions) => {
Expand All @@ -69,7 +69,7 @@
});

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

Check warning on line 72 in src/libs/ReportActionsUtils.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 @@ -78,14 +78,14 @@
});

let isNetworkOffline = false;
Onyx.connect({

Check warning on line 81 in src/libs/ReportActionsUtils.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.NETWORK,
callback: (val) => (isNetworkOffline = val?.isOffline ?? false),
});

let currentUserAccountID: number | undefined;
let currentEmail = '';
Onyx.connect({

Check warning on line 88 in src/libs/ReportActionsUtils.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.SESSION,
callback: (value) => {
// When signed out, value is undefined
Expand All @@ -99,7 +99,7 @@
});

let privatePersonalDetails: PrivatePersonalDetails | undefined;
Onyx.connect({

Check warning on line 102 in src/libs/ReportActionsUtils.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.PRIVATE_PERSONAL_DETAILS,
callback: (personalDetails) => {
privatePersonalDetails = personalDetails;
Expand Down Expand Up @@ -2387,40 +2387,40 @@
return getReportActionText(action);
}

function getWorkspaceTagUpdateMessage(action: ReportAction): string {
function getWorkspaceTagUpdateMessage(action: ReportAction | undefined): string {
const {tagListName, tagName, enabled, newName, newValue, oldName, oldValue, updatedField, count} =
getOriginalMessage(action as ReportAction<typeof CONST.REPORT.ACTIONS.TYPE.POLICY_CHANGE_LOG.ADD_CATEGORY>) ?? {};

if (action.actionName === CONST.REPORT.ACTIONS.TYPE.POLICY_CHANGE_LOG.ADD_TAG && tagListName && tagName) {
if (action?.actionName === CONST.REPORT.ACTIONS.TYPE.POLICY_CHANGE_LOG.ADD_TAG && tagListName && tagName) {
return translateLocal('workspaceActions.addTag', {
tagListName,
tagName,
});
}

if (action.actionName === CONST.REPORT.ACTIONS.TYPE.POLICY_CHANGE_LOG.DELETE_TAG && tagListName && tagName) {
if (action?.actionName === CONST.REPORT.ACTIONS.TYPE.POLICY_CHANGE_LOG.DELETE_TAG && tagListName && tagName) {
return translateLocal('workspaceActions.deleteTag', {
tagListName,
tagName,
});
}

if (action.actionName === CONST.REPORT.ACTIONS.TYPE.POLICY_CHANGE_LOG.DELETE_MULTIPLE_TAGS && count && tagListName) {
if (action?.actionName === CONST.REPORT.ACTIONS.TYPE.POLICY_CHANGE_LOG.DELETE_MULTIPLE_TAGS && count && tagListName) {
return translateLocal('workspaceActions.deleteMultipleTags', {
count,
tagListName,
});
}

if (action.actionName === CONST.REPORT.ACTIONS.TYPE.POLICY_CHANGE_LOG.UPDATE_TAG_ENABLED && tagListName && tagName) {
if (action?.actionName === CONST.REPORT.ACTIONS.TYPE.POLICY_CHANGE_LOG.UPDATE_TAG_ENABLED && tagListName && tagName) {
return translateLocal('workspaceActions.updateTagEnabled', {
tagListName,
tagName,
enabled,
});
}

if (action.actionName === CONST.REPORT.ACTIONS.TYPE.POLICY_CHANGE_LOG.UPDATE_TAG_NAME && tagListName && newName && oldName) {
if (action?.actionName === CONST.REPORT.ACTIONS.TYPE.POLICY_CHANGE_LOG.UPDATE_TAG_NAME && tagListName && newName && oldName) {
return translateLocal('workspaceActions.updateTagName', {
tagListName,
newName,
Expand All @@ -2429,7 +2429,7 @@
}

if (
action.actionName === CONST.REPORT.ACTIONS.TYPE.POLICY_CHANGE_LOG.UPDATE_TAG &&
action?.actionName === CONST.REPORT.ACTIONS.TYPE.POLICY_CHANGE_LOG.UPDATE_TAG &&
tagListName &&
(typeof oldValue === 'string' || typeof oldValue === 'undefined') &&
typeof newValue === 'string' &&
Expand Down
36 changes: 3 additions & 33 deletions src/libs/SidebarUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
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 {extractCollectionItemID} from './CollectionUtils';
import {translateLocal} from './Localize';
import {getLastActorDisplayName, getLastMessageTextForReport, getPersonalDetailsForAccountIDs, shouldShowLastActorDisplayName} from './OptionsListUtils';
import Parser from './Parser';
Expand Down Expand Up @@ -56,7 +55,6 @@
getReportAction,
getReportActionMessageText,
getRetractedMessage,
getSortedReportActions,
getTagListNameUpdatedMessage,
getTravelUpdateMessage,
getUpdatedApprovalRuleMessage,
Expand Down Expand Up @@ -84,7 +82,6 @@
isTagModificationAction,
isTaskAction,
isTransactionThread,
shouldReportActionBeVisibleAsLastAction,
} from './ReportActionsUtils';
import type {OptionData} from './ReportUtils';
import {
Expand Down Expand Up @@ -141,9 +138,8 @@

type WelcomeMessage = {phrase1?: string; messageText?: string; messageHtml?: string};

const visibleReportActionItems: ReportActions = {};
let allPersonalDetails: OnyxEntry<PersonalDetailsList>;
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.PERSONAL_DETAILS_LIST,
callback: (value) => {
allPersonalDetails = value ?? {};
Expand All @@ -151,7 +147,7 @@
});

let allReports: OnyxCollection<Report>;
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,
waitForCollectionCallback: true,
callback: (value) => {
Expand All @@ -159,32 +155,6 @@
},
});

Onyx.connect({
key: ONYXKEYS.COLLECTION.REPORT_ACTIONS,
callback: (actions, key) => {
if (!actions || !key) {
return;
}
const reportID = extractCollectionItemID(key);
const report = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${reportID}`];
const canUserPerformWriteAction = canUserPerformWriteActionUtil(report);
const actionsArray: ReportAction[] = getSortedReportActions(Object.values(actions));

// The report is only visible if it is the last action not deleted that
// does not match a closed or created state.
const reportActionsForDisplay = actionsArray.filter(
(reportAction) => shouldReportActionBeVisibleAsLastAction(reportAction, canUserPerformWriteAction) && reportAction.actionName !== CONST.REPORT.ACTIONS.TYPE.CREATED,
);

const reportAction = reportActionsForDisplay.at(-1);
if (!reportAction) {
delete visibleReportActionItems[reportID];
return;
}
visibleReportActionItems[reportID] = reportAction;
},
});

function compareStringDates(a: string, b: string): 0 | 1 | -1 {
if (a < b) {
return -1;
Expand Down Expand Up @@ -650,6 +620,7 @@
lastMessageTextFromReport: lastMessageTextFromReportProp,
invoiceReceiverPolicy,
card,
lastAction,
localeCompare,
isReportArchived = false,
}: {
Expand All @@ -663,6 +634,7 @@
invoiceReceiverPolicy?: OnyxEntry<Policy>;
reportAttributes: OnyxEntry<ReportAttributes>;
card: Card | undefined;
lastAction: ReportAction | undefined;
localeCompare: LocaleContextProps['localeCompare'];
isReportArchived?: boolean;
}): OptionData | undefined {
Expand Down Expand Up @@ -760,8 +732,6 @@
// We only create tooltips for the first 10 users or so since some reports have hundreds of users, causing performance to degrade.
const displayNamesWithTooltips = getDisplayNamesWithTooltips((participantPersonalDetailList || []).slice(0, 10), hasMultipleParticipants, localeCompare, undefined, isSelfDM(report));

const lastAction = visibleReportActionItems[report.reportID];
// lastActorAccountID can be an empty string
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
const lastActorAccountID = lastAction?.actorAccountID || report.lastActorAccountID;
// If the last actor's details are not currently saved in Onyx Collection,
Expand Down Expand Up @@ -860,7 +830,7 @@
result.alternateText = getWorkspaceCategoryUpdateMessage(lastAction);
} else if (isActionOfType(lastAction, CONST.REPORT.ACTIONS.TYPE.POLICY_CHANGE_LOG.UPDATE_TAG_LIST_NAME)) {
result.alternateText = getCleanedTagName(getTagListNameUpdatedMessage(lastAction) ?? '');
} else if (isTagModificationAction(lastAction?.actionName)) {
} else if (isTagModificationAction(lastAction?.actionName ?? '')) {
result.alternateText = getCleanedTagName(getWorkspaceTagUpdateMessage(lastAction) ?? '');
} else if (isActionOfType(lastAction, CONST.REPORT.ACTIONS.TYPE.POLICY_CHANGE_LOG.UPDATE_CUSTOM_UNIT)) {
result.alternateText = getWorkspaceCustomUnitUpdatedMessage(lastAction);
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 @@ -85,6 +85,7 @@ describe('SidebarUtils', () => {
parentReportAction,
oneTransactionThreadReport: undefined,
card: undefined,
lastAction: 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 @@ -352,6 +352,7 @@ describe('SidebarUtils', () => {
oneTransactionThreadReport: undefined,
card: undefined,
localeCompare,
lastAction: undefined,
});
const optionDataUnpinned = SidebarUtils.getOptionData({
report: MOCK_REPORT_UNPINNED,
Expand All @@ -363,6 +364,7 @@ describe('SidebarUtils', () => {
oneTransactionThreadReport: undefined,
card: undefined,
localeCompare,
lastAction: undefined,
});

expect(optionDataPinned?.isPinned).toBe(true);
Expand Down Expand Up @@ -858,6 +860,7 @@ describe('SidebarUtils', () => {
oneTransactionThreadReport: undefined,
card: undefined,
localeCompare,
lastAction,
});

// Then the alternate text should be equal to the message of the last action prepended with the last actor display name.
Expand Down Expand Up @@ -917,6 +920,7 @@ describe('SidebarUtils', () => {
oneTransactionThreadReport: undefined,
card: undefined,
localeCompare,
lastAction,
});

// Then the alternate text should show @Hidden.
Expand Down Expand Up @@ -958,6 +962,7 @@ describe('SidebarUtils', () => {
lastMessageTextFromReport: 'test message',
oneTransactionThreadReport: undefined,
card: undefined,
lastAction: undefined,
localeCompare,
});

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

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

Expand Down Expand Up @@ -1146,6 +1153,7 @@ describe('SidebarUtils', () => {
parentReportAction: undefined,
oneTransactionThreadReport: undefined,
card: undefined,
lastAction: undefined,
localeCompare,
});
const {totalDisplaySpend} = getMoneyRequestSpendBreakdown(iouReport);
Expand Down Expand Up @@ -1189,6 +1197,7 @@ describe('SidebarUtils', () => {
lastMessageTextFromReport: 'test message',
oneTransactionThreadReport: undefined,
card: undefined,
lastAction: undefined,
localeCompare,
});

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

// Then the alternate text should be equal to the message of the last action prepended with the last actor display name.
Expand Down Expand Up @@ -1303,6 +1313,7 @@ describe('SidebarUtils', () => {
oneTransactionThreadReport: undefined,
card: undefined,
localeCompare,
lastAction,
});

expect(result?.alternateText).toBe(`You: moved this report to the Three's Workspace workspace`);
Expand Down Expand Up @@ -1370,6 +1381,7 @@ describe('SidebarUtils', () => {
oneTransactionThreadReport: undefined,
card: undefined,
localeCompare,
lastAction,
});

expect(result?.alternateText).toBe(`You: ${getReportActionMessageText(lastAction)}`);
Expand Down Expand Up @@ -1482,6 +1494,7 @@ describe('SidebarUtils', () => {
oneTransactionThreadReport: undefined,
card: undefined,
localeCompare,
lastAction,
});

expect(result?.alternateText).toContain(`${getReportActionMessageText(lastAction)}`);
Expand Down
Loading