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: Workspace member has option to edit categories #43975

Merged
merged 16 commits into from
Jul 15, 2024
Merged
23 changes: 20 additions & 3 deletions src/libs/OptionsListUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import Onyx from 'react-native-onyx';
import type {OnyxCollection, OnyxEntry} from 'react-native-onyx';
import {FallbackAvatar} from '@components/Icon/Expensicons';
import type {SelectedTagOption} from '@components/TagPicker';
import type {IOUAction} from '@src/CONST';
import CONST from '@src/CONST';
import type {TranslationPaths} from '@src/languages/types';
import ONYXKEYS from '@src/ONYXKEYS';
Expand Down Expand Up @@ -177,6 +178,7 @@ type GetOptionsConfig = {
transactionViolations?: OnyxCollection<TransactionViolation[]>;
includeInvoiceRooms?: boolean;
includeDomainEmail?: boolean;
action?: IOUAction;
};

type GetUserToInviteConfig = {
Expand Down Expand Up @@ -273,6 +275,13 @@ Onyx.connect({
},
});

let allPolicyCategories: OnyxCollection<PolicyCategories> = {};
Onyx.connect({
key: ONYXKEYS.COLLECTION.POLICY_CATEGORIES,
waitForCollectionCallback: true,
callback: (val) => (allPolicyCategories = val),
});

const lastReportActions: ReportActions = {};
const allSortedReportActions: Record<string, ReportAction[]> = {};
let allReportActions: OnyxCollection<ReportActions>;
Expand Down Expand Up @@ -1802,6 +1811,7 @@ function getOptions(
recentlyUsedPolicyReportFieldOptions = [],
includeInvoiceRooms = false,
includeDomainEmail = false,
action,
}: GetOptionsConfig,
): Options {
if (includeCategories) {
Expand Down Expand Up @@ -2040,8 +2050,14 @@ function getOptions(
}

reportOption.isSelected = isReportSelected(reportOption, selectedOptions);

daledah marked this conversation as resolved.
Show resolved Hide resolved
recentReportOptions.push(reportOption);
if (action === CONST.IOU.ACTION.CATEGORIZE) {
const policyCategories = allPolicyCategories?.[`${ONYXKEYS.COLLECTION.POLICY_CATEGORIES}${reportOption.policyID}`] ?? {};
if (getEnabledCategoriesCount(policyCategories) !== 0) {
recentReportOptions.push(reportOption);
}
} else {
recentReportOptions.push(reportOption);
}
neil-marcellini marked this conversation as resolved.
Show resolved Hide resolved

// Add this login to the exclude list so it won't appear when we process the personal details
if (reportOption.login) {
Expand Down Expand Up @@ -2098,7 +2114,6 @@ function getOptions(
personalDetailsOptions = [];
recentReportOptions = orderOptions(recentReportOptions, searchValue, {preferChatroomsOverThreads: true});
}

daledah marked this conversation as resolved.
Show resolved Hide resolved
return {
personalDetails: personalDetailsOptions,
recentReports: recentReportOptions,
Expand Down Expand Up @@ -2204,6 +2219,7 @@ function getFilteredOptions(
policyReportFieldOptions: string[] = [],
recentlyUsedPolicyReportFieldOptions: string[] = [],
includeInvoiceRooms = false,
action: IOUAction | undefined = undefined,
) {
return getOptions(
{reports, personalDetails},
Expand Down Expand Up @@ -2231,6 +2247,7 @@ function getFilteredOptions(
policyReportFieldOptions,
recentlyUsedPolicyReportFieldOptions,
includeInvoiceRooms,
action,
},
);
}
Expand Down
15 changes: 12 additions & 3 deletions src/pages/iou/request/MoneyRequestParticipantsSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ function MoneyRequestParticipantsSelector({participants = CONST.EMPTY_ARRAY, onF

const isIOUSplit = iouType === CONST.IOU.TYPE.SPLIT;
const isCategorizeOrShareAction = [CONST.IOU.ACTION.CATEGORIZE, CONST.IOU.ACTION.SHARE].some((option) => option === action);

daledah marked this conversation as resolved.
Show resolved Hide resolved
const shouldShowReferralBanner = !isDismissed && iouType !== CONST.IOU.TYPE.INVOICE;

useEffect(() => {
Expand Down Expand Up @@ -124,6 +123,7 @@ function MoneyRequestParticipantsSelector({participants = CONST.EMPTY_ARRAY, onF
undefined,
undefined,
iouType === CONST.IOU.TYPE.INVOICE,
action,
);

return optionList;
Expand Down Expand Up @@ -210,7 +210,6 @@ function MoneyRequestParticipantsSelector({participants = CONST.EMPTY_ARRAY, onF
shouldShow: true,
});
}

daledah marked this conversation as resolved.
Show resolved Hide resolved
const headerMessage = OptionsListUtils.getHeaderMessage(
(chatOptions.personalDetails ?? []).length + (chatOptions.recentReports ?? []).length !== 0,
!!chatOptions?.userToInvite,
Expand All @@ -219,7 +218,17 @@ function MoneyRequestParticipantsSelector({participants = CONST.EMPTY_ARRAY, onF
);

return [newSections, headerMessage];
}, [debouncedSearchTerm, chatOptions, areOptionsInitialized, didScreenTransitionEnd, participants, personalDetails, translate]);
}, [
areOptionsInitialized,
didScreenTransitionEnd,
debouncedSearchTerm,
participants,
chatOptions.recentReports,
chatOptions.personalDetails,
chatOptions.userToInvite,
personalDetails,
translate,
]);

/**
* Adds a single participant to the expense
Expand Down
Loading