Skip to content

Commit

Permalink
Merge pull request #38988 from tienifr/fix/37783
Browse files Browse the repository at this point in the history
fix: tag name in RHP is not correct
  • Loading branch information
NikkiWines authored Apr 11, 2024
2 parents 2e1dd1d + 20d8344 commit 0cc3743
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 14 deletions.
6 changes: 3 additions & 3 deletions src/ROUTES.ts
Original file line number Diff line number Diff line change
Expand Up @@ -369,16 +369,16 @@ const ROUTES = {
getUrlWithBackToParam(`${action}/${iouType}/scan/${transactionID}/${reportID}`, backTo),
},
MONEY_REQUEST_STEP_TAG: {
route: ':action/:iouType/tag/:tagIndex/:transactionID/:reportID/:reportActionID?',
route: ':action/:iouType/tag/:orderWeight/:transactionID/:reportID/:reportActionID?',
getRoute: (
action: ValueOf<typeof CONST.IOU.ACTION>,
iouType: ValueOf<typeof CONST.IOU.TYPE>,
tagIndex: number,
orderWeight: number,
transactionID: string,
reportID: string,
backTo = '',
reportActionID?: string,
) => getUrlWithBackToParam(`${action}/${iouType}/tag/${tagIndex}/${transactionID}/${reportID}${reportActionID ? `/${reportActionID}` : ''}`, backTo),
) => getUrlWithBackToParam(`${action}/${iouType}/tag/${orderWeight}/${transactionID}/${reportID}${reportActionID ? `/${reportActionID}` : ''}`, backTo),
},
MONEY_REQUEST_STEP_WAYPOINT: {
route: ':action/:iouType/waypoint/:transactionID/:reportID/:pageIndex',
Expand Down
4 changes: 2 additions & 2 deletions src/components/ReportActionItem/MoneyRequestView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ function MoneyRequestView({
</OfflineWithFeedback>
)}
{shouldShowTag &&
policyTagLists.map(({name}, index) => (
policyTagLists.map(({name, orderWeight}, index) => (
<OfflineWithFeedback
key={name}
pendingAction={getPendingFieldAction('tag')}
Expand All @@ -421,7 +421,7 @@ function MoneyRequestView({
titleStyle={styles.flex1}
onPress={() =>
Navigation.navigate(
ROUTES.MONEY_REQUEST_STEP_TAG.getRoute(CONST.IOU.ACTION.EDIT, CONST.IOU.TYPE.REQUEST, index, transaction?.transactionID ?? '', report.reportID),
ROUTES.MONEY_REQUEST_STEP_TAG.getRoute(CONST.IOU.ACTION.EDIT, CONST.IOU.TYPE.REQUEST, orderWeight, transaction?.transactionID ?? '', report.reportID),
)
}
brickRoadIndicator={getErrorForField('tag', {tagListIndex: index, tagListName: name}) ? CONST.BRICK_ROAD_INDICATOR_STATUS.ERROR : undefined}
Expand Down
2 changes: 1 addition & 1 deletion src/libs/Navigation/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ type MoneyRequestNavigatorParamList = {
reportID: string;
backTo: Routes;
reportActionID: string;
tagIndex: string;
orderWeight: string;
};
[SCREENS.MONEY_REQUEST.STEP_TAX_RATE]: {
action: ValueOf<typeof CONST.IOU.ACTION>;
Expand Down
10 changes: 3 additions & 7 deletions src/libs/PolicyUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,19 +181,15 @@ function getSortedTagKeys(policyTagList: OnyxEntry<PolicyTagList>): Array<keyof
}

/**
* Gets a tag name of policy tags based on a tag index.
* Gets a tag name of policy tags based on a tag's orderWeight.
*/
function getTagListName(policyTagList: OnyxEntry<PolicyTagList>, tagIndex: number): string {
function getTagListName(policyTagList: OnyxEntry<PolicyTagList>, orderWeight: number): string {
if (isEmptyObject(policyTagList)) {
return '';
}

const policyTagKeys = getSortedTagKeys(policyTagList ?? {});
const policyTagKey = policyTagKeys[tagIndex] ?? '';

return policyTagList?.[policyTagKey]?.name ?? '';
return Object.values(policyTagList).find((tag) => tag.orderWeight === orderWeight)?.name ?? '';
}

/**
* Gets all tag lists of a policy
*/
Expand Down
2 changes: 1 addition & 1 deletion src/pages/iou/request/step/IOURequestStepTag.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ function IOURequestStepTag({
policyTags,
report,
route: {
params: {action, tagIndex: rawTagIndex, transactionID, backTo, iouType, reportActionID},
params: {action, orderWeight: rawTagIndex, transactionID, backTo, iouType, reportActionID},
},
transaction,
splitDraftTransaction,
Expand Down

0 comments on commit 0cc3743

Please sign in to comment.