From 417a816e4b346ec8a692b754e610185db918ab29 Mon Sep 17 00:00:00 2001 From: tienifr Date: Tue, 18 Jul 2023 15:58:24 +0700 Subject: [PATCH 1/5] policy: change filter rule to include pending delete workspace --- src/libs/PolicyUtils.js | 10 ++++++++++ .../SidebarScreen/FloatingActionButtonAndPopover.js | 4 +++- src/pages/workspace/WorkspaceNewRoomPage.js | 3 ++- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/libs/PolicyUtils.js b/src/libs/PolicyUtils.js index cd15ea19a160..6465fdb93048 100644 --- a/src/libs/PolicyUtils.js +++ b/src/libs/PolicyUtils.js @@ -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 the pending delete policies + * @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'}]}, ...} @@ -134,6 +143,7 @@ function getClientPolicyMemberEmailsToAccountIDs(policyMembers, personalDetails) } export { + getActivePolicies, hasPolicyMemberError, hasPolicyError, hasPolicyErrorFields, diff --git a/src/pages/home/sidebar/SidebarScreen/FloatingActionButtonAndPopover.js b/src/pages/home/sidebar/SidebarScreen/FloatingActionButtonAndPopover.js index 3e95818c1137..fe8edbc11307 100644 --- a/src/pages/home/sidebar/SidebarScreen/FloatingActionButtonAndPopover.js +++ b/src/pages/home/sidebar/SidebarScreen/FloatingActionButtonAndPopover.js @@ -12,6 +12,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'; @@ -35,6 +36,7 @@ const policySelector = (policy) => policy && { type: policy.type, role: policy.role, + pendingAction: policy.pendingAction, }; const propTypes = { @@ -172,7 +174,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.policy); return ( diff --git a/src/pages/workspace/WorkspaceNewRoomPage.js b/src/pages/workspace/WorkspaceNewRoomPage.js index db010429980a..58d6ce72f1f0 100644 --- a/src/pages/workspace/WorkspaceNewRoomPage.js +++ b/src/pages/workspace/WorkspaceNewRoomPage.js @@ -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'; @@ -110,7 +111,7 @@ function WorkspaceNewRoomPage(props) { const workspaceOptions = useMemo( () => _.map( - _.filter(props.policies, (policy) => policy && policy.type === CONST.POLICY.TYPE.FREE), + PolicyUtils.getActivePolicies(props.policy), (policy) => ({label: policy.name, key: policy.id, value: policy.id}), ), [props.policies], From 3bca95d492f7fd3909af0b16cafa4e27ee8318bf Mon Sep 17 00:00:00 2001 From: tienifr Date: Tue, 18 Jul 2023 16:31:55 +0700 Subject: [PATCH 2/5] correct variable name --- .../sidebar/SidebarScreen/FloatingActionButtonAndPopover.js | 4 ++-- src/pages/workspace/WorkspaceNewRoomPage.js | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/pages/home/sidebar/SidebarScreen/FloatingActionButtonAndPopover.js b/src/pages/home/sidebar/SidebarScreen/FloatingActionButtonAndPopover.js index fe8edbc11307..eb2bd85878e4 100644 --- a/src/pages/home/sidebar/SidebarScreen/FloatingActionButtonAndPopover.js +++ b/src/pages/home/sidebar/SidebarScreen/FloatingActionButtonAndPopover.js @@ -173,8 +173,8 @@ function FloatingActionButtonAndPopover(props) { }, })); - // Workspaces are policies with type === 'free' - const workspaces = PolicyUtils.getActivePolicies(props.policy); + // Workspaces are policies with type === 'free' and is not pending delete + const workspaces = PolicyUtils.getActivePolicies(props.allPolicies); return ( diff --git a/src/pages/workspace/WorkspaceNewRoomPage.js b/src/pages/workspace/WorkspaceNewRoomPage.js index 58d6ce72f1f0..54ada203b023 100644 --- a/src/pages/workspace/WorkspaceNewRoomPage.js +++ b/src/pages/workspace/WorkspaceNewRoomPage.js @@ -107,11 +107,11 @@ function WorkspaceNewRoomPage(props) { [props.reports], ); - // Workspaces are policies with type === 'free' + // Workspaces are policies with type === 'free' and is not pending delete const workspaceOptions = useMemo( () => _.map( - PolicyUtils.getActivePolicies(props.policy), + PolicyUtils.getActivePolicies(props.policies), (policy) => ({label: policy.name, key: policy.id, value: policy.id}), ), [props.policies], From 9fd088cc45002ee6136c770f10eb72f52406a51a Mon Sep 17 00:00:00 2001 From: tienifr Date: Tue, 18 Jul 2023 16:36:32 +0700 Subject: [PATCH 3/5] fix lint --- .../home/sidebar/SidebarScreen/FloatingActionButtonAndPopover.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/pages/home/sidebar/SidebarScreen/FloatingActionButtonAndPopover.js b/src/pages/home/sidebar/SidebarScreen/FloatingActionButtonAndPopover.js index eb2bd85878e4..0e4f649ca488 100644 --- a/src/pages/home/sidebar/SidebarScreen/FloatingActionButtonAndPopover.js +++ b/src/pages/home/sidebar/SidebarScreen/FloatingActionButtonAndPopover.js @@ -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'; From 3dde6d28d654810457c6f3881af84cc7f54a928f Mon Sep 17 00:00:00 2001 From: tienifr Date: Tue, 18 Jul 2023 16:43:43 +0700 Subject: [PATCH 4/5] fix lint: prettier --- src/libs/PolicyUtils.js | 2 +- src/pages/workspace/WorkspaceNewRoomPage.js | 9 +-------- 2 files changed, 2 insertions(+), 9 deletions(-) diff --git a/src/libs/PolicyUtils.js b/src/libs/PolicyUtils.js index 6465fdb93048..8a9434b41273 100644 --- a/src/libs/PolicyUtils.js +++ b/src/libs/PolicyUtils.js @@ -6,7 +6,7 @@ import ONYXKEYS from '../ONYXKEYS'; /** * Filter out the active policies, which will exclude the pending delete policies - * @param {Object} policies + * @param {Object} policies * @returns {Array} */ function getActivePolicies(policies) { diff --git a/src/pages/workspace/WorkspaceNewRoomPage.js b/src/pages/workspace/WorkspaceNewRoomPage.js index 54ada203b023..5699c3a5678e 100644 --- a/src/pages/workspace/WorkspaceNewRoomPage.js +++ b/src/pages/workspace/WorkspaceNewRoomPage.js @@ -108,14 +108,7 @@ function WorkspaceNewRoomPage(props) { ); // Workspaces are policies with type === 'free' and is not pending delete - const workspaceOptions = useMemo( - () => - _.map( - PolicyUtils.getActivePolicies(props.policies), - (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( () => From d3f3b25ad4008a2c29694e54f1a81e0046745b2e Mon Sep 17 00:00:00 2001 From: tienifr Date: Wed, 19 Jul 2023 15:08:06 +0700 Subject: [PATCH 5/5] refactor comment --- src/libs/PolicyUtils.js | 2 +- .../sidebar/SidebarScreen/FloatingActionButtonAndPopover.js | 1 - src/pages/workspace/WorkspaceNewRoomPage.js | 1 - 3 files changed, 1 insertion(+), 3 deletions(-) diff --git a/src/libs/PolicyUtils.js b/src/libs/PolicyUtils.js index 8a9434b41273..d7a4c4fdff45 100644 --- a/src/libs/PolicyUtils.js +++ b/src/libs/PolicyUtils.js @@ -5,7 +5,7 @@ import CONST from '../CONST'; import ONYXKEYS from '../ONYXKEYS'; /** - * Filter out the active policies, which will exclude the pending delete policies + * Filter out the active policies, which will exclude policies with pending deletion * @param {Object} policies * @returns {Array} */ diff --git a/src/pages/home/sidebar/SidebarScreen/FloatingActionButtonAndPopover.js b/src/pages/home/sidebar/SidebarScreen/FloatingActionButtonAndPopover.js index 0e4f649ca488..24c00a7af405 100644 --- a/src/pages/home/sidebar/SidebarScreen/FloatingActionButtonAndPopover.js +++ b/src/pages/home/sidebar/SidebarScreen/FloatingActionButtonAndPopover.js @@ -172,7 +172,6 @@ function FloatingActionButtonAndPopover(props) { }, })); - // Workspaces are policies with type === 'free' and is not pending delete const workspaces = PolicyUtils.getActivePolicies(props.allPolicies); return ( diff --git a/src/pages/workspace/WorkspaceNewRoomPage.js b/src/pages/workspace/WorkspaceNewRoomPage.js index 5699c3a5678e..104270d22976 100644 --- a/src/pages/workspace/WorkspaceNewRoomPage.js +++ b/src/pages/workspace/WorkspaceNewRoomPage.js @@ -107,7 +107,6 @@ function WorkspaceNewRoomPage(props) { [props.reports], ); - // Workspaces are policies with type === 'free' and is not pending delete const workspaceOptions = useMemo(() => _.map(PolicyUtils.getActivePolicies(props.policies), (policy) => ({label: policy.name, key: policy.id, value: policy.id})), [props.policies]); const visibilityOptions = useMemo(