Skip to content

Commit 738cb14

Browse files
authored
Merge pull request #78519 from etCoderDysto/fix_75276_n
fix: hide categorize whisper message when categories are disabled
2 parents e94f05d + 2dc38da commit 738cb14

File tree

4 files changed

+19
-4
lines changed

4 files changed

+19
-4
lines changed

src/libs/OptionsListUtils/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,13 +289,14 @@ Onyx.connect({
289289
const reportNameValuePairs = allReportNameValuePairs?.[`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${reportID}`];
290290
const isReportArchived = !!reportNameValuePairs?.private_isArchived;
291291
const isWriteActionAllowed = canUserPerformWriteAction(report, isReportArchived);
292+
const policy = allPolicies?.[`${ONYXKEYS.COLLECTION.POLICY}${report?.policyID}`];
292293

293294
// The report is only visible if it is the last action not deleted that
294295
// does not match a closed or created state.
295296
const reportActionsForDisplay = sortedReportActions.filter(
296297
(reportAction, actionKey) =>
297298
(!(isWhisperAction(reportAction) && !isReportPreviewAction(reportAction) && !isMoneyRequestAction(reportAction)) || isActionableMentionWhisper(reportAction)) &&
298-
shouldReportActionBeVisible(reportAction, actionKey, isWriteActionAllowed) &&
299+
shouldReportActionBeVisible(reportAction, actionKey, isWriteActionAllowed, policy) &&
299300
reportAction.actionName !== CONST.REPORT.ACTIONS.TYPE.CREATED &&
300301
reportAction.pendingAction !== CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE,
301302
);

src/libs/ReportActionsUtils.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1028,7 +1028,7 @@ function isResolvedConciergeDescriptionOptions(reportAction: OnyxEntry<ReportAct
10281028
* Checks if a reportAction is fit for display, meaning that it's not deprecated, is of a valid
10291029
* and supported type, it's not deleted and also not closed.
10301030
*/
1031-
function shouldReportActionBeVisible(reportAction: OnyxEntry<ReportAction>, key: string | number, canUserPerformWriteAction?: boolean): boolean {
1031+
function shouldReportActionBeVisible(reportAction: OnyxEntry<ReportAction>, key: string | number, canUserPerformWriteAction?: boolean, policy?: OnyxEntry<Policy>): boolean {
10321032
if (!reportAction) {
10331033
return false;
10341034
}
@@ -1101,6 +1101,10 @@ function shouldReportActionBeVisible(reportAction: OnyxEntry<ReportAction>, key:
11011101
return false;
11021102
}
11031103

1104+
if (isConciergeCategoryOptions(reportAction) && policy && !policy.areCategoriesEnabled) {
1105+
return false;
1106+
}
1107+
11041108
// All other actions are displayed except thread parents, deleted, or non-pending actions
11051109
return !!reportAction.pendingAction || !isDeletedAction(reportAction) || isDeletedParentAction(reportAction) || isReversedTransaction(reportAction);
11061110
}

src/pages/home/report/ReportActionsView.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ function ReportActionsView({
108108
const reportPreviewAction = useMemo(() => getReportPreviewAction(report.chatReportID, report.reportID), [report.chatReportID, report.reportID]);
109109
const didLayout = useRef(false);
110110
const {isOffline} = useNetwork();
111+
const [policy] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY}${report.policyID}`, {canBeMissing: true});
111112

112113
const {shouldUseNarrowLayout} = useResponsiveLayout();
113114
const isFocused = useIsFocused();
@@ -221,10 +222,10 @@ function ReportActionsView({
221222
reportActions.filter(
222223
(reportAction) =>
223224
(isOffline || isDeletedParentAction(reportAction) || reportAction.pendingAction !== CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE || reportAction.errors) &&
224-
shouldReportActionBeVisible(reportAction, reportAction.reportActionID, canPerformWriteAction) &&
225+
shouldReportActionBeVisible(reportAction, reportAction.reportActionID, canPerformWriteAction, policy) &&
225226
isIOUActionMatchingTransactionList(reportAction, reportTransactionIDs),
226227
),
227-
[reportActions, isOffline, canPerformWriteAction, reportTransactionIDs],
228+
[reportActions, isOffline, canPerformWriteAction, policy, reportTransactionIDs],
228229
);
229230

230231
const newestReportAction = useMemo(() => reportActions?.at(0), [reportActions]);

tests/unit/ReportActionsUtilsTest.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import {
2626
import {buildOptimisticCreatedReportForUnapprovedAction} from '../../src/libs/ReportUtils';
2727
import ONYXKEYS from '../../src/ONYXKEYS';
2828
import type {Card, OriginalMessageIOU, Report, ReportAction, ReportActions} from '../../src/types/onyx';
29+
import createRandomPolicy from '../utils/collections/policies';
2930
import createRandomReportAction from '../utils/collections/reportActions';
3031
import {createRandomReport} from '../utils/collections/reports';
3132
import * as LHNTestUtils from '../utils/LHNTestUtils';
@@ -1486,6 +1487,14 @@ describe('ReportActionsUtils', () => {
14861487
const actual = ReportActionsUtils.shouldReportActionBeVisible(reportAction, reportAction.reportActionID, true);
14871488
expect(actual).toBe(true);
14881489
});
1490+
1491+
it("should return false for concierge categorize suggestion whisper message when the policy's category feature is disabled", () => {
1492+
const reportAction: ReportAction = {...createRandomReportAction(123), actionName: CONST.REPORT.ACTIONS.TYPE.CONCIERGE_CATEGORY_OPTIONS};
1493+
const categoryFeatureDisabledPolicy = {...createRandomPolicy(1234), areCategoriesEnabled: false};
1494+
1495+
const result = ReportActionsUtils.shouldReportActionBeVisible(reportAction, reportAction.reportActionID, true, categoryFeatureDisabledPolicy);
1496+
expect(result).toBe(false);
1497+
});
14891498
});
14901499

14911500
describe('getPolicyChangeLogUpdateEmployee', () => {

0 commit comments

Comments
 (0)