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

fix: Deleted room is displayed in the 'Assign task' #51625

Merged
merged 18 commits into from
Nov 15, 2024
Merged
25 changes: 25 additions & 0 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7945,6 +7945,30 @@ function getOptimisticDataForParentReportAction(reportID: string, lastVisibleAct
});
}

function getQuickActionDetails(
quickActionReport: Report,
personalDetails: PersonalDetailsList | undefined,
policyChatForActivePolicy: Report | undefined,
reportNameValuePairs: ReportNameValuePairs,
): {quickActionAvatars: Icon[]; hideQABSubtitle: boolean} {
const isValidQuickActionReport = !(isEmptyObject(quickActionReport) || isArchivedRoom(quickActionReport, reportNameValuePairs));
let hideQABSubtitle = false;
let quickActionAvatars: Icon[] = [];
if (isValidQuickActionReport) {
const avatars = getIcons(quickActionReport, personalDetails);
quickActionAvatars = avatars.length <= 1 || isPolicyExpenseChat(quickActionReport) ? avatars : avatars.filter((avatar) => avatar.id !== currentUserAccountID);
} else {
hideQABSubtitle = true;
}
if (!isEmptyObject(policyChatForActivePolicy)) {
quickActionAvatars = getIcons(policyChatForActivePolicy, personalDetails);
}
return {
quickActionAvatars,
hideQABSubtitle,
};
}

function canBeAutoReimbursed(report: OnyxInputOrEntry<Report>, policy: OnyxInputOrEntry<Policy>): boolean {
if (isEmptyObject(policy)) {
return false;
Expand Down Expand Up @@ -8567,6 +8591,7 @@ export {
getInvoicePayerName,
getInvoicesChatName,
getPayeeName,
getQuickActionDetails,
hasActionsWithErrors,
hasAutomatedExpensifyAccountIDs,
hasExpensifyGuidesEmails,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ function FloatingActionButtonAndPopover({onHideCreateMenu, onShowCreateMenu}: Fl

const {canUseSpotnanaTravel, canUseCombinedTrackSubmit} = usePermissions();
const canSendInvoice = useMemo(() => PolicyUtils.canSendInvoice(allPolicies as OnyxCollection<OnyxTypes.Policy>, session?.email), [allPolicies, session?.email]);
const isValidReport = !(isEmptyObject(quickActionReport) || ReportUtils.isArchivedRoom(quickActionReport, reportNameValuePairs));
const {environment} = useEnvironment();
const [introSelected] = useOnyx(ONYXKEYS.NVP_INTRO_SELECTED);
const navatticURL = getNavatticURL(environment, introSelected?.choice);
Expand All @@ -202,7 +203,7 @@ function FloatingActionButtonAndPopover({onHideCreateMenu, onShowCreateMenu}: Fl
);

const quickActionAvatars = useMemo(() => {
if (quickActionReport) {
if (isValidReport) {
const avatars = ReportUtils.getIcons(quickActionReport, personalDetails);
return avatars.length <= 1 || ReportUtils.isPolicyExpenseChat(quickActionReport) ? avatars : avatars.filter((avatar) => avatar.id !== session?.accountID);
}
Expand Down Expand Up @@ -237,15 +238,15 @@ function FloatingActionButtonAndPopover({onHideCreateMenu, onShowCreateMenu}: Fl
}, [quickAction, translate, quickActionAvatars, quickActionReport]);

const hideQABSubtitle = useMemo(() => {
if (isEmptyObject(quickActionReport)) {
if (!isValidReport) {
return true;
}
if (quickActionAvatars.length === 0) {
return false;
}
const displayName = personalDetails?.[quickActionAvatars.at(0)?.id ?? -1]?.firstName ?? '';
return quickAction?.action === CONST.QUICK_ACTIONS.SEND_MONEY && displayName.length === 0;
}, [personalDetails, quickActionReport, quickAction?.action, quickActionAvatars]);
}, [isValidReport, quickActionAvatars, personalDetails, quickAction?.action]);

const selectOption = useCallback(
(onSelected: () => void, shouldRestrictAction: boolean) => {
Expand All @@ -259,7 +260,6 @@ function FloatingActionButtonAndPopover({onHideCreateMenu, onShowCreateMenu}: Fl
);

const navigateToQuickAction = useCallback(() => {
const isValidReport = !(isEmptyObject(quickActionReport) || ReportUtils.isArchivedRoom(quickActionReport, reportNameValuePairs));
const quickActionReportID = isValidReport ? quickActionReport?.reportID ?? '-1' : ReportUtils.generateReportID();

switch (quickAction?.action) {
Expand Down Expand Up @@ -288,7 +288,7 @@ function FloatingActionButtonAndPopover({onHideCreateMenu, onShowCreateMenu}: Fl
break;
default:
}
}, [quickAction, quickActionReport, reportNameValuePairs, selectOption]);
}, [isValidReport, quickAction?.action, quickAction?.targetAccountID, quickActionReport?.reportID, selectOption]);

/**
* Check if LHN status changed from active to inactive.
Expand Down Expand Up @@ -476,7 +476,6 @@ function FloatingActionButtonAndPopover({onHideCreateMenu, onShowCreateMenu}: Fl
onSelected: () =>
interceptAnonymousUser(() => {
selectOption(() => {
const isValidReport = !(isEmptyObject(policyChatForActivePolicy) || ReportUtils.isArchivedRoom(policyChatForActivePolicy, reportNameValuePairs));
const quickActionReportID = isValidReport ? policyChatForActivePolicy?.reportID ?? '-1' : ReportUtils.generateReportID();
IOU.startMoneyRequest(CONST.IOU.TYPE.SUBMIT, quickActionReportID ?? '-1', CONST.IOU.REQUEST_TYPE.SCAN, true);
}, true);
Expand All @@ -503,7 +502,7 @@ function FloatingActionButtonAndPopover({onHideCreateMenu, onShowCreateMenu}: Fl
quickActionReport,
navigateToQuickAction,
selectOption,
reportNameValuePairs,
isValidReport,
]);

return (
Expand Down
22 changes: 22 additions & 0 deletions tests/unit/ReportUtilsTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -975,6 +975,28 @@ describe('ReportUtils', () => {
});
});

describe('getQuickActionDetails', () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for adding this test!

Can you please follow this format to add a little bit of context and documentation to the test?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tgolen i updated

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, close enough, but that format is meant to have each comment start with literal "Given", "When" and "Then" words :D

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Noted for the feature.

it('if the report is archived, the quick action will hide the subtitle and avatar', () => {
// Create a fake archived report as quick action report
const archivedReport: Report = {
...LHNTestUtils.getFakeReport(),
reportID: '1',
private_isArchived: DateUtils.getDBTime(),
};
const reportNameValuePairs = {
type: 'chat',
private_isArchived: true,
};

// Get the quick action detail
const quickActionDetails = ReportUtils.getQuickActionDetails(archivedReport, undefined, undefined, reportNameValuePairs);

// Expect the quickActionAvatars is empty array and hideQABSubtitle is true since the quick action report is archived
expect(quickActionDetails.quickActionAvatars.length).toEqual(0);
expect(quickActionDetails.hideQABSubtitle).toEqual(true);
});
});

describe('getChatByParticipants', () => {
const userAccountID = 1;
const userAccountID2 = 2;
Expand Down
Loading