@@ -2,18 +2,16 @@ import Onyx from 'react-native-onyx';
2
2
import type { OnyxCollection , OnyxEntry } from 'react-native-onyx' ;
3
3
import type { ValueOf } from 'type-fest' ;
4
4
import type { LocaleContextProps } from '@components/LocaleContextProvider' ;
5
- import type { PolicySelector } from '@hooks/useReportIDs' ;
6
5
import CONST from '@src/CONST' ;
7
6
import type { TranslationPaths } from '@src/languages/types' ;
8
7
import ONYXKEYS from '@src/ONYXKEYS' ;
9
- import type { Beta , Policy , PriorityMode , ReimbursementAccount , Report , ReportAction , ReportActions , TransactionViolation , TransactionViolations } from '@src/types/onyx' ;
8
+ import type { Policy , ReimbursementAccount , Report , ReportAction , ReportActions , TransactionViolations } from '@src/types/onyx' ;
10
9
import type { PolicyConnectionSyncProgress , Unit } from '@src/types/onyx/Policy' ;
11
10
import { isConnectionInProgress } from './actions/connections' ;
12
- import * as CurrencyUtils from './CurrencyUtils' ;
11
+ import { convertToDisplayString } from './CurrencyUtils' ;
13
12
import { isPolicyAdmin , shouldShowCustomUnitsError , shouldShowEmployeeListError , shouldShowPolicyError , shouldShowSyncError , shouldShowTaxRateError } from './PolicyUtils' ;
14
- import * as ReportActionsUtils from './ReportActionsUtils' ;
15
- import * as ReportUtils from './ReportUtils' ;
16
- import SidebarUtils from './SidebarUtils' ;
13
+ import { getOneTransactionThreadReportID } from './ReportActionsUtils' ;
14
+ import { getAllReportErrors , hasReportViolations , isReportOwner , isUnread , isUnreadWithMention , requiresAttentionFromCurrentUser , shouldDisplayViolationsRBRInLHN } from './ReportUtils' ;
17
15
18
16
type CheckingMethod = ( ) => boolean ;
19
17
@@ -69,13 +67,13 @@ Onyx.connect({
69
67
*/
70
68
const getBrickRoadForPolicy = ( report : Report , altReportActions ?: OnyxCollection < ReportActions > ) : BrickRoad => {
71
69
const reportActions = ( altReportActions ?? allReportActions ) ?. [ `${ ONYXKEYS . COLLECTION . REPORT_ACTIONS } ${ report . reportID } ` ] ?? { } ;
72
- const reportErrors = ReportUtils . getAllReportErrors ( report , reportActions ) ;
73
- const oneTransactionThreadReportID = ReportActionsUtils . getOneTransactionThreadReportID ( report . reportID , reportActions ) ;
70
+ const reportErrors = getAllReportErrors ( report , reportActions ) ;
71
+ const oneTransactionThreadReportID = getOneTransactionThreadReportID ( report . reportID , reportActions ) ;
74
72
let doesReportContainErrors = Object . keys ( reportErrors ?? { } ) . length !== 0 ? CONST . BRICK_ROAD_INDICATOR_STATUS . ERROR : undefined ;
75
73
76
74
if ( ! doesReportContainErrors ) {
77
- const shouldDisplayViolations = ReportUtils . shouldDisplayViolationsRBRInLHN ( report , allTransactionViolations ) ;
78
- const shouldDisplayReportViolations = ReportUtils . isReportOwner ( report ) && ReportUtils . hasReportViolations ( report . reportID ) ;
75
+ const shouldDisplayViolations = shouldDisplayViolationsRBRInLHN ( report , allTransactionViolations ) ;
76
+ const shouldDisplayReportViolations = isReportOwner ( report ) && hasReportViolations ( report . reportID ) ;
79
77
const hasViolations = shouldDisplayViolations || shouldDisplayReportViolations ;
80
78
if ( hasViolations ) {
81
79
doesReportContainErrors = CONST . BRICK_ROAD_INDICATOR_STATUS . ERROR ;
@@ -85,7 +83,7 @@ const getBrickRoadForPolicy = (report: Report, altReportActions?: OnyxCollection
85
83
if ( oneTransactionThreadReportID && ! doesReportContainErrors ) {
86
84
const oneTransactionThreadReport = reportsCollection ?. [ `${ ONYXKEYS . COLLECTION . REPORT } ${ oneTransactionThreadReportID } ` ] ;
87
85
88
- if ( ReportUtils . shouldDisplayViolationsRBRInLHN ( oneTransactionThreadReport , allTransactionViolations ) ) {
86
+ if ( shouldDisplayViolationsRBRInLHN ( oneTransactionThreadReport , allTransactionViolations ) ) {
89
87
doesReportContainErrors = CONST . BRICK_ROAD_INDICATOR_STATUS . ERROR ;
90
88
}
91
89
}
@@ -100,8 +98,8 @@ const getBrickRoadForPolicy = (report: Report, altReportActions?: OnyxCollection
100
98
const itemParentReportActions = allReportActions ?. [ `${ ONYXKEYS . COLLECTION . REPORT_ACTIONS } ${ report . parentReportID } ` ] ?? { } ;
101
99
itemParentReportAction = report . parentReportActionID ? itemParentReportActions [ report . parentReportActionID ] : undefined ;
102
100
}
103
- const reportOption = { ...report , isUnread : ReportUtils . isUnread ( report ) , isUnreadWithMention : ReportUtils . isUnreadWithMention ( report ) } ;
104
- const shouldShowGreenDotIndicator = ReportUtils . requiresAttentionFromCurrentUser ( reportOption , itemParentReportAction ) ;
101
+ const reportOption = { ...report , isUnread : isUnread ( report ) , isUnreadWithMention : isUnreadWithMention ( report ) } ;
102
+ const shouldShowGreenDotIndicator = requiresAttentionFromCurrentUser ( reportOption , itemParentReportAction ) ;
105
103
return shouldShowGreenDotIndicator ? CONST . BRICK_ROAD_INDICATOR_STATUS . INFO : undefined ;
106
104
} ;
107
105
@@ -138,23 +136,12 @@ function hasWorkspaceSettingsRBR(policy: Policy) {
138
136
) ;
139
137
}
140
138
141
- function getChatTabBrickRoadReport (
142
- policyID : string | undefined ,
143
- currentReportId : string | undefined ,
144
- reports : OnyxCollection < Report > ,
145
- betas : OnyxEntry < Beta [ ] > ,
146
- policies : OnyxCollection < PolicySelector > ,
147
- priorityMode : OnyxEntry < PriorityMode > ,
148
- transactionViolations : OnyxCollection < TransactionViolation [ ] > ,
149
- policyMemberAccountIDs : number [ ] = [ ] ,
150
- ) : OnyxEntry < Report > {
151
- const reportIDs = SidebarUtils . getOrderedReportIDs ( currentReportId , reports , betas , policies , priorityMode , transactionViolations , policyID , policyMemberAccountIDs ) ;
152
- if ( ! reportIDs . length ) {
139
+ function getChatTabBrickRoadReport ( policyID : string | undefined , orderedReportIDs : string [ ] = [ ] ) : OnyxEntry < Report > {
140
+ if ( ! orderedReportIDs . length ) {
153
141
return undefined ;
154
142
}
155
143
156
- const allReports = reportIDs . map ( ( reportID ) => reports ?. [ `${ ONYXKEYS . COLLECTION . REPORT } ${ reportID } ` ] ) ;
157
-
144
+ const allReports = orderedReportIDs . map ( ( reportID ) => reportsCollection ?. [ `${ ONYXKEYS . COLLECTION . REPORT } ${ reportID } ` ] ) ;
158
145
// If policyID is undefined, then all reports are checked whether they contain any brick road
159
146
const policyReports = policyID ? Object . values ( allReports ) . filter ( ( report ) => report ?. policyID === policyID ) : Object . values ( allReports ) ;
160
147
@@ -180,17 +167,8 @@ function getChatTabBrickRoadReport(
180
167
return undefined ;
181
168
}
182
169
183
- function getChatTabBrickRoad (
184
- policyID : string | undefined ,
185
- currentReportId : string | undefined ,
186
- reports : OnyxCollection < Report > ,
187
- betas : OnyxEntry < Beta [ ] > ,
188
- policies : OnyxCollection < PolicySelector > ,
189
- priorityMode : OnyxEntry < PriorityMode > ,
190
- transactionViolations : OnyxCollection < TransactionViolation [ ] > ,
191
- policyMemberAccountIDs : number [ ] = [ ] ,
192
- ) : BrickRoad | undefined {
193
- const report = getChatTabBrickRoadReport ( policyID , currentReportId , reports , betas , policies , priorityMode , transactionViolations , policyMemberAccountIDs ) ;
170
+ function getChatTabBrickRoad ( policyID : string | undefined , orderedReportIDs : string [ ] ) : BrickRoad | undefined {
171
+ const report = getChatTabBrickRoadReport ( policyID , orderedReportIDs ) ;
194
172
return report ? getBrickRoadForPolicy ( report ) : undefined ;
195
173
}
196
174
@@ -250,7 +228,7 @@ function getWorkspacesUnreadStatuses(reports: OnyxCollection<Report>): Record<st
250
228
251
229
// When the only message of a report is deleted lastVisibileActionCreated is not reset leading to wrongly
252
230
// setting it Unread so we add additional condition here to avoid read workspace indicator from being bold.
253
- workspacesUnreadStatuses [ policyID ] = ReportUtils . isUnread ( report ) && ! ! report . lastActorAccountID ;
231
+ workspacesUnreadStatuses [ policyID ] = isUnread ( report ) && ! ! report . lastActorAccountID ;
254
232
} ) ;
255
233
256
234
return workspacesUnreadStatuses ;
@@ -300,7 +278,7 @@ function getOwnershipChecksDisplayText(
300
278
title = translate ( 'workspace.changeOwner.ownerOwesAmountTitle' ) ;
301
279
text = translate ( 'workspace.changeOwner.ownerOwesAmountText' , {
302
280
email : ownerOwesAmount ?. ownerEmail ,
303
- amount : CurrencyUtils . convertToDisplayString ( ownerOwesAmount ?. amount , ownerOwesAmount ?. currency ) ,
281
+ amount : convertToDisplayString ( ownerOwesAmount ?. amount , ownerOwesAmount ?. currency ) ,
304
282
} ) ;
305
283
buttonText = translate ( 'workspace.changeOwner.ownerOwesAmountButtonText' ) ;
306
284
break ;
0 commit comments