Skip to content

Commit 84ce63d

Browse files
authored
Merge pull request Expensify#63680 from Expensify/tgolen-remove-rnvps-13
Remove a call to getReportNameValuePairs when checking if a chat room description can be edited
2 parents 3797fbd + b68312e commit 84ce63d

4 files changed

Lines changed: 44 additions & 10 deletions

File tree

src/libs/OptionsListUtils.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,6 @@ import {
104104
getRejectedReportMessage,
105105
getReportLastMessage,
106106
getReportName,
107-
getReportNameValuePairs,
108107
getReportNotificationPreference,
109108
getReportOrDraftReport,
110109
getReportParticipantsTitle,
@@ -1482,10 +1481,7 @@ function getValidReports(reports: OptionList['reports'], config: GetValidReports
14821481
includeSelfDM,
14831482
login: option.login,
14841483
includeDomainEmail,
1485-
1486-
// This will get removed as part of https://github.com/Expensify/App/issues/59961
1487-
// eslint-disable-next-line deprecation/deprecation
1488-
isReportArchived: isArchivedReport(getReportNameValuePairs(report?.reportID)),
1484+
isReportArchived: !!option.private_isArchived,
14891485
});
14901486

14911487
if (!shouldBeInOptionList) {

src/libs/ReportUtils.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8967,12 +8967,10 @@ function getRoom(type: ValueOf<typeof CONST.REPORT.CHAT_TYPE>, policyID: string)
89678967
/**
89688968
* We only want policy members who are members of the report to be able to modify the report description, but not in thread chat.
89698969
*/
8970-
function canEditReportDescription(report: OnyxEntry<Report>, policy: OnyxEntry<Policy>): boolean {
8970+
function canEditReportDescription(report: OnyxEntry<Report>, policy: OnyxEntry<Policy>, isReportArchived = false): boolean {
89718971
return (
89728972
!isMoneyRequestReport(report) &&
8973-
// This will get removed as part of https://github.com/Expensify/App/issues/59961
8974-
// eslint-disable-next-line deprecation/deprecation
8975-
!isArchivedReport(getReportNameValuePairs(report?.reportID)) &&
8973+
!isReportArchived &&
89768974
isChatRoom(report) &&
89778975
!isChatThread(report) &&
89788976
!isEmpty(policy) &&

src/pages/RoomDescriptionPage.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import Text from '@components/Text';
1313
import TextInput from '@components/TextInput';
1414
import type {BaseTextInputRef} from '@components/TextInput/BaseTextInput/types';
1515
import useLocalize from '@hooks/useLocalize';
16+
import useReportIsArchived from '@hooks/useReportIsArchived';
1617
import useThemeStyles from '@hooks/useThemeStyles';
1718
import Navigation from '@libs/Navigation/Navigation';
1819
import type {PlatformStackRouteProp} from '@libs/Navigation/PlatformStackNavigation/types';
@@ -47,6 +48,7 @@ function RoomDescriptionPage({report, policies}: RoomDescriptionPageProps) {
4748
const focusTimeoutRef = useRef<ReturnType<typeof setTimeout> | null>(null);
4849
const {translate} = useLocalize();
4950
const policy = policies?.[`${ONYXKEYS.COLLECTION.POLICY}${report?.policyID}`];
51+
const reportIsArchived = useReportIsArchived(report?.reportID);
5052

5153
const handleReportDescriptionChange = useCallback((value: string) => {
5254
setDescription(value);
@@ -94,7 +96,7 @@ function RoomDescriptionPage({report, policies}: RoomDescriptionPageProps) {
9496
}, []),
9597
);
9698

97-
const canEdit = canEditReportDescription(report, policy);
99+
const canEdit = canEditReportDescription(report, policy, reportIsArchived);
98100
return (
99101
<ScreenWrapper
100102
shouldEnableMaxHeight

tests/unit/ReportUtilsTest.ts

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import {
2121
canAddTransaction,
2222
canDeleteReportAction,
2323
canDeleteTransaction,
24+
canEditReportDescription,
2425
canEditWriteCapability,
2526
canHoldUnholdReportAction,
2627
findLastAccessedReport,
@@ -3083,4 +3084,41 @@ describe('ReportUtils', () => {
30833084
expect(result).toBe(null);
30843085
});
30853086
});
3087+
3088+
describe('canEditReportDescription', () => {
3089+
it('should return true for a non-archived policy room', async () => {
3090+
// Given a non-archived policy room
3091+
const report: Report = {
3092+
...createRandomReport(40001),
3093+
chatType: CONST.REPORT.CHAT_TYPE.POLICY_ROOM,
3094+
participants: buildParticipantsFromAccountIDs([currentUserAccountID, 1]),
3095+
};
3096+
await Onyx.set(`${ONYXKEYS.COLLECTION.REPORT}${report.reportID}`, report);
3097+
3098+
// When it's checked if the description can be edited
3099+
const {result: isReportArchived} = renderHook(() => useReportIsArchived(report?.reportID));
3100+
const result = canEditReportDescription(report, policy, isReportArchived.current);
3101+
3102+
// Then it can be edited
3103+
expect(result).toBeTruthy();
3104+
});
3105+
3106+
it('should return false for an archived policy room', async () => {
3107+
// Given an archived policy room
3108+
const report: Report = {
3109+
...createRandomReport(40002),
3110+
chatType: CONST.REPORT.CHAT_TYPE.POLICY_ROOM,
3111+
participants: buildParticipantsFromAccountIDs([currentUserAccountID, 1]),
3112+
};
3113+
await Onyx.set(`${ONYXKEYS.COLLECTION.REPORT}${report.reportID}`, report);
3114+
await Onyx.set(`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${report.reportID}`, {private_isArchived: DateUtils.getDBTime()});
3115+
3116+
// When it's checked if the description can be edited
3117+
const {result: isReportArchived} = renderHook(() => useReportIsArchived(report?.reportID));
3118+
const result = canEditReportDescription(report, policy, isReportArchived.current);
3119+
3120+
// Then it cannot be edited
3121+
expect(result).toBeFalsy();
3122+
});
3123+
});
30863124
});

0 commit comments

Comments
 (0)