Skip to content
Draft
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
32 changes: 11 additions & 21 deletions src/components/LHNOptionsList/OptionRowLHN.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -434,28 +434,18 @@ function OptionRowLHN({
/>
</View>
)}
{!brickRoadIndicator &&
!!optionItem.isPinned &&
(isProduction ? (
<View
style={styles.ml2}
accessibilityLabel={translate('sidebarScreen.chatPinned')}
>
<Icon
testID="Pin Icon"
fill={theme.icon}
src={expensifyIcons.Pin}
/>
</View>
) : (
<Badge
icon={expensifyIcons.Pin}
text={translate('common.pinned')}
badgeStyles={isOptionFocused && styles.badgeDefaultActive}
isCondensed
isStrong
{!brickRoadIndicator && !!optionItem.isPinned && (
<View
style={styles.ml2}
accessibilityLabel={translate('sidebarScreen.chatPinned')}
>
<Icon
testID="Pin Icon"
fill={theme.icon}
src={expensifyIcons.Pin}
/>
))}
</View>
)}
</View>
</PressableWithSecondaryInteraction>
);
Expand Down
1 change: 1 addition & 0 deletions src/components/LHNOptionsList/OptionRowLHNData.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ function OptionRowLHNData({
fullReport,
reportAttributes?.brickRoadStatus,
reportAttributes?.actionBadge,
reportAttributes?.actionBadgeReportActionID,
reportAttributes?.reportName,
areReportErrorsEqual,
oneTransactionThreadReport,
Expand Down
79 changes: 78 additions & 1 deletion src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -833,6 +833,7 @@
allReportErrors?: Errors;
brickRoadIndicator?: ValueOf<typeof CONST.BRICK_ROAD_INDICATOR_STATUS> | '' | null;
actionBadge?: ValueOf<typeof CONST.REPORT.ACTION_BADGE>;
actionBadgeReportActionID?: string;
tooltipText?: string | null;
alternateTextMaxLines?: number;
boldStyle?: boolean;
Expand Down Expand Up @@ -1036,7 +1037,7 @@
};

let conciergeReportIDOnyxConnect: OnyxEntry<string>;
Onyx.connect({

Check warning on line 1040 in src/libs/ReportUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.CONCIERGE_REPORT_ID,
callback: (value) => {
conciergeReportIDOnyxConnect = value;
Expand All @@ -1044,7 +1045,7 @@
});

const defaultAvatarBuildingIconTestID = 'SvgDefaultAvatarBuilding Icon';
Onyx.connect({

Check warning on line 1048 in src/libs/ReportUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.SESSION,
callback: (value) => {
// When signed out, val is undefined
Expand All @@ -1062,7 +1063,7 @@
let allPersonalDetails: OnyxEntry<PersonalDetailsList>;
let allPersonalDetailLogins: string[];
let currentUserPersonalDetails: OnyxEntry<PersonalDetails>;
Onyx.connect({

Check warning on line 1066 in src/libs/ReportUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.PERSONAL_DETAILS_LIST,
callback: (value) => {
if (currentUserAccountID) {
Expand All @@ -1074,7 +1075,7 @@
});

let allReportsDraft: OnyxCollection<Report>;
Onyx.connect({

Check warning on line 1078 in src/libs/ReportUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.REPORT_DRAFT,
waitForCollectionCallback: true,
callback: (value) => (allReportsDraft = value),
Expand All @@ -1082,7 +1083,7 @@

let allPolicies: OnyxCollection<Policy>;
let policiesArray: Policy[] = [];
Onyx.connect({

Check warning on line 1086 in src/libs/ReportUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.POLICY,
waitForCollectionCallback: true,
callback: (value) => {
Expand All @@ -1092,7 +1093,7 @@
});

let allPolicyDrafts: OnyxCollection<Policy>;
Onyx.connect({

Check warning on line 1096 in src/libs/ReportUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.POLICY_DRAFTS,
waitForCollectionCallback: true,
callback: (value) => (allPolicyDrafts = value),
Expand All @@ -1100,7 +1101,7 @@

let allReports: OnyxCollection<Report>;
let reportsByPolicyID: ReportByPolicyMap;
Onyx.connect({

Check warning on line 1104 in src/libs/ReportUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.REPORT,
waitForCollectionCallback: true,
callback: (value) => {
Expand Down Expand Up @@ -1136,14 +1137,14 @@
});

let betaConfiguration: OnyxEntry<BetaConfiguration> = {};
Onyx.connect({

Check warning on line 1140 in src/libs/ReportUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.BETA_CONFIGURATION,
callback: (value) => (betaConfiguration = value ?? {}),
});

let deprecatedAllTransactions: OnyxCollection<Transaction> = {};
let deprecatedReportsTransactions: Record<string, Transaction[]> = {};
Onyx.connect({

Check warning on line 1147 in src/libs/ReportUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.TRANSACTION,
waitForCollectionCallback: true,
callback: (value) => {
Expand All @@ -1169,7 +1170,7 @@
});

let allReportActions: OnyxCollection<ReportActions>;
Onyx.connect({

Check warning on line 1173 in src/libs/ReportUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.REPORT_ACTIONS,
waitForCollectionCallback: true,
callback: (actions) => {
Expand Down Expand Up @@ -9137,6 +9138,80 @@
});
}

/**
* Returns the reportID of the first child expense report that has violations under the same policy,
* or undefined if none found. Used to find the REPORT_PREVIEW action to deep-link to.
*/
function getViolatingReportIDForLHN(report: OnyxEntry<Report>, transactionViolations: OnyxCollection<TransactionViolation[]>): string | undefined {
if (!report || !isPolicyExpenseChat(report)) {
return undefined;
}

if (!isCurrentUserSubmitter(report)) {
return undefined;
}
if (!report.policyID || !reportsByPolicyID) {
return undefined;
}

const potentialReports = Object.values(reportsByPolicyID[report.policyID] ?? {}) ?? [];
const violatingReport = potentialReports.find((potentialReport) => {
if (!potentialReport) {
return false;
}
const policy = allPolicies?.[`${ONYXKEYS.COLLECTION.POLICY}${potentialReport.policyID}`];
const transactions = getReportTransactions(potentialReport.reportID);

if (!isOpenOrProcessingReport(potentialReport)) {
return false;
}

return (
!isInvoiceReport(potentialReport) &&
ViolationsUtils.hasVisibleViolationsForUser(
potentialReport,
transactionViolations,
currentUserEmail ?? '',
currentUserAccountID ?? CONST.DEFAULT_NUMBER_ID,
policy,
transactions,
) &&
(hasViolations(
potentialReport.reportID,
transactionViolations,
currentUserAccountID ?? CONST.DEFAULT_NUMBER_ID,
currentUserEmail ?? '',
true,
transactions,
potentialReport,
policy,
) ||
hasWarningTypeViolations(
potentialReport.reportID,
transactionViolations,
currentUserAccountID ?? CONST.DEFAULT_NUMBER_ID,
currentUserEmail ?? '',
true,
transactions,
potentialReport,
policy,
) ||
hasNoticeTypeViolations(
potentialReport.reportID,
transactionViolations,
currentUserAccountID ?? CONST.DEFAULT_NUMBER_ID,
currentUserEmail ?? '',
true,
transactions,
potentialReport,
policy,
))
);
});

return violatingReport?.reportID;
}

/**
* Checks to see if a report contains a violation
*/
Expand Down Expand Up @@ -12714,7 +12789,7 @@
const hasErrors = Object.entries(reportErrors ?? {}).length > 0;
const oneTransactionThreadReportID = getOneTransactionThreadReportID(report, chatReport, reportActionsList);
const parentReportAction = report?.parentReportActionID ? parentReportActionsList?.[report.parentReportActionID] : undefined;
const {reason, actionBadge} = getReasonAndReportActionThatRequiresAttention(report, parentReportAction, isReportArchived) ?? {};
const {reason, reportAction: attentionReportAction, actionBadge} = getReasonAndReportActionThatRequiresAttention(report, parentReportAction, isReportArchived) ?? {};

return {
hasViolationsToDisplayInLHN,
Expand All @@ -12725,6 +12800,7 @@
parentReportAction,
requiresAttention: !!reason,
actionBadge,
actionBadgeReportActionID: attentionReportAction?.reportActionID,
};
}

Expand Down Expand Up @@ -13378,6 +13454,7 @@
shouldDisableThread,
shouldDisplayThreadReplies,
shouldDisplayViolationsRBRInLHN,
getViolatingReportIDForLHN,
shouldReportBeInOptionList,
shouldReportShowSubscript,
shouldShowFlagComment,
Expand Down
8 changes: 7 additions & 1 deletion src/libs/SidebarUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ import {
isInviteOrRemovedAction,
isOldDotReportAction,
isRenamedAction,
isReportPreviewAction,
isTagModificationAction,
isTaskAction,
} from './ReportActionsUtils';
Expand All @@ -151,6 +152,7 @@ import {
getReportParticipantsTitle,
getReportSubtitlePrefix,
getUnreportedTransactionMessage,
getViolatingReportIDForLHN,
getWorkspaceNameUpdatedMessage,
hasReportErrorsOtherThanFailedReceipt,
isAdminRoom,
Expand Down Expand Up @@ -635,9 +637,12 @@ function getReasonAndReportActionThatHasRedBrickRoad(
return null;
}

if (shouldDisplayViolationsRBRInLHN(report, transactionViolations)) {
const violatingReportID = getViolatingReportIDForLHN(report, transactionViolations);
if (violatingReportID) {
const reportPreviewAction = Object.values(reportActions ?? {}).find((action) => isReportPreviewAction(action) && getOriginalMessage(action)?.linkedReportID === violatingReportID);
return {
reason: CONST.RBR_REASONS.HAS_TRANSACTION_THREAD_VIOLATIONS,
reportAction: reportPreviewAction,
};
}

Expand Down Expand Up @@ -792,6 +797,7 @@ function getOptionData({
result.pendingAction = report.pendingFields?.addWorkspaceRoom ?? report.pendingFields?.createChat;
result.brickRoadIndicator = reportAttributes?.brickRoadStatus;
result.actionBadge = reportAttributes?.actionBadge;
result.actionBadgeReportActionID = reportAttributes?.actionBadgeReportActionID;
result.ownerAccountID = report.ownerAccountID;
result.managerID = report.managerID;
result.reportID = report.reportID;
Expand Down
17 changes: 16 additions & 1 deletion src/libs/actions/OnyxDerived/configs/reportAttributes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ export default createOnyxDerivedValueConfig({
reportErrors,
oneTransactionThreadReportID,
actionBadge: actionGreenBadge,
actionBadgeReportActionID: greenBadgeReportActionID,
} = generateReportAttributes({
report,
chatReport,
Expand All @@ -219,15 +220,28 @@ export default createOnyxDerivedValueConfig({

let brickRoadStatus;
let actionBadge;
let actionBadgeReportActionID;
// if report has errors or violations, show red dot
if (SidebarUtils.shouldShowRedBrickRoad(report, chatReport, reportActionsList, hasAnyViolations, reportErrors, transactions, transactionViolations, !!isReportArchived)) {
const reasonAndReportAction = SidebarUtils.getReasonAndReportActionThatHasRedBrickRoad(
report,
chatReport,
reportActionsList,
hasAnyViolations,
reportErrors,
transactions,
transactionViolations,
!!isReportArchived,
);
if (reasonAndReportAction) {
brickRoadStatus = CONST.BRICK_ROAD_INDICATOR_STATUS.ERROR;
actionBadge = CONST.REPORT.ACTION_BADGE.FIX;
actionBadgeReportActionID = reasonAndReportAction.reportAction?.reportActionID;
}
// if report does not have error, check if it should show green dot
if (brickRoadStatus !== CONST.BRICK_ROAD_INDICATOR_STATUS.ERROR && requiresAttention) {
brickRoadStatus = CONST.BRICK_ROAD_INDICATOR_STATUS.INFO;
actionBadge = actionGreenBadge;
actionBadgeReportActionID = greenBadgeReportActionID;
}

acc[report.reportID] = {
Expand All @@ -249,6 +263,7 @@ export default createOnyxDerivedValueConfig({
brickRoadStatus,
requiresAttention,
actionBadge,
actionBadgeReportActionID,
reportErrors,
oneTransactionThreadReportID,
};
Expand Down
5 changes: 3 additions & 2 deletions src/pages/inbox/sidebar/SidebarLinks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {cancelSpan} from '@libs/telemetry/activeSpans';
import type {SkeletonSpanReasonAttributes} from '@libs/telemetry/useSkeletonSpan';
import * as ReportActionContextMenu from '@pages/inbox/report/ContextMenu/ReportActionContextMenu';
import CONST from '@src/CONST';
import type {OptionData} from '@src/libs/ReportUtils';
import ONYXKEYS from '@src/ONYXKEYS';
import ROUTES from '@src/ROUTES';
import type {Report} from '@src/types/onyx';
Expand Down Expand Up @@ -51,7 +52,7 @@ function SidebarLinks({insets, optionListItems, priorityMode = CONST.PRIORITY_MO
* Show Report page with selected report id
*/
const showReportPage = useCallback(
(option: Report) => {
(option: OptionData) => {
// Prevent opening Report page when clicking LHN row quickly after clicking FAB icon
// or when clicking the active LHN row on large screens
// or when continuously clicking different LHNs, only apply to small screen
Expand All @@ -70,7 +71,7 @@ function SidebarLinks({insets, optionListItems, priorityMode = CONST.PRIORITY_MO
cancelSpan(`${CONST.TELEMETRY.SPAN_OPEN_REPORT}_${option.reportID}`);
return;
}
Navigation.navigate(ROUTES.REPORT_WITH_ID.getRoute(option.reportID));
Navigation.navigate(ROUTES.REPORT_WITH_ID.getRoute(option.reportID, option.actionBadgeReportActionID));
},
[shouldUseNarrowLayout, isActiveReport],
);
Expand Down
4 changes: 4 additions & 0 deletions src/types/onyx/DerivedValues.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ type ReportAttributes = {
* The action badge to display instead of the GBR/RBR dot (e.g. 'submit', 'approve', 'pay').
*/
actionBadge?: ValueOf<typeof CONST.REPORT.ACTION_BADGE>;
/**
* The reportActionID associated with the action badge, used for deep-linking from LHN.
*/
actionBadgeReportActionID?: string;
/**
* The errors of the report.
*/
Expand Down
Loading