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

Deprecate POLICY_MEMBERS #39489

Merged
merged 29 commits into from
Apr 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
d3d4805
Remove policyMembersDraft and policyMembers part-1
ZhenjaHorbach Apr 3, 2024
5e84a32
Remove policyMembersDraft and policyMembers part-2
ZhenjaHorbach Apr 3, 2024
e154c4a
Remove policyMembersDraft and policyMembers part-3
ZhenjaHorbach Apr 3, 2024
72a467f
Remove policyMembers from WorkspaceWorkflowsApproverPage and revert c…
ZhenjaHorbach Apr 6, 2024
224f2b7
Remove policyMembers from ReportScreenIDSetter and refactor PolicyMem…
ZhenjaHorbach Apr 6, 2024
99c6a28
Remove policyMembers from SidebarLinksData
ZhenjaHorbach Apr 6, 2024
23235b6
Remove policyMembers from WorkspaceMembersPage
ZhenjaHorbach Apr 6, 2024
b3cc1d0
Remove POLICY_MEMBERS from utils
ZhenjaHorbach Apr 6, 2024
fbe42b2
Make a little code refactoring
ZhenjaHorbach Apr 6, 2024
51b290c
Fix conflicts and update branch
ZhenjaHorbach Apr 6, 2024
a9c77e9
Fix ts issue
ZhenjaHorbach Apr 6, 2024
1bc67dc
Refactor code and fix some issues
ZhenjaHorbach Apr 6, 2024
afa8239
Update PolicyMembersUtils
ZhenjaHorbach Apr 8, 2024
d682d32
Fix bug with selected item on WorkspaceMemberDetailsRoleSelectionPage
ZhenjaHorbach Apr 8, 2024
2f65c5f
Fix conflicts and update branch
ZhenjaHorbach Apr 8, 2024
657e5ec
Fix comments
ZhenjaHorbach Apr 8, 2024
57ae55d
Fix eslint issues
ZhenjaHorbach Apr 8, 2024
fd47bb4
Fix ts and eslint issues
ZhenjaHorbach Apr 8, 2024
5d8ce6c
Fix conflicts and update branch
ZhenjaHorbach Apr 9, 2024
9809d45
Fix bug and rename policyMembers
ZhenjaHorbach Apr 9, 2024
26c2ab4
Fix conflicts and update branch
ZhenjaHorbach Apr 9, 2024
851ee9b
Fix eslint issue
ZhenjaHorbach Apr 9, 2024
a4c72ec
Fix bug with paddingTop on RoleModal
ZhenjaHorbach Apr 10, 2024
9ab0516
Fix conflicts and update branch
ZhenjaHorbach Apr 14, 2024
2fc2ddd
Fix eslint issue
ZhenjaHorbach Apr 14, 2024
91f9002
Add test for employeeList
ZhenjaHorbach Apr 14, 2024
c72dfe1
Fix conflicts
ZhenjaHorbach Apr 15, 2024
48545bb
Update leaveWorkspace
ZhenjaHorbach Apr 15, 2024
905134e
Fix conflicts and update branch
ZhenjaHorbach Apr 16, 2024
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
6 changes: 1 addition & 5 deletions src/ONYXKEYS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -312,9 +312,7 @@ const ONYXKEYS = {
COLLECTION: {
DOWNLOAD: 'download_',
POLICY: 'policy_',
POLICY_MEMBERS: 'policyMembers_',
POLICY_DRAFTS: 'policyDrafts_',
POLICY_MEMBERS_DRAFTS: 'policyMembersDrafts_',
POLICY_JOIN_MEMBER: 'policyJoinMember_',
POLICY_CATEGORIES: 'policyCategories_',
POLICY_RECENTLY_USED_CATEGORIES: 'policyRecentlyUsedCategories_',
Expand Down Expand Up @@ -526,10 +524,8 @@ type OnyxCollectionValuesMapping = {
[ONYXKEYS.COLLECTION.POLICY_DRAFTS]: OnyxTypes.Policy;
[ONYXKEYS.COLLECTION.POLICY_CATEGORIES]: OnyxTypes.PolicyCategories;
[ONYXKEYS.COLLECTION.POLICY_TAGS]: OnyxTypes.PolicyTagList;
[ONYXKEYS.COLLECTION.POLICY_MEMBERS]: OnyxTypes.PolicyMembers;
[ONYXKEYS.COLLECTION.POLICY_MEMBERS_DRAFTS]: OnyxTypes.PolicyMember;
[ONYXKEYS.COLLECTION.POLICY_RECENTLY_USED_CATEGORIES]: OnyxTypes.RecentlyUsedCategories;
[ONYXKEYS.COLLECTION.DEPRECATED_POLICY_MEMBER_LIST]: OnyxTypes.PolicyMembers;
[ONYXKEYS.COLLECTION.DEPRECATED_POLICY_MEMBER_LIST]: OnyxTypes.PolicyEmployeeList;
[ONYXKEYS.COLLECTION.WORKSPACE_INVITE_MEMBERS_DRAFT]: OnyxTypes.InvitedEmailsToAccountIDs;
[ONYXKEYS.COLLECTION.WORKSPACE_INVITE_MESSAGE_DRAFT]: string;
[ONYXKEYS.COLLECTION.REPORT]: OnyxTypes.Report;
Expand Down
13 changes: 3 additions & 10 deletions src/components/Indicator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,11 @@ import * as PolicyUtils from '@libs/PolicyUtils';
import * as UserUtils from '@libs/UserUtils';
import * as PaymentMethods from '@userActions/PaymentMethods';
import ONYXKEYS from '@src/ONYXKEYS';
import type {BankAccountList, FundList, LoginList, Policy, PolicyMembers, ReimbursementAccount, UserWallet, WalletTerms} from '@src/types/onyx';
import type {BankAccountList, FundList, LoginList, Policy, ReimbursementAccount, UserWallet, WalletTerms} from '@src/types/onyx';

type CheckingMethod = () => boolean;

type IndicatorOnyxProps = {
/** The employee list of all policies (coming from Onyx) */
allPolicyMembers: OnyxCollection<PolicyMembers>;

/** All the user's policies (from Onyx via withFullPolicy) */
policies: OnyxCollection<Policy>;

Expand All @@ -40,14 +37,13 @@ type IndicatorOnyxProps = {

type IndicatorProps = IndicatorOnyxProps;

function Indicator({reimbursementAccount, allPolicyMembers, policies, bankAccountList, fundList, userWallet, walletTerms, loginList}: IndicatorOnyxProps) {
function Indicator({reimbursementAccount, policies, bankAccountList, fundList, userWallet, walletTerms, loginList}: IndicatorOnyxProps) {
const theme = useTheme();
const styles = useThemeStyles();

// If a policy was just deleted from Onyx, then Onyx will pass a null value to the props, and
// those should be cleaned out before doing any error checking
const cleanPolicies = Object.fromEntries(Object.entries(policies ?? {}).filter(([, policy]) => policy?.id));
const cleanAllPolicyMembers = Object.fromEntries(Object.entries(allPolicyMembers ?? {}).filter(([, policyMembers]) => !!policyMembers));

// All of the error & info-checking methods are put into an array. This is so that using _.some() will return
// early as soon as the first error / info condition is returned. This makes the checks very efficient since
Expand All @@ -57,7 +53,7 @@ function Indicator({reimbursementAccount, allPolicyMembers, policies, bankAccoun
() => PaymentMethods.hasPaymentMethodError(bankAccountList, fundList),
() => Object.values(cleanPolicies).some(PolicyUtils.hasPolicyError),
() => Object.values(cleanPolicies).some(PolicyUtils.hasCustomUnitsError),
() => Object.values(cleanAllPolicyMembers).some(PolicyUtils.hasPolicyMemberError),
() => Object.values(cleanPolicies).some(PolicyUtils.hasEmployeeListError),
() => Object.keys(reimbursementAccount?.errors ?? {}).length > 0,
() => !!loginList && UserUtils.hasLoginListError(loginList),

Expand All @@ -77,9 +73,6 @@ function Indicator({reimbursementAccount, allPolicyMembers, policies, bankAccoun
Indicator.displayName = 'Indicator';

export default withOnyx<IndicatorProps, IndicatorOnyxProps>({
allPolicyMembers: {
key: ONYXKEYS.COLLECTION.POLICY_MEMBERS,
},
policies: {
key: ONYXKEYS.COLLECTION.POLICY,
},
Expand Down
21 changes: 10 additions & 11 deletions src/libs/Navigation/AppNavigator/ReportScreenIDSetter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import type {OnyxCollection, OnyxEntry} from 'react-native-onyx';
import {withOnyx} from 'react-native-onyx';
import useActiveWorkspace from '@hooks/useActiveWorkspace';
import usePermissions from '@hooks/usePermissions';
import {getPolicyMembersByIdWithoutCurrentUser} from '@libs/PolicyUtils';
import {getPolicyEmployeeListByIdWithoutCurrentUser} from '@libs/PolicyUtils';
import * as ReportUtils from '@libs/ReportUtils';
import ONYXKEYS from '@src/ONYXKEYS';
import type {Policy, PolicyMembers, Report, ReportMetadata} from '@src/types/onyx';
import type {PersonalDetailsList, Policy, Report, ReportMetadata} from '@src/types/onyx';
import type {ReportScreenWrapperProps} from './ReportScreenWrapper';

type ReportScreenIDSetterComponentProps = {
Expand All @@ -16,8 +16,8 @@ type ReportScreenIDSetterComponentProps = {
/** The policies which the user has access to */
policies: OnyxCollection<Policy>;

/** Members of all the workspaces the user is member of */
policyMembers: OnyxCollection<PolicyMembers>;
/** The personal details of the person who is logged in */
personalDetails: OnyxEntry<PersonalDetailsList>;

/** Whether user is a new user */
isFirstTimeNewExpensifyUser: OnyxEntry<boolean>;
Expand Down Expand Up @@ -58,7 +58,7 @@ const getLastAccessedReportID = (
};

// This wrapper is reponsible for opening the last accessed report if there is no reportID specified in the route params
function ReportScreenIDSetter({route, reports, policies, policyMembers = {}, navigation, isFirstTimeNewExpensifyUser = false, reportMetadata, accountID}: ReportScreenIDSetterProps) {
function ReportScreenIDSetter({route, reports, policies, navigation, isFirstTimeNewExpensifyUser = false, reportMetadata, accountID, personalDetails}: ReportScreenIDSetterProps) {
const {canUseDefaultRooms} = usePermissions();
const {activeWorkspaceID} = useActiveWorkspace();

Expand All @@ -73,7 +73,7 @@ function ReportScreenIDSetter({route, reports, policies, policyMembers = {}, nav
return;
}

const policyMemberAccountIDs = getPolicyMembersByIdWithoutCurrentUser(policyMembers, activeWorkspaceID, accountID);
const policyMemberAccountIDs = getPolicyEmployeeListByIdWithoutCurrentUser(policies, activeWorkspaceID, accountID);

// If there is no reportID in route, try to find last accessed and use it for setParams
const reportID = getLastAccessedReportID(
Expand All @@ -92,7 +92,7 @@ function ReportScreenIDSetter({route, reports, policies, policyMembers = {}, nav
if (reportID) {
navigation.setParams({reportID: String(reportID)});
}
}, [route, navigation, reports, canUseDefaultRooms, policies, isFirstTimeNewExpensifyUser, reportMetadata, activeWorkspaceID, policyMembers, accountID]);
}, [route, navigation, reports, canUseDefaultRooms, policies, isFirstTimeNewExpensifyUser, reportMetadata, activeWorkspaceID, personalDetails, accountID]);

// The ReportScreen without the reportID set will display a skeleton
// until the reportID is loaded and set in the route param
Expand All @@ -110,10 +110,6 @@ export default withOnyx<ReportScreenIDSetterProps, ReportScreenIDSetterComponent
key: ONYXKEYS.COLLECTION.POLICY,
allowStaleData: true,
},
policyMembers: {
key: ONYXKEYS.COLLECTION.POLICY_MEMBERS,
allowStaleData: true,
},
isFirstTimeNewExpensifyUser: {
key: ONYXKEYS.NVP_IS_FIRST_TIME_NEW_EXPENSIFY_USER,
initialValue: false,
Expand All @@ -126,4 +122,7 @@ export default withOnyx<ReportScreenIDSetterProps, ReportScreenIDSetterComponent
key: ONYXKEYS.SESSION,
selector: (session) => session?.accountID,
},
personalDetails: {
key: ONYXKEYS.PERSONAL_DETAILS_LIST,
},
})(ReportScreenIDSetter);
4 changes: 2 additions & 2 deletions src/libs/Navigation/dismissModalWithReport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type {NavigationContainerRef} from '@react-navigation/native';
import {StackActions} from '@react-navigation/native';
import {findLastIndex} from 'lodash';
import Log from '@libs/Log';
import getPolicyMemberAccountIDs from '@libs/PolicyMembersUtils';
import getPolicyEmployeeAccountIDs from '@libs/PolicyEmployeeListUtils';
import {doesReportBelongToWorkspace} from '@libs/ReportUtils';
import NAVIGATORS from '@src/NAVIGATORS';
import ROUTES from '@src/ROUTES';
Expand Down Expand Up @@ -47,7 +47,7 @@ function dismissModalWithReport(targetReport: Report | EmptyObject, navigationRe
if (targetReport.reportID !== getTopmostReportId(state)) {
const reportState = getStateFromPath(ROUTES.REPORT_WITH_ID.getRoute(targetReport.reportID));
const policyID = getPolicyIDFromState(state as State<RootStackParamList>);
const policyMemberAccountIDs = getPolicyMemberAccountIDs(policyID);
const policyMemberAccountIDs = getPolicyEmployeeAccountIDs(policyID);
const shouldOpenAllWorkspace = isEmptyObject(targetReport) ? true : !doesReportBelongToWorkspace(targetReport, policyMemberAccountIDs, policyID);

if (shouldOpenAllWorkspace) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as OnyxUpdates from '@libs/actions/OnyxUpdates';
import * as ActiveClientManager from '@libs/ActiveClientManager';
import Log from '@libs/Log';
import Navigation from '@libs/Navigation/Navigation';
import getPolicyMemberAccountIDs from '@libs/PolicyMembersUtils';
import getPolicyEmployeeAccountIDs from '@libs/PolicyEmployeeListUtils';
import {extractPolicyIDFromPath} from '@libs/PolicyUtils';
import {doesReportBelongToWorkspace, getReport} from '@libs/ReportUtils';
import Visibility from '@libs/Visibility';
Expand Down Expand Up @@ -65,9 +65,9 @@ export default function subscribeToReportCommentPushNotifications() {

const policyID = lastVisitedPath && extractPolicyIDFromPath(lastVisitedPath);
const report = getReport(reportID.toString());
const policyMembersAccountIDs = policyID ? getPolicyMemberAccountIDs(policyID) : [];
const policyEmployeeAccountIDs = policyID ? getPolicyEmployeeAccountIDs(policyID) : [];

const reportBelongsToWorkspace = policyID && !isEmptyObject(report) && doesReportBelongToWorkspace(report, policyMembersAccountIDs, policyID);
const reportBelongsToWorkspace = policyID && !isEmptyObject(report) && doesReportBelongToWorkspace(report, policyEmployeeAccountIDs, policyID);

Log.info('[PushNotification] onSelected() - called', false, {reportID, reportActionID});
Navigation.isNavigationReady()
Expand Down
25 changes: 25 additions & 0 deletions src/libs/PolicyEmployeeListUtils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import type {OnyxCollection} from 'react-native-onyx';
import Onyx from 'react-native-onyx';
import ONYXKEYS from '@src/ONYXKEYS';
import type {Policy} from '@src/types/onyx';
import {getCurrentUserAccountID} from './actions/Report';
import {getPolicyEmployeeListByIdWithoutCurrentUser} from './PolicyUtils';

let allPolicies: OnyxCollection<Policy> = {};
Onyx.connect({
key: ONYXKEYS.COLLECTION.POLICY,
waitForCollectionCallback: true,
callback: (value) => (allPolicies = value),
});

function getPolicyEmployeeAccountIDs(policyID?: string) {
if (!policyID) {
return [];
}

const currentUserAccountID = getCurrentUserAccountID();

return getPolicyEmployeeListByIdWithoutCurrentUser(allPolicies, policyID, currentUserAccountID);
}

export default getPolicyEmployeeAccountIDs;
25 changes: 0 additions & 25 deletions src/libs/PolicyMembersUtils.ts

This file was deleted.

Loading
Loading