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 for: IOU has pin option in LHN #20771

Merged
merged 12 commits into from
Jun 22, 2023
7 changes: 7 additions & 0 deletions src/components/LHNOptionsList/OptionRowLHN.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,13 @@ function OptionRowLHN(props) {
* @param {Object} [event] - A press event.
*/
const showPopover = (event) => {
const shouldShowFilter = (contextAction) =>
contextAction.shouldShow(ContextMenuActions.CONTEXT_MENU_TYPES.REPORT, {}, false, props.betas, popoverAnchor, false, props.reportID, optionItem.isPinned);

if (_.filter(ContextMenuActions.default, shouldShowFilter).length === 0) {
return;
}

Copy link
Member

Choose a reason for hiding this comment

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

Is this the best place to do this? IMO, it should be happening inside the ReportActionContextMenu.showContextMenu` function which dictates all opening of context menu everywhere.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@parasharrajat While placing this in ReportActionContextMenu.showContextMenu does seem like the better option, importing ContextMenuActions into ReportActionContextMenu creates dependency cycle issues that would involve refactoring a couple of components.

Copy link
Member

Choose a reason for hiding this comment

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

Oh, I see. What is your plan then?

Copy link
Member

Choose a reason for hiding this comment

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

?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@parasharrajat We could always just pass ContextMenuActions to showContextMenu as a param.

Copy link
Member

Choose a reason for hiding this comment

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

What is preventing us from handling it inside BaseReportActionContextMenu like you proposed?

Copy link
Contributor Author

@Ollyws Ollyws Jun 20, 2023

Choose a reason for hiding this comment

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

@parasharrajat For that we would have to close the menu from the render function which is not good practice and causes a console warning.

#20254 has added mark as unread to the contextmenu, so I'm not sure we need this anymore as the contextmenu will no longer be empty.

ReportActionContextMenu.showContextMenu(
ContextMenuActions.CONTEXT_MENU_TYPES.REPORT,
event,
Expand Down
5 changes: 3 additions & 2 deletions src/libs/ReportUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,11 @@ function isTaskReport(report) {
/**
* Checks if a report is an IOU or expense report.
*
* @param {Object} report
* @param {Object|String} reportOrID
* @returns {Boolean}
*/
function isMoneyRequestReport(report) {
function isMoneyRequestReport(reportOrID) {
const report = _.isObject(reportOrID) ? reportOrID : allReports[`${ONYXKEYS.COLLECTION.REPORT}${reportOrID}`];
return isIOUReport(report) || isExpenseReport(report);
}

Expand Down
6 changes: 4 additions & 2 deletions src/pages/home/report/ContextMenu/ContextMenuActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,8 @@ export default [
{
textTranslateKey: 'common.pin',
icon: Expensicons.Pin,
shouldShow: (type, reportAction, isArchivedRoom, betas, anchor, isChronosReport, reportID, isPinnedChat) => type === CONTEXT_MENU_TYPES.REPORT && !isPinnedChat,
shouldShow: (type, reportAction, isArchivedRoom, betas, anchor, isChronosReport, reportID, isPinnedChat) =>
type === CONTEXT_MENU_TYPES.REPORT && !isPinnedChat && !ReportUtils.isMoneyRequestReport(reportID),
onPress: (closePopover, {reportID}) => {
Report.togglePinnedState(reportID, false);
if (closePopover) {
Expand All @@ -284,7 +285,8 @@ export default [
{
textTranslateKey: 'common.unPin',
icon: Expensicons.Pin,
shouldShow: (type, reportAction, isArchivedRoom, betas, anchor, isChronosReport, reportID, isPinnedChat) => type === CONTEXT_MENU_TYPES.REPORT && isPinnedChat,
shouldShow: (type, reportAction, isArchivedRoom, betas, anchor, isChronosReport, reportID, isPinnedChat) =>
type === CONTEXT_MENU_TYPES.REPORT && isPinnedChat && !ReportUtils.isMoneyRequestReport(reportID),
onPress: (closePopover, {reportID}) => {
Report.togglePinnedState(reportID, true);
if (closePopover) {
Expand Down