Skip to content

Commit

Permalink
Merge pull request #51289 from ishpaul777/revert-49412-feat/49344
Browse files Browse the repository at this point in the history
(cherry picked from commit e4fb650)

(CP triggered by yuwenmemon)
  • Loading branch information
blimpich authored and OSBotify committed Oct 22, 2024
1 parent 696199a commit c19b64d
Show file tree
Hide file tree
Showing 8 changed files with 11 additions and 89 deletions.
1 change: 0 additions & 1 deletion src/libs/API/parameters/RequestMoneyParams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ type RequestMoneyParams = {
transactionThreadReportID: string;
createdReportActionIDForThread: string;
reimbursible?: boolean;
policyID?: string;
};

export default RequestMoneyParams;
62 changes: 0 additions & 62 deletions src/libs/OptionsListUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ import type * as OnyxCommon from '@src/types/onyx/OnyxCommon';
import type DeepValueOf from '@src/types/utils/DeepValueOf';
import {isEmptyObject} from '@src/types/utils/EmptyObject';
import times from '@src/utils/times';
import {createDraftReportForPolicyExpenseChat} from './actions/Report';
import Timing from './actions/Timing';
import filterArrayByMatch from './filterArrayByMatch';
import localeCompare from './LocaleCompare';
Expand All @@ -62,7 +61,6 @@ import * as UserUtils from './UserUtils';

type SearchOption<T> = ReportUtils.OptionData & {
item: T;
isOptimisticReportOption?: boolean;
};

type OptionList = {
Expand Down Expand Up @@ -181,7 +179,6 @@ type GetOptionsConfig = {
includeDomainEmail?: boolean;
action?: IOUAction;
shouldBoldTitleByDefault?: boolean;
includePoliciesWithoutExpenseChats?: boolean;
};

type GetUserToInviteConfig = {
Expand Down Expand Up @@ -243,13 +240,6 @@ Onyx.connect({
},
});

let allReportsDraft: OnyxCollection<Report>;
Onyx.connect({
key: ONYXKEYS.COLLECTION.REPORT_DRAFT,
waitForCollectionCallback: true,
callback: (value) => (allReportsDraft = value),
});

let loginList: OnyxEntry<Login>;
Onyx.connect({
key: ONYXKEYS.LOGIN_LIST,
Expand Down Expand Up @@ -1509,7 +1499,6 @@ function isReportSelected(reportOption: ReportUtils.OptionData, selectedOptions:
function createOptionList(personalDetails: OnyxEntry<PersonalDetailsList>, reports?: OnyxCollection<Report>) {
const reportMapForAccountIDs: Record<number, Report> = {};
const allReportOptions: Array<SearchOption<Report>> = [];
const policyToReportForPolicyExpenseChats: Record<string, Report> = {};

if (reports) {
Object.values(reports).forEach((report) => {
Expand All @@ -1525,10 +1514,6 @@ function createOptionList(personalDetails: OnyxEntry<PersonalDetailsList>, repor
return;
}

if (ReportUtils.isPolicyExpenseChat(report) && report.policyID) {
policyToReportForPolicyExpenseChats[report.policyID] = report;
}

// Save the report in the map if this is a single participant so we can associate the reportID with the
// personal detail option later. Individuals should not be associated with single participant
// policyExpenseChats or chatRooms since those are not people.
Expand All @@ -1543,46 +1528,6 @@ function createOptionList(personalDetails: OnyxEntry<PersonalDetailsList>, repor
});
}

const policiesWithoutExpenseChats = Object.values(policies ?? {}).filter((policy) => {
if (policy?.type === CONST.POLICY.TYPE.PERSONAL) {
return false;
}
return !policyToReportForPolicyExpenseChats[policy?.id ?? ''];
});

// go through each policy and create a optimistic report option for it
if (policiesWithoutExpenseChats && policiesWithoutExpenseChats.length > 0) {
policiesWithoutExpenseChats.forEach((policy) => {
// check for draft report exist in allreportDrafts for the policy
let draftReport = Object.values(allReportsDraft ?? {})?.find((reportDraft) => reportDraft?.policyID === policy?.id);
if (!draftReport) {
draftReport = ReportUtils.buildOptimisticChatReport(
[currentUserAccountID ?? -1],
'',
CONST.REPORT.CHAT_TYPE.POLICY_EXPENSE_CHAT,
policy?.id,
currentUserAccountID,
true,
policy?.name,
undefined,
undefined,
undefined,
undefined,
undefined,
undefined,
undefined,
undefined,
);
createDraftReportForPolicyExpenseChat({...draftReport, isOptimisticReport: true});
}
const accountIDs = ReportUtils.getParticipantsAccountIDsForDisplay(draftReport);
allReportOptions.push({
item: draftReport,
isOptimisticReportOption: true,
...createOption(accountIDs, personalDetails, draftReport, {}),
});
});
}
const allPersonalDetailsOptions = Object.values(personalDetails ?? {}).map((personalDetail) => ({
item: personalDetail,
...createOption([personalDetail?.accountID ?? -1], personalDetails, reportMapForAccountIDs[personalDetail?.accountID ?? -1], {}, {showPersonalDetails: true}),
Expand Down Expand Up @@ -1778,7 +1723,6 @@ function getOptions(
includeDomainEmail = false,
action,
shouldBoldTitleByDefault = true,
includePoliciesWithoutExpenseChats = false,
}: GetOptionsConfig,
): Options {
if (includeCategories) {
Expand Down Expand Up @@ -1843,9 +1787,6 @@ function getOptions(

// Filter out all the reports that shouldn't be displayed
const filteredReportOptions = options.reports.filter((option) => {
if (option.isOptimisticReportOption && !includePoliciesWithoutExpenseChats) {
return;
}
const report = option.item;
const doesReportHaveViolations = ReportUtils.shouldShowViolations(report, transactionViolations);

Expand Down Expand Up @@ -2195,7 +2136,6 @@ type FilteredOptionsParams = {
includeInvoiceRooms?: boolean;
action?: IOUAction;
sortByReportTypeInSearch?: boolean;
includePoliciesWithoutExpenseChats?: boolean;
};

// It is not recommended to pass a search value to getFilteredOptions when passing reports and personalDetails.
Expand Down Expand Up @@ -2237,7 +2177,6 @@ function getFilteredOptions(params: FilteredOptionsParamsWithDefaultSearchValue
includeInvoiceRooms = false,
action,
sortByReportTypeInSearch = false,
includePoliciesWithoutExpenseChats = false,
} = params;
return getOptions(
{reports, personalDetails},
Expand Down Expand Up @@ -2267,7 +2206,6 @@ function getFilteredOptions(params: FilteredOptionsParamsWithDefaultSearchValue
includeInvoiceRooms,
action,
sortByReportTypeInSearch,
includePoliciesWithoutExpenseChats,
},
);
}
Expand Down
2 changes: 0 additions & 2 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,6 @@ type OptimisticChatReport = Pick<
| 'chatReportID'
| 'iouReportID'
| 'isOwnPolicyExpenseChat'
| 'isPolicyExpenseChat'
| 'isPinned'
| 'lastActorAccountID'
| 'lastMessageTranslationKey'
Expand Down Expand Up @@ -5323,7 +5322,6 @@ function buildOptimisticChatReport(
chatType,
isOwnPolicyExpenseChat,
isPinned: isNewlyCreatedWorkspaceChat,
isPolicyExpenseChat: chatType === CONST.REPORT.CHAT_TYPE.POLICY_EXPENSE_CHAT,
lastActorAccountID: 0,
lastMessageTranslationKey: '',
lastMessageHtml: '',
Expand Down
1 change: 0 additions & 1 deletion src/libs/actions/IOU.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3640,7 +3640,6 @@ function requestMoney(
transactionThreadReportID,
createdReportActionIDForThread,
reimbursible,
policyID: policy?.id,
};

// eslint-disable-next-line rulesdir/no-multiple-api-calls
Expand Down
8 changes: 1 addition & 7 deletions src/libs/actions/Report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ import processReportIDDeeplink from '@libs/processReportIDDeeplink';
import * as Pusher from '@libs/Pusher/pusher';
import * as ReportActionsUtils from '@libs/ReportActionsUtils';
import * as ReportConnection from '@libs/ReportConnection';
import type {OptimisticAddCommentReportAction, OptimisticChatReport} from '@libs/ReportUtils';
import type {OptimisticAddCommentReportAction} from '@libs/ReportUtils';
import * as ReportUtils from '@libs/ReportUtils';
import {doesReportBelongToWorkspace} from '@libs/ReportUtils';
import shouldSkipDeepLinkNavigation from '@libs/shouldSkipDeepLinkNavigation';
Expand Down Expand Up @@ -1372,7 +1372,6 @@ function handleReportChanged(report: OnyxEntry<Report>) {
if (report?.reportID && report.preexistingReportID) {
let callback = () => {
Onyx.set(`${ONYXKEYS.COLLECTION.REPORT}${report.reportID}`, null);
Onyx.set(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report.reportID}`, null);
Onyx.set(`${ONYXKEYS.COLLECTION.REPORT_DRAFT_COMMENT}${report.reportID}`, null);
};
// Only re-route them if they are still looking at the optimistically created report
Expand Down Expand Up @@ -4130,10 +4129,6 @@ function markAsManuallyExported(reportID: string, connectionName: ConnectionName
API.write(WRITE_COMMANDS.MARK_AS_EXPORTED, params, {optimisticData, successData, failureData});
}

function createDraftReportForPolicyExpenseChat(draftReport: OptimisticChatReport) {
Onyx.set(`${ONYXKEYS.COLLECTION.REPORT_DRAFT}${draftReport.reportID}`, draftReport);
}

function exportReportToCSV({reportID, transactionIDList}: ExportReportCSVParams, onDownloadFailed: () => void) {
const finalParameters = enhanceParameters(WRITE_COMMANDS.EXPORT_REPORT_TO_CSV, {
reportID,
Expand Down Expand Up @@ -4241,5 +4236,4 @@ export {
updateReportName,
updateRoomVisibility,
updateWriteCapability,
createDraftReportForPolicyExpenseChat,
};
1 change: 0 additions & 1 deletion src/pages/iou/request/MoneyRequestParticipantsSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,6 @@ function MoneyRequestParticipantsSelector({
sortByReportTypeInSearch: isPaidGroupPolicy,
searchValue: '',
maxRecentReportsToShow: 0,
includePoliciesWithoutExpenseChats: true,
});

return optionList;
Expand Down
14 changes: 5 additions & 9 deletions src/pages/iou/request/step/IOURequestStepConfirmation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,17 +55,13 @@ function IOURequestStepConfirmation({
const currentUserPersonalDetails = useCurrentUserPersonalDetails();
const personalDetails = usePersonalDetails() || CONST.EMPTY_OBJECT;

const policyIDForReal = IOU.getIOURequestPolicyID(transaction, reportReal ?? reportDraft);
const policyIDForDraft = IOU.getIOURequestPolicyID(transaction, reportDraft);

const [policyReal] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY}${policyIDForReal}`);
const [policyDraft] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY_DRAFTS}${policyIDForDraft}`);
const [policyCategoriesReal] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY_CATEGORIES}${policyIDForReal}`);
const [policyCategoriesDraft] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY_CATEGORIES}${policyIDForDraft}`);
const [policyTags] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY_TAGS}${policyIDForReal}`);
const [policyDraft] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY_DRAFTS}${IOU.getIOURequestPolicyID(transaction, reportDraft)}`);
const [policyReal] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY}${IOU.getIOURequestPolicyID(transaction, reportReal)}`);
const [policyCategoriesReal] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY_CATEGORIES}${IOU.getIOURequestPolicyID(transaction, reportReal)}`);
const [policyCategoriesDraft] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY_CATEGORIES}${IOU.getIOURequestPolicyID(transaction, reportDraft)}`);
const [policyTags] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY_TAGS}${IOU.getIOURequestPolicyID(transaction, reportReal)}`);

const report = reportReal ?? reportDraft;
// Check if the real policy exists for either reportReal or reportDraft
const policy = policyReal ?? policyDraft;
const policyCategories = policyCategoriesReal ?? policyCategoriesDraft;

Expand Down
11 changes: 5 additions & 6 deletions tests/unit/OptionsListUtilsTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -411,8 +411,7 @@ describe('OptionsListUtils', () => {
expect(results.personalDetails.length).toBe(9);

// Then all of the reports should be shown including the archived rooms.
// - 1 because when we create the option list we also create a workspace chat optimistic options for the old oldot policies or polices with isPolicyExpenseChatEnabled: false, in this case we have a policy "Hero Policy" with isPolicyExpenseChatEnabled: false, More info: https://github.com/Expensify/App/issues/49344
expect(results.recentReports.length).toBe(Object.values(OPTIONS.reports).length - 1);
expect(results.recentReports.length).toBe(Object.values(OPTIONS.reports).length);
});

it('getFilteredOptions()', () => {
Expand Down Expand Up @@ -609,8 +608,8 @@ describe('OptionsListUtils', () => {
// When we pass an empty search value
let results = OptionsListUtils.getShareDestinationOptions(filteredReports, OPTIONS.personalDetails, [], '');

// Then we should expect all the recent reports to show but exclude the archived rooms and workspace policy chat report
expect(results.recentReports.length).toBe(Object.values(OPTIONS.reports).length - 2);
// Then we should expect all the recent reports to show but exclude the archived rooms
expect(results.recentReports.length).toBe(Object.values(OPTIONS.reports).length - 1);

// Filter current REPORTS_WITH_WORKSPACE_ROOMS as we do in the component, before getting share destination options
const filteredReportsWithWorkspaceRooms = Object.values(OPTIONS_WITH_WORKSPACE_ROOM.reports).reduce<OptionsListUtils.OptionList['reports']>((filtered, option) => {
Expand All @@ -625,8 +624,8 @@ describe('OptionsListUtils', () => {
// When we also have a policy to return rooms in the results
results = OptionsListUtils.getShareDestinationOptions(filteredReportsWithWorkspaceRooms, OPTIONS.personalDetails, [], '');
// Then we should expect the DMS, the group chats and the workspace room to show
// We should expect all the recent reports to show, excluding the archived rooms and workspace policy chat report
expect(results.recentReports.length).toBe(Object.values(OPTIONS_WITH_WORKSPACE_ROOM.reports).length - 2);
// We should expect all the recent reports to show, excluding the archived rooms
expect(results.recentReports.length).toBe(Object.values(OPTIONS_WITH_WORKSPACE_ROOM.reports).length - 1);
});

it('getMemberInviteOptions()', () => {
Expand Down

0 comments on commit c19b64d

Please sign in to comment.