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
21 changes: 20 additions & 1 deletion 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 @@ -277,6 +279,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 @@ -1806,6 +1815,7 @@ function getOptions(
recentlyUsedPolicyReportFieldOptions = [],
includeInvoiceRooms = false,
includeDomainEmail = false,
action,
}: GetOptionsConfig,
): Options {
if (includeCategories) {
Expand Down Expand Up @@ -2045,7 +2055,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 @@ -2208,6 +2225,7 @@ function getFilteredOptions(
policyReportFieldOptions: string[] = [],
recentlyUsedPolicyReportFieldOptions: string[] = [],
includeInvoiceRooms = false,
action: IOUAction | undefined = undefined,
) {
return getOptions(
{reports, personalDetails},
Expand Down Expand Up @@ -2235,6 +2253,7 @@ function getFilteredOptions(
policyReportFieldOptions,
recentlyUsedPolicyReportFieldOptions,
includeInvoiceRooms,
action,
},
);
}
Expand Down
13 changes: 12 additions & 1 deletion src/pages/iou/request/MoneyRequestParticipantsSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ function MoneyRequestParticipantsSelector({participants = CONST.EMPTY_ARRAY, onF
undefined,
undefined,
iouType === CONST.IOU.TYPE.INVOICE,
action,
);

return optionList;
Expand Down Expand Up @@ -219,7 +220,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