Skip to content
Open
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
4 changes: 3 additions & 1 deletion src/components/LHNOptionsList/LHNOptionsList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,9 @@ function LHNOptionsList({style, contentContainerStyles, data, onSelectRow, optio
const canUserPerformWriteAction = canUserPerformWriteActionUtil(item, isReportArchived);
const actionsArray = getSortedReportActions(Object.values(itemReportActions));
const reportActionsForDisplay = actionsArray.filter(
(reportAction) => shouldReportActionBeVisibleAsLastAction(reportAction, canUserPerformWriteAction) && reportAction.actionName !== CONST.REPORT.ACTIONS.TYPE.CREATED,
(reportAction) =>
shouldReportActionBeVisibleAsLastAction(reportAction, canUserPerformWriteAction, itemPolicy?.areCategoriesEnabled) &&
reportAction.actionName !== CONST.REPORT.ACTIONS.TYPE.CREATED,
);
lastAction = reportActionsForDisplay.at(-1);
}
Expand Down
5 changes: 3 additions & 2 deletions src/libs/OptionsListUtils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,13 +198,13 @@
*/

let allPersonalDetails: OnyxEntry<PersonalDetailsList>;
Onyx.connect({

Check warning on line 201 in src/libs/OptionsListUtils/index.ts

View workflow job for this annotation

GitHub Actions / ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function

Check warning on line 201 in src/libs/OptionsListUtils/index.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 = isEmptyObject(value) ? {} : value),
});

const policies: OnyxCollection<Policy> = {};
Onyx.connect({

Check warning on line 207 in src/libs/OptionsListUtils/index.ts

View workflow job for this annotation

GitHub Actions / ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function

Check warning on line 207 in src/libs/OptionsListUtils/index.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,
callback: (policy, key) => {
if (!policy || !key || !policy.name) {
Expand All @@ -216,7 +216,7 @@
});

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

Check warning on line 219 in src/libs/OptionsListUtils/index.ts

View workflow job for this annotation

GitHub Actions / ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function

Check warning on line 219 in src/libs/OptionsListUtils/index.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 @@ -225,7 +225,7 @@
});

let allReportNameValuePairsOnyxConnect: OnyxCollection<ReportNameValuePairs>;
Onyx.connect({

Check warning on line 228 in src/libs/OptionsListUtils/index.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_NAME_VALUE_PAIRS,
waitForCollectionCallback: true,
callback: (value) => {
Expand All @@ -237,7 +237,7 @@
const allSortedReportActions: Record<string, ReportAction[]> = {};
let allReportActions: OnyxCollection<ReportActions>;
const lastVisibleReportActions: ReportActions = {};
Onyx.connect({

Check warning on line 240 in src/libs/OptionsListUtils/index.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 Down Expand Up @@ -274,6 +274,7 @@
} else {
lastReportActions[reportID] = firstReportAction;
}
const policy = policies?.[`${ONYXKEYS.COLLECTION.POLICY}${report?.policyID}`];

const reportNameValuePairs = allReportNameValuePairsOnyxConnect?.[`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${reportID}`];
const isReportArchived = !!reportNameValuePairs?.private_isArchived;
Expand All @@ -284,7 +285,7 @@
const reportActionsForDisplay = sortedReportActions.filter(
(reportAction, actionKey) =>
(!(isWhisperAction(reportAction) && !isReportPreviewAction(reportAction) && !isMoneyRequestAction(reportAction)) || isActionableMentionWhisper(reportAction)) &&
shouldReportActionBeVisible(reportAction, actionKey, isWriteActionAllowed) &&
shouldReportActionBeVisible(reportAction, actionKey, isWriteActionAllowed, policy?.areCategoriesEnabled) &&
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Recompute LHN visible-action cache on policy updates

This filter now makes lastVisibleReportActions depend on policy?.areCategoriesEnabled, but the cache is only rebuilt inside the REPORT_ACTIONS Onyx callback; when Categories is toggled without any new report-action updates, the cached last action stays stale and getLastMessageTextForReport() can continue deriving LHN text from an old concierge category action. In practice this means the sidebar preview can remain incorrect until another report action arrives, so the cache should also be invalidated/recomputed from policy changes.

Useful? React with 👍 / 👎.

reportAction.actionName !== CONST.REPORT.ACTIONS.TYPE.CREATED &&
reportAction.pendingAction !== CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE,
);
Expand All @@ -299,7 +300,7 @@
});

let activePolicyID: OnyxEntry<string>;
Onyx.connect({

Check warning on line 303 in src/libs/OptionsListUtils/index.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.NVP_ACTIVE_POLICY_ID,
callback: (value) => (activePolicyID = value),
});
Expand Down Expand Up @@ -617,7 +618,7 @@
}): string {
const reportID = report?.reportID;
const lastReportAction = reportID ? lastVisibleReportActions[reportID] : undefined;
const lastVisibleMessage = getLastVisibleMessage(report?.reportID);
const lastVisibleMessage = getLastVisibleMessage(report?.reportID, undefined, undefined, undefined, policy?.areCategoriesEnabled);

// some types of actions are filtered out for lastReportAction, in some cases we need to check the actual last action
const lastOriginalReportAction = reportID ? lastReportActions[reportID] : undefined;
Expand Down
16 changes: 11 additions & 5 deletions src/libs/ReportActionsUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
}

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

Check warning on line 80 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 @@ -89,7 +89,7 @@
});

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

Check warning on line 92 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 @@ -98,13 +98,13 @@
});

let isNetworkOffline = false;
Onyx.connect({

Check warning on line 101 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 deprecatedCurrentUserAccountID: number | undefined;
Onyx.connect({

Check warning on line 107 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 Down Expand Up @@ -1079,7 +1079,7 @@
* Checks if a reportAction is fit for display, meaning that it's not deprecated, is of a valid
* and supported type, it's not deleted and also not closed.
*/
function shouldReportActionBeVisible(reportAction: OnyxEntry<ReportAction>, key: string | number, canUserPerformWriteAction?: boolean): boolean {
function shouldReportActionBeVisible(reportAction: OnyxEntry<ReportAction>, key: string | number, canUserPerformWriteAction?: boolean, arePolicyCategoriesEnabled?: boolean): boolean {
if (!reportAction) {
return false;
}
Expand Down Expand Up @@ -1152,6 +1152,10 @@
return false;
}

if (isConciergeCategoryOptions(reportAction) && arePolicyCategoriesEnabled !== undefined && !arePolicyCategoriesEnabled) {
return false;
}

// All other actions are displayed except thread parents, deleted, or non-pending actions
return !!reportAction.pendingAction || !isDeletedAction(reportAction) || isDeletedParentAction(reportAction) || isReversedTransaction(reportAction);
}
Expand All @@ -1170,7 +1174,7 @@
* Checks if a reportAction is fit for display as report last action, meaning that
* it satisfies shouldReportActionBeVisible, it's not whisper action and not deleted.
*/
function shouldReportActionBeVisibleAsLastAction(reportAction: OnyxInputOrEntry<ReportAction>, canUserPerformWriteAction?: boolean): boolean {
function shouldReportActionBeVisibleAsLastAction(reportAction: OnyxInputOrEntry<ReportAction>, canUserPerformWriteAction?: boolean, areCategoriesEnabled?: boolean): boolean {
if (!reportAction) {
return false;
}
Expand All @@ -1182,7 +1186,7 @@
// If a whisper action is the REPORT_PREVIEW action, we are displaying it.
// If the action's message text is empty and it is not a deleted parent with visible child actions, hide it. Else, consider the action to be displayable.
return (
shouldReportActionBeVisible(reportAction, reportAction.reportActionID, canUserPerformWriteAction) &&
shouldReportActionBeVisible(reportAction, reportAction.reportActionID, canUserPerformWriteAction, areCategoriesEnabled) &&
(!(isWhisperAction(reportAction) && !isReportPreviewAction(reportAction) && !isMoneyRequestAction(reportAction)) || isActionableMentionWhisper(reportAction)) &&
!(isDeletedAction(reportAction) && !isDeletedParentAction(reportAction) && !isPendingHide(reportAction))
);
Expand Down Expand Up @@ -1219,6 +1223,7 @@
canUserPerformWriteAction?: boolean,
actionsToMerge: Record<string, NullishDeep<ReportAction> | null> = {},
reportActionsParam: OnyxCollection<ReportActions> = allReportActions,
areCategoriesEnabled?: boolean,
): OnyxEntry<ReportAction> {
let reportActions: Array<ReportAction | null | undefined> = [];
if (!isEmpty(actionsToMerge)) {
Expand All @@ -1228,7 +1233,7 @@
} else {
reportActions = Object.values(allReportActions?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reportID}`] ?? {});
}
const visibleReportActions = reportActions.filter((action): action is ReportAction => shouldReportActionBeVisibleAsLastAction(action, canUserPerformWriteAction));
const visibleReportActions = reportActions.filter((action): action is ReportAction => shouldReportActionBeVisibleAsLastAction(action, canUserPerformWriteAction, areCategoriesEnabled));
const sortedReportActions = getSortedReportActions(visibleReportActions, true);
if (sortedReportActions.length === 0) {
return undefined;
Expand Down Expand Up @@ -1256,8 +1261,9 @@
canUserPerformWriteAction?: boolean,
actionsToMerge: Record<string, NullishDeep<ReportAction> | null> = {},
reportAction: OnyxInputOrEntry<ReportAction> | undefined = undefined,
areCategoriesEnabled?: boolean,
): LastVisibleMessage {
const lastVisibleAction = reportAction ?? getLastVisibleAction(reportID, canUserPerformWriteAction, actionsToMerge);
const lastVisibleAction = reportAction ?? getLastVisibleAction(reportID, canUserPerformWriteAction, actionsToMerge, undefined, areCategoriesEnabled);
const message = getReportActionMessage(lastVisibleAction);

if (message && isReportMessageAttachment(message)) {
Expand Down
2 changes: 1 addition & 1 deletion src/libs/SidebarUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1074,7 +1074,7 @@ function getOptionData({
result.alternateText =
lastMessageTextFromReport.length > 0
? formatReportLastMessageText(Parser.htmlToText(lastMessageText))
: getLastVisibleMessage(report.reportID, result.isAllowedToComment, {}, lastAction)?.lastMessageText;
: getLastVisibleMessage(report.reportID, result.isAllowedToComment, {}, lastAction, policy?.areCategoriesEnabled)?.lastMessageText;

if (!result.alternateText) {
result.alternateText = formatReportLastMessageText(
Expand Down
9 changes: 7 additions & 2 deletions src/pages/inbox/report/ReportActionsView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@ function ReportActionsView({
[canPerformWriteAction],
);

const areCategoriesEnabledSelector = useCallback((policy: OnyxEntry<OnyxTypes.Policy>): boolean => {
return !!policy?.areCategoriesEnabled;
}, []);

const [transactionThreadReportActions] = useOnyx(
`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${transactionThreadReportID}`,
{
Expand All @@ -108,6 +112,7 @@ function ReportActionsView({
const reportPreviewAction = useMemo(() => getReportPreviewAction(report.chatReportID, report.reportID), [report.chatReportID, report.reportID]);
const didLayout = useRef(false);
const {isOffline} = useNetwork();
const [areCategoriesEnabled] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY}${report.policyID}`, {canBeMissing: true, selector: areCategoriesEnabledSelector});

const {shouldUseNarrowLayout} = useResponsiveLayout();
const isFocused = useIsFocused();
Expand Down Expand Up @@ -221,10 +226,10 @@ function ReportActionsView({
reportActions.filter(
(reportAction) =>
(isOffline || isDeletedParentAction(reportAction) || reportAction.pendingAction !== CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE || reportAction.errors) &&
shouldReportActionBeVisible(reportAction, reportAction.reportActionID, canPerformWriteAction) &&
shouldReportActionBeVisible(reportAction, reportAction.reportActionID, canPerformWriteAction, areCategoriesEnabled) &&
isIOUActionMatchingTransactionList(reportAction, reportTransactionIDs),
),
[reportActions, isOffline, canPerformWriteAction, reportTransactionIDs],
[reportActions, isOffline, canPerformWriteAction, reportTransactionIDs, areCategoriesEnabled],
);

const newestReportAction = useMemo(() => reportActions?.at(0), [reportActions]);
Expand Down
6 changes: 6 additions & 0 deletions tests/unit/ReportActionsUtilsTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1529,6 +1529,12 @@ describe('ReportActionsUtils', () => {
const actual = ReportActionsUtils.shouldReportActionBeVisible(reportAction, reportAction.reportActionID, true);
expect(actual).toBe(true);
});

it("should return false for concierge categorize suggestion whisper message when the policy's category feature is disabled", () => {
const reportAction: ReportAction = {...createRandomReportAction(123), actionName: CONST.REPORT.ACTIONS.TYPE.CONCIERGE_CATEGORY_OPTIONS};
const result = ReportActionsUtils.shouldReportActionBeVisible(reportAction, reportAction.reportActionID, true, false);
expect(result).toBe(false);
});
});

describe('getPolicyChangeLogUpdateEmployee', () => {
Expand Down
Loading