Skip to content

Commit

Permalink
Merge pull request #43975 from daledah/fix/43623
Browse files Browse the repository at this point in the history
Fix: Workspace member has option to edit categories
  • Loading branch information
neil-marcellini authored Jul 15, 2024
2 parents 7468c85 + 4c80b47 commit c7af580
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
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 @@ -1813,6 +1822,7 @@ function getOptions(
recentlyUsedPolicyReportFieldOptions = [],
includeInvoiceRooms = false,
includeDomainEmail = false,
action,
}: GetOptionsConfig,
): Options {
if (includeCategories) {
Expand Down Expand Up @@ -2052,7 +2062,14 @@ function getOptions(

reportOption.isSelected = isReportSelected(reportOption, selectedOptions);

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);
}

// 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 @@ -2215,6 +2232,7 @@ function getFilteredOptions(
policyReportFieldOptions: string[] = [],
recentlyUsedPolicyReportFieldOptions: string[] = [],
includeInvoiceRooms = false,
action: IOUAction | undefined = undefined,
) {
return getOptions(
{reports, personalDetails},
Expand Down Expand Up @@ -2242,6 +2260,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

0 comments on commit c7af580

Please sign in to comment.