Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update archive feature #46934

Merged
merged 24 commits into from
Sep 17, 2024
Merged
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
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 @@ -425,7 +425,6 @@
keyForList?: string;
searchText?: string;
isIOUReportOwner?: boolean | null;
isArchivedRoom?: boolean | null;
shouldShowSubscript?: boolean | null;
isPolicyExpenseChat?: boolean | null;
isMoneyRequestReport?: boolean | null;
Expand Down Expand Up @@ -1536,7 +1535,7 @@
/**
* A Track Expense Report is a thread where the parent the parentReportAction is a transaction, and
* parentReportAction has type of track.
*/

Check failure on line 1538 in src/libs/ReportUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

'getParentReportAction' is deprecated. Use Onyx.connect() or withOnyx() instead
function isTrackExpenseReport(report: OnyxInputOrEntry<Report>): boolean {
if (isThread(report)) {
const parentReportAction = ReportActionsUtils.getParentReportAction(report);
Expand All @@ -1549,7 +1548,7 @@
* Checks if a report is an IOU or expense request.
*/
function isMoneyRequest(reportOrID: OnyxEntry<Report> | string): boolean {
const report = typeof reportOrID === 'string' ? ReportConnection.getAllReports()?.[`${ONYXKEYS.COLLECTION.REPORT}${reportOrID}`] ?? null : reportOrID;

Check failure on line 1551 in src/libs/ReportUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

'getParentReportAction' is deprecated. Use Onyx.connect() or withOnyx() instead
return isIOURequest(report) || isExpenseRequest(report);
}

Expand All @@ -1562,7 +1561,7 @@
}

/**
* Checks if a report contains only Non-Reimbursable transactions

Check failure on line 1564 in src/libs/ReportUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

'getParentReportAction' is deprecated. Use Onyx.connect() or withOnyx() instead
*/
function hasOnlyNonReimbursableTransactions(iouReportID: string | undefined): boolean {
if (!iouReportID) {
Expand Down Expand Up @@ -2211,7 +2210,7 @@
const parentReportAction = ReportActionsUtils.getParentReportAction(report);

const actorAccountID = getReportActionActorAccountID(parentReportAction, report);
const actorDisplayName = PersonalDetailsUtils.getDisplayNameOrDefault(allPersonalDetails?.[actorAccountID ?? -1], '', false);

Check failure on line 2213 in src/libs/ReportUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

'getParentReportAction' is deprecated. Use Onyx.connect() or withOnyx() instead
const actorIcon = {
id: actorAccountID,
source: personalDetails?.[actorAccountID ?? -1]?.avatar ?? FallbackAvatar,
Expand All @@ -2224,7 +2223,7 @@
const workspaceIcon = getWorkspaceIcon(report, policy);
return [actorIcon, workspaceIcon];
}
return [actorIcon];

Check failure on line 2226 in src/libs/ReportUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

'getParentReportAction' is deprecated. Use Onyx.connect() or withOnyx() instead
}
if (isTaskReport(report)) {
const ownerIcon = {
Expand Down Expand Up @@ -3105,7 +3104,7 @@
const isScanning = TransactionUtils.hasReceipt(transaction) && TransactionUtils.isReceiptBeingScanned(transaction);
const isClosed = isClosedReport(moneyRequestReport);

const canModifyStatus = !isTrackExpenseMoneyReport && (isAdmin || isActionOwner || isApprover);

Check failure on line 3107 in src/libs/ReportUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

'getParentReportAction' is deprecated. Use Onyx.connect() or withOnyx() instead
const canModifyUnholdStatus = !isTrackExpenseMoneyReport && (isAdmin || (isActionOwner && isHoldActionCreator) || isApprover);
const isDeletedParentAction = isEmptyObject(parentReportAction) || ReportActionsUtils.isDeletedAction(parentReportAction);

Expand Down Expand Up @@ -3712,7 +3711,7 @@
}

if (isChatThread(report)) {
if (!isEmptyObject(parentReportAction) && ReportActionsUtils.isTransactionThread(parentReportAction)) {

Check failure on line 3714 in src/libs/ReportUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

'getParentReportAction' is deprecated. Use Onyx.connect() or withOnyx() instead
formattedName = getTransactionReportName(parentReportAction);
if (isArchivedRoom(report, getReportNameValuePairs(report?.reportID))) {
formattedName += ` (${Localize.translateLocal('common.archived')})`;
Expand Down Expand Up @@ -4248,7 +4247,7 @@
return reportAction;
}

/**

Check failure on line 4250 in src/libs/ReportUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

'originalMessage' is deprecated. Used in old report actions before migration. Replaced by using getOriginalMessage function
* Builds an optimistic IOU report with a randomly generated reportID
*
* @param payeeAccountID - AccountID of the person generating the IOU.
Expand Down Expand Up @@ -5989,7 +5988,7 @@
!isGroupChat(report))
) {
return false;
}

Check failure on line 5991 in src/libs/ReportUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

'getParentReportAction' is deprecated. Use Onyx.connect() or withOnyx() instead

// We used to use the system DM for A/B testing onboarding tasks, but now only create them in the Concierge chat. We
// still need to allow existing users who have tasks in the system DM to see them, but otherwise we don't need to
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,
cretadn22 marked this conversation as resolved.
Show resolved Hide resolved
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 @@ -575,8 +575,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);
cretadn22 marked this conversation as resolved.
Show resolved Hide resolved
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
Loading