From 55242e5018e31b7bbd803775362c040e80a6ee71 Mon Sep 17 00:00:00 2001 From: Wojciech Boman Date: Thu, 1 Feb 2024 12:21:22 +0100 Subject: [PATCH] Refactor getWorkspacesUnreadStatuses and getWorkspacesBrickRoads --- src/libs/WorkspacesUtils.ts | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/src/libs/WorkspacesUtils.ts b/src/libs/WorkspacesUtils.ts index 1c1cf40bb33a..9a1a258a893a 100644 --- a/src/libs/WorkspacesUtils.ts +++ b/src/libs/WorkspacesUtils.ts @@ -162,13 +162,12 @@ function getWorkspacesBrickRoads(): Record { } }); - 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) { + Object.values(allReports).forEach((report) => { + const policyID = report?.policyID ?? CONST.POLICY.EMPTY; + if (!report || workspacesBrickRoadsMap[policyID] === CONST.BRICK_ROAD_INDICATOR_STATUS.ERROR) { return; } - const workspaceBrickRoad = getBrickRoadForPolicy(policyReport); + const workspaceBrickRoad = getBrickRoadForPolicy(report); if (!workspaceBrickRoad && !!workspacesBrickRoadsMap[policyID]) { return; @@ -190,14 +189,13 @@ function getWorkspacesUnreadStatuses(): Record { const workspacesUnreadStatuses: Record = {}; - Object.keys(allReports).forEach((reportID) => { - const policyID = allReports?.[reportID]?.policyID; - const policyReport = allReports ? allReports[reportID] : null; - if (!policyID || (!policyReport && workspacesUnreadStatuses[policyID])) { + Object.values(allReports).forEach((report) => { + const policyID = report?.policyID; + if (!policyID || workspacesUnreadStatuses[policyID]) { return; } - workspacesUnreadStatuses[policyID] = ReportUtils.isUnread(policyReport); + workspacesUnreadStatuses[policyID] = ReportUtils.isUnread(report); }); return workspacesUnreadStatuses;