diff --git a/src/CONST.ts b/src/CONST.ts index d1bd2e60689f..2a415d61d4e6 100755 --- a/src/CONST.ts +++ b/src/CONST.ts @@ -3109,11 +3109,6 @@ const CONST = { CAROUSEL: 3, }, - BRICK_ROAD: { - GBR: 'info', - RBR: 'error', - }, - /** * Constants for types of violations. * Defined here because they need to be referenced by the type system to generate the diff --git a/src/libs/WorkspacesUtils.ts b/src/libs/WorkspacesUtils.ts index f0d93183e480..c41393cb75f7 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) { @@ -96,36 +96,28 @@ function getChatTabBrickRoad(policyID?: string): BrickRoad | undefined { return undefined; } - let brickRoad: BrickRoad | undefined; + // If policyID is undefined, then all reports are checked whether they contain any brick road + const policyReports = policyID ? Object.values(allReports).filter((report) => report?.policyID === policyID) : Object.values(allReports); - Object.keys(allReports).forEach((report) => { - if (brickRoad === CONST.BRICK_ROAD_INDICATOR_STATUS.ERROR) { - return; - } + let hasChatTabGBR = false; - if (policyID && policyID !== allReports?.[report]?.policyID) { - return; + const hasChatTabRBR = policyReports.some((report) => { + const brickRoad = report ? getBrickRoadForPolicy(report) : undefined; + if (!hasChatTabGBR && brickRoad === CONST.BRICK_ROAD_INDICATOR_STATUS.INFO) { + hasChatTabGBR = true; } + return brickRoad === CONST.BRICK_ROAD_INDICATOR_STATUS.ERROR; + }); - const policyReport = allReports ? allReports[report] : null; - - if (!policyReport) { - return; - } - - const workspaceBrickRoad = getBrickRoadForPolicy(policyReport); - - if (workspaceBrickRoad === CONST.BRICK_ROAD_INDICATOR_STATUS.ERROR) { - brickRoad = CONST.BRICK_ROAD_INDICATOR_STATUS.ERROR; - return; - } + if (hasChatTabRBR) { + return CONST.BRICK_ROAD_INDICATOR_STATUS.ERROR; + } - if (!brickRoad && workspaceBrickRoad) { - brickRoad = workspaceBrickRoad; - } - }); + if (hasChatTabGBR) { + return CONST.BRICK_ROAD_INDICATOR_STATUS.INFO; + } - return brickRoad; + return undefined; } function checkIfWorkspaceSettingsTabHasRBR(policyID?: string) { @@ -152,25 +144,22 @@ 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.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; @@ -192,20 +181,13 @@ 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.values(allReports).forEach((report) => { + const policyID = report?.policyID; + if (!policyID || workspacesUnreadStatuses[policyID]) { return; } - const unreadStatus = ReportUtils.isUnread(policyReport); - - if (unreadStatus) { - workspacesUnreadStatuses[policyID] = true; - } else { - workspacesUnreadStatuses[policyID] = false; - } + workspacesUnreadStatuses[policyID] = ReportUtils.isUnread(report); }); 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; diff --git a/src/types/onyx/Policy.ts b/src/types/onyx/Policy.ts index 966c9f2139da..96ed47f210c9 100644 --- a/src/types/onyx/Policy.ts +++ b/src/types/onyx/Policy.ts @@ -154,6 +154,7 @@ type Policy = { /** ReportID of the admins room for this workspace */ chatReportIDAdmins?: number; + /** ReportID of the announce room for this workspace */ chatReportIDAnnounce?: number; };