Skip to content

Commit

Permalink
Merge pull request #46934 from cretadn22/update-archive-feature
Browse files Browse the repository at this point in the history
Update archive feature
  • Loading branch information
srikarparsi authored Sep 17, 2024
2 parents 539327d + 96c5cd2 commit 14b99ca
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 20 deletions.
18 changes: 8 additions & 10 deletions src/libs/OptionsListUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -595,9 +595,8 @@ function getLastMessageTextForReport(report: OnyxEntry<Report>, lastActorDetails
// some types of actions are filtered out for lastReportAction, in some cases we need to check the actual last action
const lastOriginalReportAction = lastReportActions[reportID] ?? null;
let lastMessageTextFromReport = '';
const reportNameValuePairs = ReportUtils.getReportNameValuePairs(report?.reportID);

if (ReportUtils.isArchivedRoom(report, reportNameValuePairs)) {
if (report?.private_isArchived) {
const archiveReason =
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
(ReportActionUtils.isClosedAction(lastOriginalReportAction) && ReportActionUtils.getOriginalMessage(lastOriginalReportAction)?.reason) || CONST.REPORT.ARCHIVE_REASON.DEFAULT;
Expand Down Expand Up @@ -712,7 +711,6 @@ function createOption(
isIOUReportOwner: null,
iouReportAmount: 0,
isChatRoom: false,
isArchivedRoom: false,
shouldShowSubscript: false,
isPolicyExpenseChat: false,
isOwnPolicyExpenseChat: false,
Expand All @@ -730,11 +728,11 @@ function createOption(
let reportName;
result.participantsList = personalDetailList;
result.isOptimisticPersonalDetail = personalDetail?.isOptimisticPersonalDetail;
const reportNameValuePairs = ReportUtils.getReportNameValuePairs(report?.reportID);
if (report) {
result.isChatRoom = ReportUtils.isChatRoom(report);
result.isDefaultRoom = ReportUtils.isDefaultRoom(report);
result.isArchivedRoom = ReportUtils.isArchivedRoom(report, reportNameValuePairs);
// eslint-disable-next-line @typescript-eslint/naming-convention
result.private_isArchived = report.private_isArchived;
result.isExpenseReport = ReportUtils.isExpenseReport(report);
result.isInvoiceRoom = ReportUtils.isInvoiceRoom(report);
result.isMoneyRequestReport = ReportUtils.isMoneyRequestReport(report);
Expand Down Expand Up @@ -1588,7 +1586,7 @@ function orderOptions(options: ReportUtils.OptionData[], searchValue: string | u
if (preferChatroomsOverThreads && option.isThread) {
return 4;
}
if (!!option.isChatRoom || option.isArchivedRoom) {
if (!!option.isChatRoom || option.private_isArchived) {
return 3;
}
if (!option.login) {
Expand Down Expand Up @@ -1833,7 +1831,7 @@ function getOptions(
// - All archived reports should remain at the bottom
const orderedReportOptions = lodashSortBy(filteredReportOptions, (option) => {
const report = option.item;
if (option.isArchivedRoom) {
if (option.private_isArchived) {
return CONST.DATE.UNIX_EPOCH;
}

Expand Down Expand Up @@ -1942,10 +1940,10 @@ function getOptions(
}

const isCurrentUserOwnedPolicyExpenseChatThatCouldShow =
reportOption.isPolicyExpenseChat && reportOption.ownerAccountID === currentUserAccountID && includeOwnedWorkspaceChats && !reportOption.isArchivedRoom;
reportOption.isPolicyExpenseChat && reportOption.ownerAccountID === currentUserAccountID && includeOwnedWorkspaceChats && !reportOption.private_isArchived;

const shouldShowInvoiceRoom =
includeInvoiceRooms && ReportUtils.isInvoiceRoom(reportOption.item) && ReportUtils.isPolicyAdmin(reportOption.policyID ?? '', policies) && !reportOption.isArchivedRoom;
includeInvoiceRooms && ReportUtils.isInvoiceRoom(reportOption.item) && ReportUtils.isPolicyAdmin(reportOption.policyID ?? '', policies) && !reportOption.private_isArchived;
// TODO: Uncomment the following line when the invoices screen is ready - https://github.com/Expensify/App/issues/45175.
// && PolicyUtils.canSendInvoiceFromWorkspace(reportOption.policyID);

Expand Down Expand Up @@ -2305,7 +2303,7 @@ function getHeaderMessageForNonUserList(hasSelectableOptions: boolean, searchVal
* Helper method to check whether an option can show tooltip or not
*/
function shouldOptionShowTooltip(option: ReportUtils.OptionData): boolean {
return (!option.isChatRoom || !!option.isThread) && !option.isArchivedRoom;
return (!option.isChatRoom || !!option.isThread) && !option.private_isArchived;
}

/**
Expand Down
1 change: 0 additions & 1 deletion src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,6 @@ type OptionData = {
keyForList?: string;
searchText?: string;
isIOUReportOwner?: boolean | null;
isArchivedRoom?: boolean | null;
shouldShowSubscript?: boolean | null;
isPolicyExpenseChat?: boolean | null;
isMoneyRequestReport?: boolean | null;
Expand Down
13 changes: 6 additions & 7 deletions src/libs/SidebarUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,8 @@ function getOptionData({
hasParentAccess: undefined,
isIOUReportOwner: null,
isChatRoom: false,
isArchivedRoom: false,
// eslint-disable-next-line @typescript-eslint/naming-convention
private_isArchived: undefined,
shouldShowSubscript: false,
isPolicyExpenseChat: false,
isMoneyRequestReport: false,
Expand All @@ -307,8 +308,8 @@ function getOptionData({
result.isTaskReport = ReportUtils.isTaskReport(report);
result.isInvoiceReport = ReportUtils.isInvoiceReport(report);
result.parentReportAction = parentReportAction;
const reportNameValuePairs = ReportUtils.getReportNameValuePairs(report?.reportID);
result.isArchivedRoom = ReportUtils.isArchivedRoom(report, reportNameValuePairs);
// eslint-disable-next-line @typescript-eslint/naming-convention
result.private_isArchived = report?.private_isArchived;
result.isPolicyExpenseChat = ReportUtils.isPolicyExpenseChat(report);
result.isExpenseRequest = ReportUtils.isExpenseRequest(report);
result.isMoneyRequestReport = ReportUtils.isMoneyRequestReport(report);
Expand Down Expand Up @@ -399,8 +400,7 @@ function getOptionData({

const isThreadMessage =
ReportUtils.isThread(report) && lastAction?.actionName === CONST.REPORT.ACTIONS.TYPE.ADD_COMMENT && lastAction?.pendingAction !== CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE;

if ((result.isChatRoom || result.isPolicyExpenseChat || result.isThread || result.isTaskReport || isThreadMessage) && !result.isArchivedRoom) {
if ((result.isChatRoom || result.isPolicyExpenseChat || result.isThread || result.isTaskReport || isThreadMessage) && !result.private_isArchived) {
const lastActionName = lastAction?.actionName ?? report.lastActionType;

if (ReportActionsUtils.isRenamedAction(lastAction)) {
Expand Down Expand Up @@ -577,8 +577,7 @@ function getRoomWelcomeMessage(report: OnyxEntry<Report>): WelcomeMessage {
return welcomeMessage;
}

const reportNameValuePairs = ReportUtils.getReportNameValuePairs(report?.reportID);
if (ReportUtils.isArchivedRoom(report, reportNameValuePairs)) {
if (report?.private_isArchived) {
welcomeMessage.phrase1 = Localize.translateLocal('reportActionsView.beginningOfArchivedRoomPartOne');
welcomeMessage.phrase2 = Localize.translateLocal('reportActionsView.beginningOfArchivedRoomPartTwo');
} else if (ReportUtils.isDomainRoom(report)) {
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/OptionsListUtilsTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2641,7 +2641,7 @@ describe('OptionsListUtils', () => {
const filteredOptions = OptionsListUtils.filterOptions(options, searchText);

expect(filteredOptions.recentReports.length).toBe(1);
expect(filteredOptions.recentReports[0].isArchivedRoom).toBe(true);
expect(!!filteredOptions.recentReports[0].private_isArchived).toBe(true);
});

it('should filter options by email if dot is skipped in the email', () => {
Expand Down
3 changes: 2 additions & 1 deletion tests/utils/collections/optionData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ export default function createRandomOptionData(index: number): OptionData {
policyName: randWord(),
policyID: `policy_${index}`,
accountID: randNumber(),
isArchivedRoom: randBoolean(),
// eslint-disable-next-line @typescript-eslint/naming-convention
private_isArchived: new Date().toISOString(),
isPolicyExpenseChat: randBoolean(),
chatType: rand(Object.values(CONST.REPORT.CHAT_TYPE)),
hasOutstandingChildRequest: randBoolean(),
Expand Down

0 comments on commit 14b99ca

Please sign in to comment.