|
1 | | -import Onyx from 'react-native-onyx'; |
2 | 1 | import type {OnyxEntry} from 'react-native-onyx'; |
3 | 2 | import type {ValueOf} from 'type-fest'; |
4 | 3 | import type {LocaleContextProps} from '@components/LocaleContextProvider'; |
5 | 4 | import CONST from '@src/CONST'; |
6 | 5 | import type {TranslationPaths} from '@src/languages/types'; |
7 | | -import ONYXKEYS from '@src/ONYXKEYS'; |
8 | | -import type {Policy, Report, ReportAttributesDerivedValue} from '@src/types/onyx'; |
| 6 | +import type {Policy, ReportAttributesDerivedValue} from '@src/types/onyx'; |
9 | 7 | import type {Unit} from '@src/types/onyx/Policy'; |
10 | 8 | import {convertToDisplayString} from './CurrencyUtils'; |
11 | 9 |
|
12 | 10 | type BrickRoad = ValueOf<typeof CONST.BRICK_ROAD_INDICATOR_STATUS> | undefined; |
13 | 11 |
|
14 | | -let reportAttributes: ReportAttributesDerivedValue['reports']; |
15 | | -Onyx.connect({ |
16 | | - key: ONYXKEYS.DERIVED.REPORT_ATTRIBUTES, |
17 | | - callback: (value) => { |
18 | | - if (!value) { |
19 | | - return; |
20 | | - } |
21 | | - reportAttributes = value.reports; |
22 | | - }, |
23 | | -}); |
24 | 12 | /** |
25 | | - * @param altReportActions Replaces (local) allReportActions used within (local) function getWorkspacesBrickRoads |
26 | | - * @returns BrickRoad for the policy passed as a param and optionally actionsByReport (if passed) |
| 13 | + * @returns BrickRoad for the given reportID using reportAttributes |
27 | 14 | */ |
28 | | -const getBrickRoadForPolicy = (report: Report): BrickRoad => { |
29 | | - return reportAttributes?.[report.reportID]?.brickRoadStatus; |
| 15 | +const getBrickRoadForPolicy = (reportID: string, reportAttributes: ReportAttributesDerivedValue['reports'] | undefined): BrickRoad => { |
| 16 | + return reportAttributes?.[reportID]?.brickRoadStatus; |
30 | 17 | }; |
31 | 18 |
|
32 | | -function getChatTabBrickRoadReport(orderedReports: Array<OnyxEntry<Report>> = []): OnyxEntry<Report> { |
33 | | - if (!orderedReports.length) { |
| 19 | +function getChatTabBrickRoadReportID(orderedReportIDs: string[], reportAttributes: ReportAttributesDerivedValue['reports'] | undefined): string | undefined { |
| 20 | + if (!orderedReportIDs.length) { |
34 | 21 | return undefined; |
35 | 22 | } |
36 | 23 |
|
37 | | - let reportWithGBR: OnyxEntry<Report>; |
| 24 | + let reportIDWithGBR: string | undefined; |
38 | 25 |
|
39 | | - const reportWithRBR = orderedReports.find((report) => { |
40 | | - const brickRoad = report ? getBrickRoadForPolicy(report) : undefined; |
41 | | - if (!reportWithGBR && brickRoad === CONST.BRICK_ROAD_INDICATOR_STATUS.INFO) { |
42 | | - reportWithGBR = report; |
43 | | - return false; |
| 26 | + for (const reportID of orderedReportIDs) { |
| 27 | + const brickRoad = getBrickRoadForPolicy(reportID, reportAttributes); |
| 28 | + if (brickRoad === CONST.BRICK_ROAD_INDICATOR_STATUS.INFO) { |
| 29 | + reportIDWithGBR = reportID; |
| 30 | + } |
| 31 | + if (brickRoad === CONST.BRICK_ROAD_INDICATOR_STATUS.ERROR) { |
| 32 | + return reportID; |
44 | 33 | } |
45 | | - return brickRoad === CONST.BRICK_ROAD_INDICATOR_STATUS.ERROR; |
46 | | - }); |
47 | | - |
48 | | - if (reportWithRBR) { |
49 | | - return reportWithRBR; |
50 | | - } |
51 | | - |
52 | | - if (reportWithGBR) { |
53 | | - return reportWithGBR; |
54 | 34 | } |
55 | 35 |
|
56 | | - return undefined; |
| 36 | + return reportIDWithGBR; |
57 | 37 | } |
58 | 38 |
|
59 | | -function getChatTabBrickRoad(orderedReports: Array<OnyxEntry<Report>>): BrickRoad | undefined { |
60 | | - const report = getChatTabBrickRoadReport(orderedReports); |
61 | | - return report ? getBrickRoadForPolicy(report) : undefined; |
| 39 | +function getChatTabBrickRoad(orderedReportIDs: string[], reportAttributes: ReportAttributesDerivedValue['reports'] | undefined): BrickRoad | undefined { |
| 40 | + const reportID = getChatTabBrickRoadReportID(orderedReportIDs, reportAttributes); |
| 41 | + return reportID ? getBrickRoadForPolicy(reportID, reportAttributes) : undefined; |
62 | 42 | } |
63 | 43 |
|
64 | 44 | /** |
@@ -145,5 +125,5 @@ function getOwnershipChecksDisplayText( |
145 | 125 | return {title, text, buttonText}; |
146 | 126 | } |
147 | 127 |
|
148 | | -export {getChatTabBrickRoadReport, getBrickRoadForPolicy, getChatTabBrickRoad, getUnitTranslationKey, getOwnershipChecksDisplayText}; |
| 128 | +export {getChatTabBrickRoadReportID, getBrickRoadForPolicy, getChatTabBrickRoad, getUnitTranslationKey, getOwnershipChecksDisplayText}; |
149 | 129 | export type {BrickRoad}; |
0 commit comments