Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions src/pages/Insights/dashboardSpecs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -273,12 +273,15 @@ function getUpgradeablePolicyIDsInScope(policiesInScope: Policy[], login: string
.map((policy) => policy.id);
}

/** Returns the dashboards the user can open, ignoring the workspace filter. */
/**
* Returns the dashboards the user can open, ignoring the workspace filter.
* Workspaces deleted offline stay in Onyx until the server confirms, so they don't count, or a dashboard would vanish only on reconnect.
*/
function getAccessibleDashboards(policies: OnyxCollection<Policy>, login: string | undefined, isBetaEnabled: (beta: Beta) => boolean): InsightsDashboardID[] {
const allPolicies = Object.values(policies ?? {});
const activePolicies = Object.values(policies ?? {}).filter((policy): policy is Policy => !!policy && !isArchivedOrPendingDeletePolicy(policy));
return Object.values(CONST.INSIGHTS.DASHBOARD).filter((dashboardID) => {
const {beta, isPolicyEligible} = INSIGHTS_DASHBOARD_SPECS[dashboardID];
return (!beta || isBetaEnabled(beta)) && (!isPolicyEligible || allPolicies.some((policy) => !!policy && isPolicyEligible(policy, login)));
return (!beta || isBetaEnabled(beta)) && (!isPolicyEligible || activePolicies.some((policy) => isPolicyEligible(policy, login)));
});
}

Expand Down
11 changes: 11 additions & 0 deletions tests/unit/insightsAccessTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,17 @@ describe('insightsAccess', () => {
expect(dashboards).toEqual([SPEND, COMPLIANCE]);
});

it('hides Compliance once its only qualifying workspace is deleted offline', () => {
// Given an admin with the beta whose only workspace is waiting for the server to confirm its deletion
const policies = toCollection([{...buildPolicy(1, CONST.POLICY.ROLE.ADMIN), pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE}]);

// When the dashboards they can open are resolved
const dashboards = getAccessibleDashboards(policies, LOGIN, isComplianceBetaEnabled);

// Then Compliance is gone right away, instead of turning into a not-found page on reconnect
expect(dashboards).toEqual([SPEND]);
});

it('offers Efficiency to admins and auditors with the beta, on every plan', () => {
// Given an admin of a Collect workspace and an auditor of a Control workspace, both with the beta
const adminPolicies = toCollection([buildPolicy(1, CONST.POLICY.ROLE.ADMIN, CONST.POLICY.TYPE.TEAM)]);
Expand Down
Loading