Skip to content

Commit fa05898

Browse files
committed
fix: gate getModerationFlagState to ADD_COMMENT actions
1 parent 9e27261 commit fa05898

3 files changed

Lines changed: 13 additions & 2 deletions

File tree

src/libs/ReportActionsUtils.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,10 @@ function isPendingRemove(reportAction: OnyxInputOrEntry<ReportAction>): boolean
265265
* Used by leaves that previously received the equivalent values as props from PureReportActionItem.
266266
*/
267267
function getModerationFlagState(reportAction: OnyxInputOrEntry<ReportAction>): {latestDecision: DecisionName | undefined; hasBeenFlagged: boolean} {
268+
// Moderation only applies to ADD_COMMENT actions
269+
if (reportAction?.actionName !== CONST.REPORT.ACTIONS.TYPE.ADD_COMMENT) {
270+
return {latestDecision: undefined, hasBeenFlagged: false};
271+
}
268272
const latestDecision = getReportActionMessage(reportAction)?.moderationDecision?.decision;
269273
const hasBeenFlagged =
270274
!!latestDecision &&

src/pages/inbox/report/ReportActionItemSingle.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,7 @@ function ReportActionItemSingle({
7272
isHovered = false,
7373
isActive = false,
7474
}: ReportActionItemSingleProps) {
75-
const {latestDecision, hasBeenFlagged} =
76-
action?.actionName === CONST.REPORT.ACTIONS.TYPE.ADD_COMMENT ? getModerationFlagState(action) : {latestDecision: undefined, hasBeenFlagged: false};
75+
const {latestDecision, hasBeenFlagged} = getModerationFlagState(action);
7776
const theme = useTheme();
7877
const styles = useThemeStyles();
7978
const StyleUtils = useStyleUtils();

tests/unit/ReportActionsUtilsTest.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5173,5 +5173,13 @@ describe('ReportActionsUtils', () => {
51735173
hasBeenFlagged: true,
51745174
});
51755175
});
5176+
5177+
it('returns the safe default for non-ADD_COMMENT actions even when the message carries a flagged decision', () => {
5178+
const action = {
5179+
...makeActionWithDecision(CONST.MODERATION.MODERATOR_DECISION_HIDDEN),
5180+
actionName: CONST.REPORT.ACTIONS.TYPE.IOU,
5181+
} as ReportAction;
5182+
expect(getModerationFlagState(action)).toEqual({latestDecision: undefined, hasBeenFlagged: false});
5183+
});
51765184
});
51775185
});

0 commit comments

Comments
 (0)