Skip to content

Commit

Permalink
Remove CONST.BRICK_ROAD
Browse files Browse the repository at this point in the history
  • Loading branch information
WojtekBoman committed Feb 1, 2024
1 parent 7860696 commit 2ff8e8f
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 33 deletions.
4 changes: 0 additions & 4 deletions src/CONST.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3104,10 +3104,6 @@ const CONST = {
DEFAULT: 5,
CAROUSEL: 3,
},
BRICK_ROAD: {
GBR: 'info',
RBR: 'error',
},

/**
* Constants for types of violations.
Expand Down
42 changes: 17 additions & 25 deletions src/libs/WorkspacesUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ type CheckingMethod = () => boolean;

let allReports: OnyxCollection<Report>;

type BrickRoad = ValueOf<typeof CONST.BRICK_ROAD> | undefined;
type BrickRoad = ValueOf<typeof CONST.BRICK_ROAD_INDICATOR_STATUS> | undefined;

Onyx.connect({
key: ONYXKEYS.COLLECTION.REPORT,
Expand Down Expand Up @@ -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
Expand All @@ -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<Policy>, policyMembers: OnyxCollection<PolicyMembers>) {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -152,22 +152,20 @@ function getWorkspacesBrickRoads(): Record<string, BrickRoad> {
// The key in this map is the workspace id
const workspacesBrickRoadsMap: Record<string, BrickRoad> = {};

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);
Expand All @@ -192,20 +190,14 @@ function getWorkspacesUnreadStatuses(): Record<string, boolean> {

const workspacesUnreadStatuses: Record<string, boolean> = {};

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;
Expand Down
8 changes: 4 additions & 4 deletions src/pages/WorkspaceSwitcherPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 2ff8e8f

Please sign in to comment.