From 2ff8e8f7f51cc0cc48449c50731d6048843697c5 Mon Sep 17 00:00:00 2001 From: Wojciech Boman Date: Thu, 1 Feb 2024 11:54:35 +0100 Subject: [PATCH] Remove CONST.BRICK_ROAD --- src/CONST.ts | 4 --- src/libs/WorkspacesUtils.ts | 42 ++++++++++++------------------ src/pages/WorkspaceSwitcherPage.js | 8 +++--- 3 files changed, 21 insertions(+), 33 deletions(-) diff --git a/src/CONST.ts b/src/CONST.ts index 9d0a90a6a53d..4870dd0a12fe 100755 --- a/src/CONST.ts +++ b/src/CONST.ts @@ -3104,10 +3104,6 @@ const CONST = { DEFAULT: 5, CAROUSEL: 3, }, - BRICK_ROAD: { - GBR: 'info', - RBR: 'error', - }, /** * Constants for types of violations. diff --git a/src/libs/WorkspacesUtils.ts b/src/libs/WorkspacesUtils.ts index f0d93183e480..1c1cf40bb33a 100644 --- a/src/libs/WorkspacesUtils.ts +++ b/src/libs/WorkspacesUtils.ts @@ -13,7 +13,7 @@ type CheckingMethod = () => boolean; let allReports: OnyxCollection; -type BrickRoad = ValueOf | undefined; +type BrickRoad = ValueOf | undefined; Onyx.connect({ key: ONYXKEYS.COLLECTION.REPORT, @@ -57,7 +57,7 @@ const getBrickRoadForPolicy = (report: Report): BrickRoad => { const reportErrors = OptionsListUtils.getAllReportErrors(report, reportActions); const doesReportContainErrors = Object.keys(reportErrors ?? {}).length !== 0 ? CONST.BRICK_ROAD_INDICATOR_STATUS.ERROR : undefined; if (doesReportContainErrors) { - return CONST.BRICK_ROAD.RBR; + return CONST.BRICK_ROAD_INDICATOR_STATUS.ERROR; } // To determine if the report requires attention from the current user, we need to load the parent report action @@ -68,7 +68,7 @@ const getBrickRoadForPolicy = (report: Report): BrickRoad => { } const reportOption = {...report, isUnread: ReportUtils.isUnread(report), isUnreadWithMention: ReportUtils.isUnreadWithMention(report)}; const shouldShowGreenDotIndicator = ReportUtils.requiresAttentionFromCurrentUser(reportOption, itemParentReportAction); - return shouldShowGreenDotIndicator ? CONST.BRICK_ROAD.GBR : undefined; + return shouldShowGreenDotIndicator ? CONST.BRICK_ROAD_INDICATOR_STATUS.INFO : undefined; }; function hasGlobalWorkspaceSettingsRBR(policies: OnyxCollection, policyMembers: OnyxCollection) { @@ -98,16 +98,16 @@ function getChatTabBrickRoad(policyID?: string): BrickRoad | undefined { let brickRoad: BrickRoad | undefined; - Object.keys(allReports).forEach((report) => { + Object.keys(allReports).forEach((reportID) => { if (brickRoad === CONST.BRICK_ROAD_INDICATOR_STATUS.ERROR) { return; } - if (policyID && policyID !== allReports?.[report]?.policyID) { + if (policyID && policyID !== allReports?.[reportID]?.policyID) { return; } - const policyReport = allReports ? allReports[report] : null; + const policyReport = allReports ? allReports[reportID] : null; if (!policyReport) { return; @@ -152,22 +152,20 @@ function getWorkspacesBrickRoads(): Record { // The key in this map is the workspace id const workspacesBrickRoadsMap: Record = {}; - const cleanPolicies = Object.fromEntries(Object.entries(allPolicies ?? {}).filter(([, policy]) => !!policy)); - - Object.values(cleanPolicies).forEach((policy) => { + Object.values(allPolicies ?? {}).forEach((policy) => { if (!policy) { return; } if (hasWorkspaceSettingsRBR(policy)) { - workspacesBrickRoadsMap[policy.id] = CONST.BRICK_ROAD.RBR; + workspacesBrickRoadsMap[policy.id] = CONST.BRICK_ROAD_INDICATOR_STATUS.ERROR; } }); - Object.keys(allReports).forEach((report) => { - const policyID = allReports?.[report]?.policyID ?? CONST.POLICY.EMPTY; - const policyReport = allReports ? allReports[report] : null; - if (!policyReport || workspacesBrickRoadsMap[policyID] === CONST.BRICK_ROAD.RBR) { + Object.keys(allReports).forEach((reportID) => { + const policyID = allReports?.[reportID]?.policyID ?? CONST.POLICY.EMPTY; + const policyReport = allReports ? allReports[reportID] : null; + if (!policyReport || workspacesBrickRoadsMap[policyID] === CONST.BRICK_ROAD_INDICATOR_STATUS.ERROR) { return; } const workspaceBrickRoad = getBrickRoadForPolicy(policyReport); @@ -192,20 +190,14 @@ function getWorkspacesUnreadStatuses(): Record { const workspacesUnreadStatuses: Record = {}; - Object.keys(allReports).forEach((report) => { - const policyID = allReports?.[report]?.policyID; - const policyReport = allReports ? allReports[report] : null; - if (!policyID || !policyReport) { + Object.keys(allReports).forEach((reportID) => { + const policyID = allReports?.[reportID]?.policyID; + const policyReport = allReports ? allReports[reportID] : null; + if (!policyID || (!policyReport && workspacesUnreadStatuses[policyID])) { return; } - const unreadStatus = ReportUtils.isUnread(policyReport); - - if (unreadStatus) { - workspacesUnreadStatuses[policyID] = true; - } else { - workspacesUnreadStatuses[policyID] = false; - } + workspacesUnreadStatuses[policyID] = ReportUtils.isUnread(policyReport); }); return workspacesUnreadStatuses; diff --git a/src/pages/WorkspaceSwitcherPage.js b/src/pages/WorkspaceSwitcherPage.js index 9972a7bac5ba..6c63617200c8 100644 --- a/src/pages/WorkspaceSwitcherPage.js +++ b/src/pages/WorkspaceSwitcherPage.js @@ -84,12 +84,12 @@ function WorkspaceSwitcherPage({policies}) { return brickRoadsForPolicies[policyId]; } - if (_.values(brickRoadsForPolicies).includes(CONST.BRICK_ROAD.RBR)) { - return CONST.BRICK_ROAD.RBR; + if (_.values(brickRoadsForPolicies).includes(CONST.BRICK_ROAD_INDICATOR_STATUS.ERROR)) { + return CONST.BRICK_ROAD_INDICATOR_STATUS.ERROR; } - if (_.values(brickRoadsForPolicies).includes(CONST.BRICK_ROAD.GBR)) { - return CONST.BRICK_ROAD.GBR; + if (_.values(brickRoadsForPolicies).includes(CONST.BRICK_ROAD_INDICATOR_STATUS.INFO)) { + return CONST.BRICK_ROAD_INDICATOR_STATUS.INFO; } return undefined;