Skip to content

Commit

Permalink
Merge pull request #54197 from Expensify/lucien/revert-53630
Browse files Browse the repository at this point in the history
Revert "Merge pull request #53630 from FitseTLT/fix-showing-workspace…
  • Loading branch information
lakchote authored Dec 16, 2024
2 parents 7d5bf75 + 2c4c659 commit f0461fb
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 22 deletions.
10 changes: 4 additions & 6 deletions src/libs/PolicyUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,11 @@ Onyx.connect({

/**
* Filter out the active policies, which will exclude policies with pending deletion
* and policies the current user doesn't belong to.
* These are policies that we can use to create reports with in NewDot.
*/
function getActivePolicies(policies: OnyxCollection<Policy> | null, currentUserLogin: string | undefined): Policy[] {
function getActivePolicies(policies: OnyxCollection<Policy> | null): Policy[] {
return Object.values(policies ?? {}).filter<Policy>(
(policy): policy is Policy =>
!!policy && policy.pendingAction !== CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE && !!policy.name && !!policy.id && !!getPolicyRole(policy, currentUserLogin),
(policy): policy is Policy => !!policy && policy.pendingAction !== CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE && !!policy.name && !!policy.id,
);
}
/**
Expand Down Expand Up @@ -638,7 +636,7 @@ function getPolicy(policyID: string | undefined): OnyxEntry<Policy> {

/** Return active policies where current user is an admin */
function getActiveAdminWorkspaces(policies: OnyxCollection<Policy> | null, currentUserLogin: string | undefined): Policy[] {
const activePolicies = getActivePolicies(policies, currentUserLogin);
const activePolicies = getActivePolicies(policies);
return activePolicies.filter((policy) => shouldShowPolicy(policy, NetworkStore.isOffline(), currentUserLogin) && isPolicyAdmin(policy, currentUserLogin));
}

Expand All @@ -654,7 +652,7 @@ function canSendInvoice(policies: OnyxCollection<Policy> | null, currentUserLogi
}

function hasWorkspaceWithInvoices(currentUserLogin: string | undefined): boolean {
const activePolicies = getActivePolicies(allPolicies, currentUserLogin);
const activePolicies = getActivePolicies(allPolicies);
return activePolicies.some((policy) => shouldShowPolicy(policy, NetworkStore.isOffline(), currentUserLogin) && policy.areInvoicesEnabled);
}

Expand Down
4 changes: 2 additions & 2 deletions src/pages/workspace/WorkspaceNewRoomPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,14 @@ function WorkspaceNewRoomPage() {

const workspaceOptions = useMemo(
() =>
PolicyUtils.getActivePolicies(policies, session?.email)
PolicyUtils.getActivePolicies(policies)
?.filter((policy) => policy.type !== CONST.POLICY.TYPE.PERSONAL)
.map((policy) => ({
label: policy.name,
value: policy.id,
}))
.sort((a, b) => localeCompare(a.label, b.label)) ?? [],
[policies, session?.email],
[policies],
);
const [policyID, setPolicyID] = useState<string>(() => {
if (!!activeWorkspaceOrDefaultID && workspaceOptions.some((option) => option.value === activeWorkspaceOrDefaultID)) {
Expand Down
14 changes: 0 additions & 14 deletions tests/unit/PolicyUtilsTest.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,10 @@
import * as PolicyUtils from '@libs/PolicyUtils';
import ONYXKEYS from '@src/ONYXKEYS';
import type {Policy} from '@src/types/onyx';
import createCollection from '../utils/collections/createCollection';
import createRandomPolicy from '../utils/collections/policies';

function toLocaleDigitMock(dot: string): string {
return dot;
}

describe('PolicyUtils', () => {
describe('getActivePolicies', () => {
it("getActivePolicies should filter out policies that the current user doesn't belong to", () => {
const policies = createCollection<Policy>(
(item) => `${ONYXKEYS.COLLECTION.POLICY}${item.id}`,
(index) => ({...createRandomPolicy(index + 1), ...(!index && {role: null})} as Policy),
2,
);
expect(PolicyUtils.getActivePolicies(policies, undefined)).toHaveLength(1);
});
});
describe('getRateDisplayValue', () => {
it('should return an empty string for NaN', () => {
const rate = PolicyUtils.getRateDisplayValue('invalid' as unknown as number, toLocaleDigitMock);
Expand Down

0 comments on commit f0461fb

Please sign in to comment.