Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
16 changes: 8 additions & 8 deletions src/libs/TagsOptionsListUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,14 @@ function getTagListSections({
return tagSections;
}

if (numberOfTags < CONST.STANDARD_LIST_ITEM_LIMIT) {
const filteredRecentlyUsedTags = recentlyUsedTags
.filter((recentlyUsedTag) => {
const tagObject = sortedTags.find((tag) => tag.name === recentlyUsedTag);
return !!tagObject?.enabled && !selectedOptionNames.has(recentlyUsedTag) && tagObject?.pendingAction !== CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE;
})
.map((tag) => ({name: tag, enabled: true}));

if (numberOfTags < CONST.STANDARD_LIST_ITEM_LIMIT && filteredRecentlyUsedTags.length === 0) {
tagSections.push({
// "All" section when items amount less than the threshold
title: '',
Expand All @@ -138,13 +145,6 @@ function getTagListSections({
return tagSections;
}

const filteredRecentlyUsedTags = recentlyUsedTags
.filter((recentlyUsedTag) => {
const tagObject = sortedTags.find((tag) => tag.name === recentlyUsedTag);
return !!tagObject?.enabled && !selectedOptionNames.has(recentlyUsedTag) && tagObject?.pendingAction !== CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE;
})
.map((tag) => ({name: tag, enabled: true}));

if (selectedOptions.length) {
tagSections.push({
// "Selected" section
Expand Down
25 changes: 21 additions & 4 deletions src/libs/actions/IOU/TrackExpense.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ import {clearByKey as clearPdfByOnyxKey} from '@userActions/CachedPDFPaths';
import {buildAddMembersToWorkspaceOnyxData, buildUpdateWorkspaceMembersRoleOnyxData} from '@userActions/Policy/Member';
import {buildPolicyData} from '@userActions/Policy/Policy';
import type {BuildPolicyDataKeys} from '@userActions/Policy/Policy';
import {buildOptimisticPolicyRecentlyUsedTags} from '@userActions/Policy/Tag';
import type {GuidedSetupData} from '@userActions/Report';
import {buildInviteToRoomOnyxData, notifyNewAction} from '@userActions/Report';
import {stringifyWaypointsForAPI} from '@userActions/Transaction';
Expand Down Expand Up @@ -146,7 +147,7 @@ type TrackExpenseInformation = {
actionableWhisperReportActionIDParam?: string;
optimisticReportID: string | undefined;
optimisticReportActionID: string | undefined;
onyxData: OnyxData<BuildOnyxDataForTrackExpenseKeys | BuildPolicyDataKeys | typeof ONYXKEYS.SELF_DM_REPORT_ID>;
onyxData: OnyxData<BuildOnyxDataForTrackExpenseKeys | BuildPolicyDataKeys | typeof ONYXKEYS.SELF_DM_REPORT_ID | typeof ONYXKEYS.COLLECTION.POLICY_RECENTLY_USED_TAGS>;
};

type GetTrackExpenseInformationTransactionParams = {
Expand Down Expand Up @@ -835,7 +836,7 @@ function getTrackExpenseInformation(params: GetTrackExpenseInformationParams): T
defaultWorkspaceName,
} = params;
const {payeeAccountID = getUserAccountID(), payeeEmail = getCurrentUserEmail(), participant} = participantParams;
const {policy} = policyParams;
const {policy, policyTagList, policyRecentlyUsedTags} = policyParams;
const {
comment,
amount,
Expand All @@ -858,7 +859,7 @@ function getTrackExpenseInformation(params: GetTrackExpenseInformationParams): T
gpsCoordinates,
} = transactionParams;

const onyxData: OnyxData<BuildOnyxDataForTrackExpenseKeys | BuildPolicyDataKeys | typeof ONYXKEYS.SELF_DM_REPORT_ID> = {
const onyxData: OnyxData<BuildOnyxDataForTrackExpenseKeys | BuildPolicyDataKeys | typeof ONYXKEYS.SELF_DM_REPORT_ID | typeof ONYXKEYS.COLLECTION.POLICY_RECENTLY_USED_TAGS> = {
optimisticData: [],
successData: [],
failureData: [],
Expand Down Expand Up @@ -1144,6 +1145,20 @@ function getTrackExpenseInformation(params: GetTrackExpenseInformationParams): T
onyxData.successData?.push(...(trackExpenseOnyxData.successData ?? []));
onyxData.failureData?.push(...(trackExpenseOnyxData.failureData ?? []));

const optimisticPolicyRecentlyUsedTags = buildOptimisticPolicyRecentlyUsedTags({
policyTags: policyTagList ?? {},
policyRecentlyUsedTags,
transactionTags: tag,
});

if (!isEmptyObject(optimisticPolicyRecentlyUsedTags) && chatReport?.policyID) {
onyxData.optimisticData?.push({
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.POLICY_RECENTLY_USED_TAGS}${chatReport.policyID}`,
value: optimisticPolicyRecentlyUsedTags,
});
}

return {
createdWorkspaceParams,
chatReport,
Expand Down Expand Up @@ -2151,6 +2166,7 @@ function shareTrackedExpense(trackedExpenseParams: TrackedExpenseParams) {
| typeof ONYXKEYS.NVP_LAST_DISTANCE_EXPENSE_TYPE
| typeof ONYXKEYS.GPS_DRAFT_DETAILS
| typeof ONYXKEYS.SELF_DM_REPORT_ID
| typeof ONYXKEYS.COLLECTION.POLICY_RECENTLY_USED_TAGS
> = {
optimisticData: trackedExpenseOnyxData?.optimisticData ?? [],
successData: trackedExpenseOnyxData?.successData ?? [],
Expand Down Expand Up @@ -2281,7 +2297,7 @@ function trackExpense(params: CreateTrackExpenseParams) {
defaultWorkspaceName,
} = params;
const {participant, payeeAccountID, payeeEmail} = participantParams;
const {policy, policyCategories, policyTagList} = policyData;
const {policy, policyCategories, policyTagList, policyRecentlyUsedTags} = policyData;
const parsedComment = getParsedComment(transactionData.comment ?? '');
transactionData.comment = parsedComment;
const {
Expand Down Expand Up @@ -2409,6 +2425,7 @@ function trackExpense(params: CreateTrackExpenseParams) {
policy,
policyCategories,
policyTagList,
policyRecentlyUsedTags,
},
retryParams,
isASAPSubmitBetaEnabled,
Expand Down
1 change: 1 addition & 0 deletions src/libs/actions/IOU/types/TrackedExpenseParams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ type TrackedExpenseParams = {
| typeof ONYXKEYS.NVP_LAST_DISTANCE_EXPENSE_TYPE
| typeof ONYXKEYS.GPS_DRAFT_DETAILS
| typeof ONYXKEYS.SELF_DM_REPORT_ID
| typeof ONYXKEYS.COLLECTION.POLICY_RECENTLY_USED_TAGS
>;
reportInformation: TrackedExpenseReportInformation;
transactionParams: TrackedExpenseTransactionParams;
Expand Down
2 changes: 1 addition & 1 deletion src/pages/Share/SubmitDetailsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ function SubmitDetailsPage({
report: report ?? {reportID: reportOrAccountID},
isDraftPolicy: false,
participantParams: {payeeEmail: currentUserPersonalDetails.login, payeeAccountID: currentUserPersonalDetails.accountID, participant},
policyParams: {policy, policyTagList: policyTags, policyCategories},
policyParams: {policy, policyTagList: policyTags, policyCategories, policyRecentlyUsedTags},
action: CONST.IOU.TYPE.CREATE,
transactionParams: {
attendees: transaction.comment?.attendees,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,7 @@ function useExpenseSubmission(params: UseExpenseSubmissionParams) {
policy,
policyCategories,
policyTagList: policyTags,
policyRecentlyUsedTags,
},
transactionParams: {
amount: item.amount,
Expand Down
Loading