Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import React, {useState} from 'react';

import type {ReportActionsListProps} from './types';

import filterHiddenSupportTicketSurveys from './filterHiddenSupportTicketSurveys';
import useReportActionsListData from './useReportActionsListData';
import useReportActionsListRenderItem from './useReportActionsListRenderItem';
import useReportActionsListScroll from './useReportActionsListScroll';
Expand All @@ -66,6 +67,7 @@ function ReportActionsListContent({reportID, onLayout}: ReportActionsListProps)
hasNewerActions,
oldestUnreadReportAction,
transactionThreadReport,
sortedAllReportActions,
sortedReportActions: unfilteredReportActions,
sortedVisibleReportActions: unfilteredVisibleReportActions,
isConciergeHiddenHistory,
Expand All @@ -74,8 +76,8 @@ function ReportActionsListContent({reportID, onLayout}: ReportActionsListProps)
} = useReportActionsListState();

// Remove rows hidden by the renderer before calculating summary counts, headers, and scroll positions.
const sortedReportActions = report?.isWaitingOnBankAccount ? unfilteredReportActions.filter((action) => !shouldHidePayAction(action, true)) : unfilteredReportActions;
const sortedVisibleReportActions = report?.isWaitingOnBankAccount
const paymentFilteredReportActions = report?.isWaitingOnBankAccount ? unfilteredReportActions.filter((action) => !shouldHidePayAction(action, true)) : unfilteredReportActions;
const paymentFilteredVisibleReportActions = report?.isWaitingOnBankAccount
? unfilteredVisibleReportActions.filter((action) => !shouldHidePayAction(action, true))
: unfilteredVisibleReportActions;

Expand All @@ -95,6 +97,19 @@ function ReportActionsListContent({reportID, onLayout}: ReportActionsListProps)
useRetireMerchantRuleSuggestionOnLeave(reportID);

const [reportNameValuePairs] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${reportID}`);
// Hidden surveys must not become unread targets that have no rendered row.
const sortedReportActions = filterHiddenSupportTicketSurveys({
reportActions: paymentFilteredReportActions,
sortedAllReportActions,
report,
reportNameValuePairs,
});
const sortedVisibleReportActions = filterHiddenSupportTicketSurveys({
reportActions: paymentFilteredVisibleReportActions,
sortedAllReportActions,
Comment thread
roryabraham marked this conversation as resolved.
Resolved
report,
reportNameValuePairs,
});
const isReportArchived = !!isArchivedReport(reportNameValuePairs);
const [isTrackIntentUser] = useOnyx(ONYXKEYS.NVP_INTRO_SELECTED, {selector: isTrackIntentUserSelector});
const [policy] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY}${getNonEmptyStringOnyxID(report?.policyID)}`);
Expand Down Expand Up @@ -139,7 +154,6 @@ function ReportActionsListContent({reportID, onLayout}: ReportActionsListProps)

const reportActionsListData = useReportActionsListData({
sortedVisibleReportActions,
reportNameValuePairs,
sessionStartTime,
linkedReportActionID,
unreadMarkerReportActionID,
Expand All @@ -149,7 +163,8 @@ function ReportActionsListContent({reportID, onLayout}: ReportActionsListProps)
const {listID, listProps, shouldBeAlignedToTop, isFloatingMessageCounterVisible, isActionBadgeAboveViewport, scrollToBottomAndMarkReportAsRead, scrollToActionBadgeTarget} =
useReportActionsListScroll({
reportID,
sortedVisibleReportActions,
// Hidden surveys still prove that the selected page contains the newest action.
sortedVisibleReportActions: paymentFilteredVisibleReportActions,
renderedVisibleReportActions: listData,
reportActionIDToDisplayIndex,
hasScrolledOverThreshold,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/** Keeps survey eligibility consistent between unread selection and rendered rows. */
import {isResolvedSupportTicket, isSupportTicket} from '@libs/ReportUtils';

import CONST from '@src/CONST';
import type {Report, ReportAction, ReportNameValuePairs} from '@src/types/onyx';

import type {OnyxEntry} from 'react-native-onyx';

type FilterHiddenSupportTicketSurveysParams = {
reportActions: ReportAction[];
sortedAllReportActions: ReportAction[] | undefined;
report: OnyxEntry<Report>;
reportNameValuePairs: OnyxEntry<ReportNameValuePairs>;
};

function filterHiddenSupportTicketSurveys({reportActions, sortedAllReportActions, report, reportNameValuePairs}: FilterHiddenSupportTicketSurveysParams): ReportAction[] {
if (!isSupportTicket(report)) {
return reportActions;
}

const shouldHideAllSurveys = !isResolvedSupportTicket(report) || !!reportNameValuePairs?.reopenedAsReportID;
const latestResolution = shouldHideAllSurveys ? undefined : sortedAllReportActions?.find((action) => action.actionName === CONST.REPORT.ACTIONS.TYPE.CLOSED);
const latestSurvey = latestResolution
? sortedAllReportActions?.find((action) => action.actionName === CONST.REPORT.ACTIONS.TYPE.SUPPORT_SURVEY && action.created >= latestResolution.created)
: undefined;
const shouldHideSurvey = (action: ReportAction) =>
action.actionName === CONST.REPORT.ACTIONS.TYPE.SUPPORT_SURVEY && (shouldHideAllSurveys || action.reportActionID !== latestSurvey?.reportActionID);

return reportActions.some(shouldHideSurvey) ? reportActions.filter((action) => !shouldHideSurvey(action)) : reportActions;
}

export default filterHiddenSupportTicketSurveys;
4 changes: 2 additions & 2 deletions src/pages/inbox/report/ReportActionsList/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ type ReportActionsListProps = {

type UseReportActionsListDataParams = {
sortedVisibleReportActions: OnyxTypes.ReportAction[];
reportNameValuePairs: OnyxEntry<OnyxTypes.ReportNameValuePairs>;
sessionStartTime: string | null;
linkedReportActionID: string | undefined;
unreadMarkerReportActionID: string | null;
Expand Down Expand Up @@ -57,8 +56,9 @@ type UseReportActionsListRenderItemParams = Pick<
| 'draftReportActionID'
| 'isDraftPendingCompletion'
> &
Pick<UseReportActionsListDataParams, 'reportNameValuePairs' | 'linkedReportActionID' | 'unreadMarkerReportActionID'> &
Pick<UseReportActionsListDataParams, 'linkedReportActionID' | 'unreadMarkerReportActionID'> &
Pick<ReportActionsListProps, 'reportID'> & {
reportNameValuePairs: OnyxEntry<OnyxTypes.ReportNameValuePairs>;
isReportArchived: boolean;
isOffline: boolean;
sortedReportActions: OnyxTypes.ReportAction[];
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {getReportActionMessage, isTransactionThread} from '@libs/ReportActionsUtils';
import {isExpenseReport, isIOUReport, isInvoiceReport, isResolvedSupportTicket, isSupportTicket} from '@libs/ReportUtils';
import {isExpenseReport, isIOUReport, isInvoiceReport} from '@libs/ReportUtils';

import {useConciergeDraft, useConciergeDraftActions} from '@pages/inbox/ConciergeDraftContext';
import {useReportActionsListState} from '@pages/inbox/report/ReportActionsListContext';
Expand All @@ -13,8 +13,8 @@ import type {UseReportActionsListDataParams} from './types';

import getReportActionsWithStreamedReply from './getReportActionsWithStreamedReply';

/** Prepares the rendered report rows, including streamed Concierge drafts, support surveys, and collapsed system messages. */
function useReportActionsListData({sortedVisibleReportActions, reportNameValuePairs, sessionStartTime, linkedReportActionID, unreadMarkerReportActionID}: UseReportActionsListDataParams) {
/** Prepares the rendered report rows, including streamed Concierge drafts and collapsed system messages. */
function useReportActionsListData({sortedVisibleReportActions, sessionStartTime, linkedReportActionID, unreadMarkerReportActionID}: UseReportActionsListDataParams) {
const {report, sortedAllReportActions, parentReportAction, isConciergeHiddenHistory, showFullHistory} = useReportActionsListState();
const {draftReportAction, isDraftPendingCompletion} = useConciergeDraft();
const {clearDraft, revealDraftFromReportAction} = useConciergeDraftActions();
Expand All @@ -26,36 +26,15 @@ function useReportActionsListData({sortedVisibleReportActions, reportNameValuePa
)
: undefined;

const shouldHideSupportTicketSurvey = isSupportTicket(report) && (!isResolvedSupportTicket(report) || !!reportNameValuePairs?.reopenedAsReportID);
const latestResolvedSupportTicketAction = sortedAllReportActions?.find((action) => action.actionName === CONST.REPORT.ACTIONS.TYPE.CLOSED);
const latestSupportTicketSurveyAction = latestResolvedSupportTicketAction
? sortedAllReportActions?.find((action) => action.actionName === CONST.REPORT.ACTIONS.TYPE.SUPPORT_SURVEY && action.created >= latestResolvedSupportTicketAction.created)
: undefined;

const shouldHideDraft = !!(showHiddenHistory && sessionStartTime && draftReportAction && draftReportAction.created < sessionStartTime);
const {reportActionsWithStreamedReply, isSyntheticDraftVisible} = getReportActionsWithStreamedReply({
const {reportActionsWithStreamedReply: renderedVisibleReportActions, isSyntheticDraftVisible} = getReportActionsWithStreamedReply({
sortedVisibleReportActions,
draftReportAction,
isDraftPendingCompletion,
hasPersistedDraft: !!persistedDraftReportAction,
shouldHideDraft,
});

const shouldFilterSupportTicketSurveys =
isSupportTicket(report) &&
reportActionsWithStreamedReply.some(
(action) =>
action.actionName === CONST.REPORT.ACTIONS.TYPE.SUPPORT_SURVEY &&
(shouldHideSupportTicketSurvey || action.reportActionID !== latestSupportTicketSurveyAction?.reportActionID),
);
const renderedVisibleReportActions = shouldFilterSupportTicketSurveys
? reportActionsWithStreamedReply.filter(
(action) =>
action.actionName !== CONST.REPORT.ACTIONS.TYPE.SUPPORT_SURVEY ||
(!shouldHideSupportTicketSurvey && action.reportActionID === latestSupportTicketSurveyAction?.reportActionID),
)
: reportActionsWithStreamedReply;

const shouldCollapseSystemMessages = isExpenseReport(report) || isIOUReport(report) || isInvoiceReport(report) || isTransactionThread(parentReportAction);
const {
displayReportActions,
Expand Down
Loading
Loading