Skip to content

Commit

Permalink
Merge pull request #61 from software-mansion-labs/w8/ideal-nav-fixes-v7
Browse files Browse the repository at this point in the history
W8/ideal nav fixes v7
  • Loading branch information
kosmydel authored Feb 1, 2024
2 parents e20a5f4 + b3ae304 commit f4611da
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 56 deletions.
5 changes: 0 additions & 5 deletions src/CONST.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
76 changes: 29 additions & 47 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 @@ -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) {
Expand All @@ -152,25 +144,22 @@ 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.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;
Expand All @@ -192,20 +181,13 @@ 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.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;
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
1 change: 1 addition & 0 deletions src/types/onyx/Policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};

Expand Down

0 comments on commit f4611da

Please sign in to comment.