Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix 22745: change filter rule to exclude pending delete workspace #23064

Merged
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
10 changes: 10 additions & 0 deletions src/libs/PolicyUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@ import Str from 'expensify-common/lib/str';
import CONST from '../CONST';
import ONYXKEYS from '../ONYXKEYS';

/**
* Filter out the active policies, which will exclude policies with pending deletion
* @param {Object} policies
* @returns {Array}
*/
function getActivePolicies(policies) {
return _.filter(policies, (policy) => policy && policy.type === CONST.POLICY.TYPE.FREE && policy.pendingAction !== CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE);
}

/**
* Checks if we have any errors stored within the POLICY_MEMBERS. Determines whether we should show a red brick road error or not.
* Data structure: {accountID: {role:'user', errors: []}, accountID2: {role:'admin', errors: [{1231312313: 'Unable to do X'}]}, ...}
Expand Down Expand Up @@ -134,6 +143,7 @@ function getClientPolicyMemberEmailsToAccountIDs(policyMembers, personalDetails)
}

export {
getActivePolicies,
hasPolicyMemberError,
hasPolicyError,
hasPolicyErrorFields,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import React, {useState, useEffect, useCallback, useImperativeHandle, forwardRef} from 'react';
import _ from 'underscore';
import {withOnyx} from 'react-native-onyx';
import PropTypes from 'prop-types';
import lodashGet from 'lodash/get';
Expand All @@ -12,6 +11,7 @@ import NAVIGATORS from '../../../../NAVIGATORS';
import SCREENS from '../../../../SCREENS';
import Permissions from '../../../../libs/Permissions';
import * as Policy from '../../../../libs/actions/Policy';
import * as PolicyUtils from '../../../../libs/PolicyUtils';
import PopoverMenu from '../../../../components/PopoverMenu';
import CONST from '../../../../CONST';
import FloatingActionButton from '../../../../components/FloatingActionButton';
Expand All @@ -35,6 +35,7 @@ const policySelector = (policy) =>
policy && {
type: policy.type,
role: policy.role,
pendingAction: policy.pendingAction,
};

const propTypes = {
Expand Down Expand Up @@ -171,8 +172,7 @@ function FloatingActionButtonAndPopover(props) {
},
}));

// Workspaces are policies with type === 'free'
const workspaces = _.filter(props.allPolicies, (policy) => policy && policy.type === CONST.POLICY.TYPE.FREE);
const workspaces = PolicyUtils.getActivePolicies(props.allPolicies);

return (
<View>
Expand Down
11 changes: 2 additions & 9 deletions src/pages/workspace/WorkspaceNewRoomPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import Permissions from '../../libs/Permissions';
import Log from '../../libs/Log';
import * as ErrorUtils from '../../libs/ErrorUtils';
import * as ValidationUtils from '../../libs/ValidationUtils';
import * as PolicyUtils from '../../libs/PolicyUtils';
import Form from '../../components/Form';
import shouldDelayFocus from '../../libs/shouldDelayFocus';
import policyMemberPropType from '../policyMemberPropType';
Expand Down Expand Up @@ -106,15 +107,7 @@ function WorkspaceNewRoomPage(props) {
[props.reports],
);

// Workspaces are policies with type === 'free'
const workspaceOptions = useMemo(
() =>
_.map(
_.filter(props.policies, (policy) => policy && policy.type === CONST.POLICY.TYPE.FREE),
(policy) => ({label: policy.name, key: policy.id, value: policy.id}),
),
[props.policies],
);
const workspaceOptions = useMemo(() => _.map(PolicyUtils.getActivePolicies(props.policies), (policy) => ({label: policy.name, key: policy.id, value: policy.id})), [props.policies]);

const visibilityOptions = useMemo(
() =>
Expand Down